Skip to content

badcel/HidApi.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HidApi.Net

Build StatusNuGetLicense (MIT)

Welcome to HidApi.Net a modern cross platform C# binding for the C HIDAPI library. Supported platforms are Linux, OSX and Windows.

Supported HIDAPI version: Up to 0.14

Use

To use the library please reference the nuget package in your project. Additionally it is required to either ensure that HIDAPI is available on the host system or is distributed as part of your application.

To get an overview of the API please refer to the API documentation.

Code sample

You can use the Hid class to enumerate over devices or directly use the device class to connect to a known device:

foreach(var deviceInfo in Hid.Enumerate())
{
    using var device = deviceInfo.ConnectToDevice();
    Console.WriteLine(device.GetManufacturer());
}
Hid.Exit(); //Call at the end of your program
var device = new Device(0x00, 0x00); //Fill vendor id and product id
Console.WriteLine(device.GetManufacturer());
Hid.Exit(); //Call at the end of your program

Linux

In order to access HID devices as an unprivileged user an udev rule must be installed on the host system. Please refer to the sample udev file of the HIDAPI project.

Native AOT

If the application targets at least .NET 8 the nuget package allows applications to be published as Native AOT as itself is AOT compatible.

Build

To build the solution locally execute the following commands:

$ git clone https://github.com/badcel/HidApi.Net.git
$ cd HidApi.Net/src
$ dotnet build

Licensing terms

HidApi.Net is licensed under the terms of the MIT-License. Please see the license file for further information.