Anp.UsbDeviceDescriptors 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Anp.UsbDeviceDescriptors --version 1.0.0
                    
NuGet\Install-Package Anp.UsbDeviceDescriptors -Version 1.0.0
                    
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="Anp.UsbDeviceDescriptors" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anp.UsbDeviceDescriptors" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Anp.UsbDeviceDescriptors" />
                    
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 Anp.UsbDeviceDescriptors --version 1.0.0
                    
#r "nuget: Anp.UsbDeviceDescriptors, 1.0.0"
                    
#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 Anp.UsbDeviceDescriptors@1.0.0
                    
#: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=Anp.UsbDeviceDescriptors&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Anp.UsbDeviceDescriptors&version=1.0.0
                    
Install as a Cake Tool

UsbDeviceDescriptors

Reads USB descriptors on Windows—Device, Configuration, Interface, Endpoint, and String—via the Win32 IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION control code, and exposes them as strongly‑typed C# structures. Targets .NET Framework 4.8, .NET Standard 2.0, .NET 8.0.

Features

  • Strongly‑typed descriptors: DeviceDescriptor, ConfigurationDescriptor, InterfaceDescriptor, EndpointDescriptor, StringDescriptor, plus RawDescriptor for unknown blocks. All implement meaningful ToString() for inspection.
  • One‑call read: UsbDescriptorReader.GetDescriptors(...) returns a hierarchical UsbDescriptorSet (device → configurations → interfaces → endpoints).
  • Selectively include configurations and/or string descriptors with ReadOptions.
  • Windows‑only; uses CreateFile/DeviceIoControl and the USB hub IOCTL.
  • Synchronous I/O; no additional native dependencies.

Install NuGet

Quick start

using System;
using System.Linq;
using Anp.UsbDeviceDescriptors;

class Program
{
    static void Main()
    {
        // Inputs:
        string parentNodeId = @"USB\ROOT_HUB30\4&17AA0D8F&0"; // example (PnP Device Instance ID of a USB hub)
        uint portIndex = 3;                                     // 1-based port number on that hub

        // Read full tree (device + configurations + strings, default langId = 0x0409 English)
        UsbDescriptorSet set = UsbDescriptorReader.GetDescriptors(
            parentNodeId, portIndex, ReadOptions.All /*, langId: 0x0409*/);

        Console.WriteLine(set);

        Console.WriteLine($"VID:PID = 0x{set.DeviceDescriptor.IdVendor:X4}:0x{set.DeviceDescriptor.IdProduct:X4}");
        Console.WriteLine($"Product: {set.DeviceDescriptor.ProductName}");

        foreach (var ep in set.EndpointDescriptors)
        {
            Console.WriteLine($"EP 0x{ep.EndpointAddress:X2} ({ep.TransferType}), wMaxPacketSize={ep.MaxPacketSize}");
        }
    }
}

Language IDs & string descriptors

Some devices localize their strings.

  • UsbDescriptorReader.GetSupportedLanguageIds(parentNodeId, portIndex) — returns supported LANGIDs (lazy enumerable). Devices with no strings often return an empty set. Strings may be unavailable in low‑power states.
  • UsbDescriptorReader.GetStringDescriptor(parentNodeId, portIndex, stringIndex, langId) — reads a specific string descriptor. Index 0 is reserved for the LANGID table.

Auto‑select the first available language:

using System.Linq;
using Anp.UsbDeviceDescriptors;

ushort lang = UsbDescriptorReader.GetSupportedLanguageIds(parentNodeId, portIndex).FirstOrDefault(); // 0 if none
var set = UsbDescriptorReader.GetDescriptors(parentNodeId, portIndex, ReadOptions.All, lang);

Inputs: Parent ID and Port index

This library reads USB descriptors via Windows API that requires parent info:

  • Parent ID — the parent node (USB hub) Device Instance ID. A parent node symbolic name (\??\…) or a full device interface path (\\?\…) is also accepted.
  • Port index — the 1‑based port number (bus address) on the parent hub where the target device is connected.

Parent info is exposed by the Pnp Device Discovery library or can be obtained by other means.

API overview

Entry points

  • UsbDescriptorReader.GetDescriptors(string parentNodeId, uint portIndex, ReadOptions options = ReadOptions.All, ushort langId = 0x0409)
  • UsbDescriptorReader.GetSupportedLanguageIds(string parentNodeId, uint portIndex)
  • UsbDescriptorReader.GetStringDescriptor(string parentNodeId, uint portIndex, byte stringIndex, ushort langId = 0x0409)

Options

[Flags]
public enum ReadOptions
{
    None = 0,
    Configurations = 1,
    Strings = 2,
    All = Configurations | Strings
}

Build & support

  • Targets: .NET Framework 4.8, .NET Standard 2.0, .NET 8.0
  • Language: C# 7.3
  • Interop: Windows‑only (Win32 CreateFile/DeviceIoControl).

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 134 2/21/2026
1.0.0 133 1/9/2026

Initial release