Smdn.IO.UsbHid.Providers.LibUsbDotNet
1.0.1
Prefix Reserved
dotnet add package Smdn.IO.UsbHid.Providers.LibUsbDotNet --version 1.0.1
NuGet\Install-Package Smdn.IO.UsbHid.Providers.LibUsbDotNet -Version 1.0.1
<PackageReference Include="Smdn.IO.UsbHid.Providers.LibUsbDotNet" Version="1.0.1" />
<PackageVersion Include="Smdn.IO.UsbHid.Providers.LibUsbDotNet" Version="1.0.1" />
<PackageReference Include="Smdn.IO.UsbHid.Providers.LibUsbDotNet" />
paket add Smdn.IO.UsbHid.Providers.LibUsbDotNet --version 1.0.1
#r "nuget: Smdn.IO.UsbHid.Providers.LibUsbDotNet, 1.0.1"
#:package Smdn.IO.UsbHid.Providers.LibUsbDotNet@1.0.1
#addin nuget:?package=Smdn.IO.UsbHid.Providers.LibUsbDotNet&version=1.0.1
#tool nuget:?package=Smdn.IO.UsbHid.Providers.LibUsbDotNet&version=1.0.1
Smdn.IO.UsbHid.Providers.LibUsbDotNet 1.0.1
Smdn.IO.UsbHid.Providers.LibUsbDotNet is a backend provider for Smdn.IO.UsbHid.Abstractions
that utilizes the LibUsbDotNet v2 library for hardware communication.
It enables applications using the Smdn.IO.UsbHid.* abstraction layer to operate on HID devices through the LibUsbDotNet implementation.
Usage
The following example demonstrates registering and getting USB HID services (IUsbHidService) via
ServiceCollection and IServiceProvider, and getting a list of USB HID devices.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Smdn.IO.UsbHid;
using Smdn.IO.UsbHid.DependencyInjection;
var services = new ServiceCollection();
// Register the IUsbHidService using LibUsbDotNet v2 as the implementation provider
services.AddLibUsbDotNetUsbHid(
configure: static (builder, options) => {
// Specify the log level for output to stdout by libusb native library
options.DebugLevel = LogLevel.Information;
// If loading libusb-1.0 fails, check the filename or full path to the .so or
// .dylib file installed on your system and specify it with this option.
options.LibUsbLibraryPath = "libusb-1.0.so.0";
}
);
using var serviceProvider = services.BuildServiceProvider();
// Request IUsbHidService from IServiceProvider
var usbHidService = serviceProvider.GetRequiredService<IUsbHidService>();
const int VendorId = 0x04d8;
const int ProductId = 0x00dd;
// Get and list all devices with a specific Vendor ID and Product ID
foreach (IUsbHidDevice device in usbHidService.GetDevices(VendorId, ProductId)) {
Console.WriteLine($"{device.VendorId:X4}:{device.ProductId:X4}");
if (device.TryGetProductName(out var productName))
Console.WriteLine($" {productName}");
if (device.TryGetManufacturer(out var manufacturer))
Console.WriteLine($" {manufacturer}");
if (device.TryGetSerialNumber(out var serialNumber))
Console.WriteLine($" {serialNumber}");
// Open the device endpoint to send and receive HID reports
using IUsbHidEndPoint endPoint = device.OpenEndPoint(shouldDisposeDevice: true);
// await endPoint.ReadAsync(...);
// await endPoint.WriteAsync(...);
// Dispose the endpoint
await endPoint.DisposeAsync();
// Specifying true for `shouldDisposeDevice` when calling the OpenEndPoint()
// method will also dispose of the original IUsbHidDevice along with
// calling IUsbHidEndPoint.Dispose()
}
AddLibUsbDotNetUsbHid() registers the LibUsbDotNet as backend provider. By changing this to another provider's registration method,
you can switch backends without modifying other code.
More examples can be found on the GitHub repository.
Contributing
This project welcomes contributions, feedbacks and suggestions. You can contribute to this project by submitting Issues or Pull Requests on the GitHub repository.
Credits
This library uses the following third-party components:
- LibUsbDotNet - Licensed under the LGPL-3.0
- Polly.Core and Polly.Extensions - Licensed under the BSD-3-Clause license
Important notice: This software is released under the MIT License. However, it links to LibUsbDotNet as a shared library. In accordance with the LGPL-3.0, users are permitted to replace the LibUsbDotNet library file with modified versions for their own use.
For full license texts, see ThirdPartyNotices.md.
API List
List of APIs exposed by assembly Smdn.IO.UsbHid.Providers.LibUsbDotNet-1.0.1 (net10.0)
// Smdn.IO.UsbHid.Providers.LibUsbDotNet.dll (Smdn.IO.UsbHid.Providers.LibUsbDotNet-1.0.1)
// Name: Smdn.IO.UsbHid.Providers.LibUsbDotNet
// AssemblyVersion: 1.0.1.0
// InformationalVersion: 1.0.1+a02be1536a5a6483464d66d3c646344fee434e12
// TargetFramework: .NETCoreApp,Version=v10.0
// Configuration: Release
// Metadata: IsTrimmable=True
// Metadata: RepositoryUrl=https://github.com/smdn/Smdn.IO.UsbHid
// Metadata: RepositoryBranch=main
// Metadata: RepositoryCommit=a02be1536a5a6483464d66d3c646344fee434e12
// Referenced assemblies:
// LibUsbDotNet.LibUsbDotNet, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c677239abe1e02a9
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Options, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Polly.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc
// Polly.Extensions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc
// Smdn.Extensions.Polly.KeyedRegistry, Version=1.2.0.0, Culture=neutral
// Smdn.IO.UsbHid.Abstractions, Version=1.0.0.0, Culture=neutral
// System.Collections, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ComponentModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Linq, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Memory, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// System.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Runtime.InteropServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using LibUsbDotNet;
using Polly;
using Polly.DependencyInjection;
using Polly.Registry;
using Polly.Retry;
using Smdn.IO.UsbHid;
using Smdn.IO.UsbHid.DependencyInjection;
namespace Smdn.IO.UsbHid {
public interface ILibUsbSession : IDisposable {
void Initialize(LibUsbDotNetOptions options);
}
public sealed class LibUsbDotNetOptions {
public LibUsbDotNetOptions() {}
public LogLevel DebugLevel { get; set; }
public DllImportResolver? LibUsbDllImportResolver { get; set; }
public string? LibUsbLibraryPath { get; set; }
public int ReadEndPointBufferSize { get; set; }
public TimeSpan ReadEndPointTimeout { get; set; }
public TimeSpan WriteEndPointTimeout { get; set; }
public LibUsbDotNetOptions Configure(LibUsbDotNetOptions baseOptions) {}
}
public sealed class LibUsbDotNetUsbHidDevice : IUsbHidDevice<UsbDevice> {
public static string ResiliencePipelineKeyForOpenEndPoint { get; } = "LibUsbDotNetUsbHidDevice.resiliencePipelineOpenEndPoint";
public int ProductId { get; }
public UsbDevice UnderlyingDevice { get; }
public int VendorId { get; }
public void Dispose() {}
public ValueTask DisposeAsync() {}
public IUsbHidEndPoint OpenEndPoint(bool openOutEndPoint, bool openInEndPoint, bool shouldDisposeDevice, CancellationToken cancellationToken) {}
public ValueTask<IUsbHidEndPoint> OpenEndPointAsync(bool openOutEndPoint, bool openInEndPoint, bool shouldDisposeDevice, CancellationToken cancellationToken) {}
public override string? ToString() {}
public bool TryGetDeviceIdentifier([NotNullWhen(true)] out string? deviceIdentifier) {}
public bool TryGetManufacturer([NotNullWhen(true)] out string? manufacturer) {}
public bool TryGetProductName([NotNullWhen(true)] out string? productName) {}
public bool TryGetSerialNumber([NotNullWhen(true)] out string? serialNumber) {}
}
public sealed class LibUsbDotNetUsbHidEndPoint : IUsbHidEndPoint<UsbEndpointReader, UsbEndpointWriter> {
public bool CanRead { get; }
public bool CanWrite { get; }
public IUsbHidDevice Device { get; }
public UsbEndpointReader? ReadEndPoint { get; }
public UsbEndpointWriter? WriteEndPoint { get; }
public void Dispose() {}
public async ValueTask DisposeAsync() {}
public int Read(Span<byte> buffer, CancellationToken cancellationToken) {}
public ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) {}
public override string? ToString() {}
public void Write(ReadOnlySpan<byte> buffer, CancellationToken cancellationToken) {}
public ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken) {}
}
}
namespace Smdn.IO.UsbHid.DependencyInjection {
public static class LibUsbDotNetServiceCollectionExtensions {
public static IServiceCollection AddLibUsbDotNetUsbHid(this IServiceCollection services) {}
public static IServiceCollection AddLibUsbDotNetUsbHid(this IServiceCollection services, Action<LibUsbDotNetUsbHidServiceBuilder<object?>, LibUsbDotNetOptions> configure) {}
public static IServiceCollection AddLibUsbDotNetUsbHid(this IServiceCollection services, string serviceKey) {}
public static IServiceCollection AddLibUsbDotNetUsbHid(this IServiceCollection services, string serviceKey, Action<LibUsbDotNetUsbHidServiceBuilder<string>, LibUsbDotNetOptions> configure) {}
public static IServiceCollection AddLibUsbDotNetUsbHid<TServiceKey>(this IServiceCollection services, TServiceKey serviceKey, Func<TServiceKey, string?> selectOptionsNameForServiceKey) {}
public static IServiceCollection AddLibUsbDotNetUsbHid<TServiceKey>(this IServiceCollection services, TServiceKey serviceKey, Func<TServiceKey, string?> selectOptionsNameForServiceKey, Action<LibUsbDotNetUsbHidServiceBuilder<TServiceKey>, LibUsbDotNetOptions> configure) {}
}
public static class LibUsbDotNetUsbHidServiceBuilderExtensions {
public static LibUsbDotNetUsbHidServiceBuilder<TServiceKey> AddResiliencePipelineForOpenEndPoint<TServiceKey>(this LibUsbDotNetUsbHidServiceBuilder<TServiceKey> builder, Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<LibUsbDotNetResiliencePipelineKeyPair<TServiceKey>>> configure) {}
public static LibUsbDotNetUsbHidServiceBuilder<TServiceKey> AddResiliencePipelineForOpenEndPoint<TServiceKey>(this LibUsbDotNetUsbHidServiceBuilder<TServiceKey> builder, RetryStrategyOptions retryOptions) {}
}
public sealed class LibUsbDotNetUsbHidServiceBuilder<TServiceKey> : UsbHidServiceBuilder<TServiceKey> {
public override IUsbHidService Build(IServiceProvider serviceProvider) {}
}
public static class LibUsbDotNetUsbHidServiceProviderExtensions {
public static ResiliencePipelineProvider<string>? GetResiliencePipelineProviderForLibUsbDotNetUsbHidService(this IServiceProvider serviceProvider, object? serviceKey) {}
}
public readonly record struct LibUsbDotNetResiliencePipelineKeyPair<TServiceKey> {
public LibUsbDotNetResiliencePipelineKeyPair(TServiceKey serviceKey, string pipelineKey) {}
public string PipelineKey { get; }
public TServiceKey ServiceKey { get; }
public override string ToString() {}
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.8.2.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.6.2.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
| Product | Versions 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 is compatible. 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. 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 is compatible. 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 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. 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. |
-
.NETFramework 4.6.2
- LibUsbDotNet (>= 2.2.75)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Polly.Core (>= 8.0.0)
- Polly.Extensions (>= 8.0.0)
- Smdn.Extensions.Polly.KeyedRegistry (>= 1.2.0 && < 2.0.0)
- Smdn.IO.UsbHid.Abstractions (>= 1.0.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
.NETStandard 2.0
- LibUsbDotNet (>= 2.2.75)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Polly.Core (>= 8.0.0)
- Polly.Extensions (>= 8.0.0)
- Smdn.Extensions.Polly.KeyedRegistry (>= 1.2.0 && < 2.0.0)
- Smdn.IO.UsbHid.Abstractions (>= 1.0.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
.NETStandard 2.1
- LibUsbDotNet (>= 2.2.75)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Polly.Core (>= 8.0.0)
- Polly.Extensions (>= 8.0.0)
- Smdn.Extensions.Polly.KeyedRegistry (>= 1.2.0 && < 2.0.0)
- Smdn.IO.UsbHid.Abstractions (>= 1.0.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
net10.0
- LibUsbDotNet (>= 2.2.75)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Polly.Core (>= 8.0.0)
- Polly.Extensions (>= 8.0.0)
- Smdn.Extensions.Polly.KeyedRegistry (>= 1.2.0 && < 2.0.0)
- Smdn.IO.UsbHid.Abstractions (>= 1.0.0)
-
net8.0
- LibUsbDotNet (>= 2.2.75)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Polly.Core (>= 8.0.0)
- Polly.Extensions (>= 8.0.0)
- Smdn.Extensions.Polly.KeyedRegistry (>= 1.2.0 && < 2.0.0)
- Smdn.IO.UsbHid.Abstractions (>= 1.0.0)
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 | 135 | 5/10/2026 |
| 1.0.0 | 196 | 4/11/2026 |
| 1.0.0-preview5 | 137 | 3/27/2026 |
| 1.0.0-preview4 | 125 | 3/13/2026 |
| 1.0.0-preview3 | 119 | 3/8/2026 |
| 1.0.0-preview2 | 130 | 2/28/2026 |
| 1.0.0-preview1 | 132 | 2/23/2026 |
See the release notes for [Smdn.IO.UsbHid.Providers.LibUsbDotNet version 1.0.1](https://github.com/smdn/Smdn.IO.UsbHid/releases/tag/releases%2FSmdn.IO.UsbHid.Providers.LibUsbDotNet-1.0.1) on GitHub Releases.