Smdn.IO.UsbHid.Providers.HidSharp 1.0.0

Prefix Reserved
dotnet add package Smdn.IO.UsbHid.Providers.HidSharp --version 1.0.0
                    
NuGet\Install-Package Smdn.IO.UsbHid.Providers.HidSharp -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="Smdn.IO.UsbHid.Providers.HidSharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Smdn.IO.UsbHid.Providers.HidSharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Smdn.IO.UsbHid.Providers.HidSharp" />
                    
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 Smdn.IO.UsbHid.Providers.HidSharp --version 1.0.0
                    
#r "nuget: Smdn.IO.UsbHid.Providers.HidSharp, 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 Smdn.IO.UsbHid.Providers.HidSharp@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=Smdn.IO.UsbHid.Providers.HidSharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Smdn.IO.UsbHid.Providers.HidSharp&version=1.0.0
                    
Install as a Cake Tool

Smdn.IO.UsbHid.Providers.HidSharp 1.0.0

Smdn.IO.UsbHid.Providers.HidSharp is a backend provider for Smdn.IO.UsbHid.Abstractions that utilizes the HIDSharp library for hardware communication. It enables applications using the Smdn.IO.UsbHid.* abstraction layer to operate on HID devices through the HidSharp 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 Smdn.IO.UsbHid;
using Smdn.IO.UsbHid.DependencyInjection;

var services = new ServiceCollection();

// Register the IUsbHidService using HidSharp as the implementation provider
services.AddHidSharpUsbHid();

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()
}

AddHidSharpUsbHid() registers the HidSharp 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:

API List

List of APIs exposed by assembly Smdn.IO.UsbHid.Providers.HidSharp-1.0.0 (net10.0)

// Smdn.IO.UsbHid.Providers.HidSharp.dll (Smdn.IO.UsbHid.Providers.HidSharp-1.0.0)
//   Name: Smdn.IO.UsbHid.Providers.HidSharp
//   AssemblyVersion: 1.0.0.0
//   InformationalVersion: 1.0.0+470070c6da64aee99f46bf7d909a3d58bdec0ee4
//   TargetFramework: .NETCoreApp,Version=v10.0
//   Configuration: Release
//   Metadata: IsTrimmable=True
//   Metadata: RepositoryUrl=https://github.com/smdn/Smdn.IO.UsbHid
//   Metadata: RepositoryBranch=main
//   Metadata: RepositoryCommit=470070c6da64aee99f46bf7d909a3d58bdec0ee4
//   Referenced assemblies:
//     HidSharp, Version=2.1.0.0, Culture=neutral
//     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
//     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.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using HidSharp;
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 sealed class HidSharpUsbHidDevice : IUsbHidDevice<HidDevice> {
    public static string ResiliencePipelineKeyForOpenEndPoint { get; } = "HidSharpUsbHidDevice.resiliencePipelineOpenEndPoint";

    public int ProductId { get; }
    public HidDevice 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 HidSharpUsbHidEndPoint : IUsbHidEndPoint<HidStream, HidStream> {
    public bool CanRead { get; }
    public bool CanWrite { get; }
    public IUsbHidDevice Device { get; }
    public HidStream? ReadEndPoint { get; }
    public HidStream? 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 HidSharpServiceCollectionExtensions {
    public static IServiceCollection AddHidSharpUsbHid(this IServiceCollection services) {}
    public static IServiceCollection AddHidSharpUsbHid(this IServiceCollection services, Action<HidSharpUsbHidServiceBuilder<object?>> configure) {}
    public static IServiceCollection AddHidSharpUsbHid(this IServiceCollection services, string serviceKey) {}
    public static IServiceCollection AddHidSharpUsbHid(this IServiceCollection services, string serviceKey, Action<HidSharpUsbHidServiceBuilder<string>> configure) {}
    public static IServiceCollection AddHidSharpUsbHid<TServiceKey>(this IServiceCollection services, TServiceKey serviceKey, Func<TServiceKey, string?> selectOptionsNameForServiceKey) {}
    public static IServiceCollection AddHidSharpUsbHid<TServiceKey>(this IServiceCollection services, TServiceKey serviceKey, Func<TServiceKey, string?> selectOptionsNameForServiceKey, Action<HidSharpUsbHidServiceBuilder<TServiceKey>> configure) {}
  }

  public static class HidSharpUsbHidServiceBuilderExtensions {
    public static HidSharpUsbHidServiceBuilder<TServiceKey> AddResiliencePipelineForOpenEndPoint<TServiceKey>(this HidSharpUsbHidServiceBuilder<TServiceKey> builder) {}
    public static HidSharpUsbHidServiceBuilder<TServiceKey> AddResiliencePipelineForOpenEndPoint<TServiceKey>(this HidSharpUsbHidServiceBuilder<TServiceKey> builder, Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<HidSharpResiliencePipelineKeyPair<TServiceKey>>> configure) {}
    public static HidSharpUsbHidServiceBuilder<TServiceKey> AddResiliencePipelineForOpenEndPoint<TServiceKey>(this HidSharpUsbHidServiceBuilder<TServiceKey> builder, RetryStrategyOptions retryOptions) {}
  }

  public sealed class HidSharpUsbHidServiceBuilder<TServiceKey> : UsbHidServiceBuilder<TServiceKey> {
    public override IUsbHidService Build(IServiceProvider serviceProvider) {}
  }

  public static class HidSharpUsbHidServiceProviderExtensions {
    public static ResiliencePipelineProvider<string>? GetResiliencePipelineProviderForHidSharpUsbHidService(this IServiceProvider serviceProvider, object? serviceKey) {}
  }

  public readonly record struct HidSharpResiliencePipelineKeyPair<TServiceKey> {
    public HidSharpResiliencePipelineKeyPair(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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 253 4/11/2026
1.0.0-preview4 1,728 3/13/2026
1.0.0-preview3 116 3/8/2026
1.0.0-preview2 141 2/28/2026
1.0.0-preview1 126 2/23/2026

See the release notes for [Smdn.IO.UsbHid.Providers.HidSharp version 1.0.0](https://github.com/smdn/Smdn.IO.UsbHid/releases/tag/releases%2FSmdn.IO.UsbHid.Providers.HidSharp-1.0.0) on GitHub Releases.