Oakrey.Usb 3.0.3

dotnet add package Oakrey.Usb --version 3.0.3
                    
NuGet\Install-Package Oakrey.Usb -Version 3.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Usb" Version="3.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Usb" Version="3.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Usb" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Usb --version 3.0.3
                    
#r "nuget: Oakrey.Usb, 3.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Usb@3.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Usb&version=3.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Usb&version=3.0.3
                    
Install as a Cake Tool

Oakrey.Usb

Windows .NET library for WinUSB bulk-transfer communication and real-time USB plug-and-play device monitoring.

Main features

  • WinUSB bulk transfer - synchronous read/write over WinUSB pipes via UsbAdapter and the simplified send-only UsbOutStreamAdapter.
  • Device monitoring - UsbNotifier raises arrival and removal events for any USB device connected to the system.
  • Filtered subscriptions - UsbNotifier.RegisterUsbNotification accepts a predicate so consumers receive only the events relevant to their VID, PID, or serial number.
  • Parsed device identity - ProcessedDeviceInfo extracts VID, PID, serial number, and device ID from the PnP symbolic link automatically.

Architecture

graph TD
    subgraph Oakrey.Usb.Adapter
        IUsbAdapter
        UsbAdapter -->|implements| IUsbAdapter
        UsbOutStreamAdapter -->|wraps| UsbAdapter
    end

    subgraph Oakrey.Usb.Notifier
        UsbNotifier
        UsbNotifierFilter -->|filters| UsbNotifier
        IUsbNotifierFilter
        UsbNotifierFilter -->|implements| IUsbNotifierFilter
    end

    UsbNotifier -->|uses| Nefarius[Nefarius.Utilities.DeviceManagement]
    UsbAdapter -->|uses| WinUSBNet

Requirements

  • .NET 10 (Windows only - net10.0-windows)
  • The target USB device must have the WinUSB kernel driver installed (use Zadig or a custom INF).

Installation

.NET CLI

dotnet add package Oakrey.Usb

Package Manager Console

Install-Package Oakrey.Usb

NuGet Package Manager

Search for Oakrey.Usb in Visual Studio under Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

Usage

Reading and writing over WinUSB

using Oakrey.Usb.Adapter;

// guid  - DeviceInterfaceGUID registered in the WinUSB INF
// serial - device serial number string
using UsbAdapter adapter = new("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "MY_SERIAL");

Console.WriteLine($"Connected: {adapter.Name} ({adapter.Serial})");

// Write
byte[] command = [0x01, 0x02, 0x03];
adapter.Write(command, 0, command.Length);

// Read
byte[] response = new byte[64];
int bytesRead = adapter.Read(response, 0, response.Length);

Send-only shortcut with UsbOutStreamAdapter:

using UsbOutStreamAdapter stream = new("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", "MY_SERIAL");
stream.Send([0x01, 0x02, 0x03]);

Monitoring device arrival and removal

Subscribe to all USB devices:

using Oakrey.Usb.Notifier;

using IUsbNotifierFilter subscription = UsbNotifier.RegisterUsbNotification(_ => true);

subscription.UsbEvent += (sender, e) =>
{
    Console.WriteLine($"{e.UsbDeviceChangeStatus}: VID={e.DeviceInfo.VID} PID={e.DeviceInfo.PID} Serial={e.DeviceInfo.Serial}");
};

Filter by VID and PID:

using IUsbNotifierFilter subscription = UsbNotifier.RegisterUsbNotification(
    device => device.VID == "1234" && device.PID == "ABCD");

subscription.UsbEvent += (sender, e) =>
{
    if (e.UsbDeviceChangeStatus == UsbDeviceChangeStatus.INSERTED)
    {
        Console.WriteLine($"Target device arrived: {e.DeviceInfo.Serial}");
    }
};

Dispose the subscription to stop receiving events:

subscription.Dispose();

ProcessedDeviceInfo properties

Property Description
VID Vendor ID (4 hex digits)
PID Product ID (4 hex digits)
Serial Device serial number string
SymbolicLink Raw PnP symbolic link
DeviceId Formatted device ID (USB\VID_xxxx&PID_xxxx\serial)

Project information

Field Value
Author Oakrey
License MIT
Repository https://dev.azure.com/oakrey/OpenPackages/_git/Drivers
Project URL http://www.oakrey.cz/opkg_drivers_usb

License

MIT License. See LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Oakrey.Usb:

Package Downloads
Oakrey.Applications.UsbNotifying

Windows-only .NET service that wraps the Windows PnP device notification API and exposes USB device arrival and removal events as an IObservable<UsbEventArgs> stream, backed by a ReplaySubject from System.Reactive.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.3 123 5/15/2026
3.0.2 95 5/14/2026
3.0.1 184 2/2/2026
3.0.0 130 1/7/2026
2.0.0 327 11/14/2025
1.0.0 4,597 4/17/2025