Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/badcel/hidapi.net

A modern cross platform C# binding for HIDAPI
https://github.com/badcel/hidapi.net

binding dotnet hidapi

Last synced: 1 day ago
JSON representation

A modern cross platform C# binding for HIDAPI

Awesome Lists containing this project

README

        

# HidApi.Net
[![Build Status](https://img.shields.io/github/actions/workflow/status/badcel/HidApi.Net/ci.yml?branch=main)](https://github.com/badcel/HidApi.Net/actions/workflows/ci.yml)[![NuGet](https://img.shields.io/nuget/v/HidApi.Net)](https://www.nuget.org/packages/HidApi.Net/)[![License (MIT)](https://img.shields.io/github/license/badcel/HidApi.Net)](https://github.com/badcel/HidApi.Net/blob/main/license.txt)

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](https://www.nuget.org/packages/HidApi.Net/) 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][api].

### Code sample
You can use the [Hid class](https://github.com/badcel/HidApi.Net/blob/main/src/HidApi.Net/Hid.cs) to enumerate over devices or directly use the [device class](https://github.com/badcel/HidApi.Net/blob/main/src/HidApi.Net/Device.cs) to connect to a known device:

```csharp
foreach(var deviceInfo in Hid.Enumerate())
{
using var device = deviceInfo.ConnectToDevice();
Console.WriteLine(device.GetManufacturer());
}
Hid.Exit(); //Call at the end of your program
```

```csharp
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][udev] 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:

```sh
$ 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][license] for further information.

[HIDAPI]:https://github.com/libusb/hidapi
[udev]:https://github.com/libusb/hidapi/blob/master/udev/69-hid.rules
[license]:https://raw.githubusercontent.com/badcel/HidApi.Net/main/license.txt
[api]:https://badcel.github.io/HidApi.Net/api/HidApi.html