HidDeviceReaderLibraryCore 1.1.0
dotnet add package HidDeviceReaderLibraryCore --version 1.1.0
NuGet\Install-Package HidDeviceReaderLibraryCore -Version 1.1.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="HidDeviceReaderLibraryCore" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HidDeviceReaderLibraryCore" Version="1.1.0" />
<PackageReference Include="HidDeviceReaderLibraryCore" />
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 HidDeviceReaderLibraryCore --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HidDeviceReaderLibraryCore, 1.1.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.
#addin nuget:?package=HidDeviceReaderLibraryCore&version=1.1.0
#tool nuget:?package=HidDeviceReaderLibraryCore&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HidDeviceReaderLibrary
Introduction
HidDeviceReaderLibrary
is a .NET library for reading data from USB HID devices (not supporting virtual keyboard mode) and parsing JSON data. It is suitable for scenarios where you need to communicate with HID devices and process their data.
Features
- Supports finding and connecting HID devices by VendorID and ProductID
- Real-time reading of HID device data streams
- Automatically filters ASCII data and extracts JSON strings
- Supports parsing JSON and retrieving specific field values
- Asynchronous data retrieval via event callbacks
- Supports custom cancellation of reading (CancellationToken)
Supported Platforms
- .NET Core 2.0 and above
- .NET 6/8/9
- Windows, Linux, macOS (platforms supported by HidSharp)
Installation
dotnet add package HidDeviceReaderLibrary
Quick Start Example
using System;
using System.Threading;
using HidDeviceReaderLibrary;
class Program {
static async void Main()
{
// your HID device VendorID 和 ProductID
var reader = new HidDeviceReaderV1(0x2F50, 0x0300);
reader.OnDataReceived += data =>
{
Console.WriteLine($"Received data: {data}");
};
using (var cts = new CancellationTokenSource())
{
// press Ctrl+C cancels
Console.CancelKeyPress += (s, e) => {
e.Cancel = true;
cts.Cancel();
};
await reader.StartReadingAsync(cts.Token);
Console.ReadKey();
}
}
}
// DI version supports
using HidDeviceReaderLibrary;
namespace WebApplicationHIDTests
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLogging();
builder.Services.AddHidDeviceReader(vendorId: 1234, productId: 5678);
builder.Services.AddHostedService<HIDService>();
var app = builder.Build();
app.Run();
}
}
}
// Later, resolve IHidDeviceReader:
//Method 1:
var reader = serviceProvider.GetRequiredService<IHidDeviceReader>();
using (var cts = new CancellationTokenSource())
await reader.StartReadingAsync(cts.Token);
//Method 2:
using HidDeviceReaderLibrary;
using HidSharp;
namespace WebApplicationHIDTests
{
public class HIDService(IHidDeviceReader hidDevice, ILogger<HidDevice> logger) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogDebug($"Testing start...");
// Subscribe to the OnDataReceived event correctly
hidDevice.OnDataReceived += data => logger.LogDebug(data);
await hidDevice.StartReadingAsync(stoppingToken);
while (!stoppingToken.IsCancellationRequested)
await Task.Delay(1000, stoppingToken);
}
}
}
Dependencies
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- HidSharpCore (>= 1.3.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.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.1.0 | 189 | 5/16/2025 |
## version 1.1.0
- [fix] pre-release