Skip to content

hidapi adapter is a port of popular cross platform library "hidapi"

License

Notifications You must be signed in to change notification settings

Yazracor/hidapiadapter

 
 

Repository files navigation

hidapi adapter

This project was created to port popular library, that helps to interact with HID devices - hidapi (C language) https://github.com/signal11/hidapi

The main goal of project is to make library that adapted to C#

Here is example showing how to print information about connected HID devices

    //trying to find devices with any vendor_id, product_id
    var devices = HidDeviceManager.GetManager().SearchDevices(0, 0);

    if(devices.Any())
    {
        foreach(var device in devices)
        {
            device.Connect();

            Console.WriteLine(
              $"device: {device.Path()}\n" +
              $"manufacturer: {device.Manufacturer()}\n" +
              $"product: {device.Product()}\n" +
              $"serial number: {device.SerialNumber()}\n");

            device.Disconnect();
        }

    }

How to use?

To get devices use SearchDevices static method of HidDeviceManager class.

    HidDeviceManager.GetManager().SearchDevices(0, 0);

SearchDevices will return a set of founded devices (HidDevice)

To interact with devices use methods Read\Write. Here example

...
    m_ReadResult = m_Device.Read(m_Buffer, m_Buffer.Length);
    if (m_ReadResult == -1)
        throw new HardwareConnectionException("Cannot read data from device");
...

Nuget

Install-Package HidApiAdapter

If you getting DllNotFoundException: ... DLL "hidapi32"

Change properties of installed dlls - hidapi32.dll hidapi64.dll like on screenshot

image

About

hidapi adapter is a port of popular cross platform library "hidapi"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%