What is the best USB library to communicate with USB HID devices on Windows?

31,500

Solution 1

Take a look at hidapi: it is C, which answers the C++ bindings question (effectively :)), is cross platform and has a very permissive license.

It doesn't appear to have the callbacks, but...

Solution 2

If libhid works for you, then perhaps the thing to do would be to write an application (which you would GPL), which uses libhid to talk to devices, then provides whatever you need via a TCP connection. Your real application would connect via TCP to do what it needs. This would obviously be a massive performance hit.

This application would effectively be a 'shim' between libhid and your application. In this case, the shim would exist for legal, not technical, reasons.

I'm not saying it's a good idea, just that it's an idea.

Solution 3

Consider rolling your own. You'll have total control over the interface, the level of platform independence, and such. Even though a project is GPL, you can use it as a recipe for your own, and as a testbed to find issues with your own.

Solution 4

There are several USB HID host drivers for Windows. An easy-to-use dynamic-link library is from http://embedded24.net.

There are also several example applications included for Visual Studio 2010 (C++, C#, and Visual Basic).

Solution 5

Look at this code:

Read and use FM radio (or any other USB HID device) from C#

It gives you some simple classes to talk to a HID device. It boils down to getting the alias for the device (something like \?\HID#Vid_nnnn&Pid_nnn#...) and use CreateFile to open it. You can get the device's alias under HKML\SYSTEM\CCS\Control\DeviceClasses\{4d1e55...}\.

The Vid and Pid are the vendor ID and product ID of the device (check Device Manager).

Share:
31,500
Saad
Author by

Saad

Updated on July 09, 2022

Comments

  • Saad
    Saad almost 2 years

    The library should;

    • Be easy to use and few lines of client code should accomplish much
    • Be as platform independent as possible. (In case of future ports to other platforms)
    • Have C++ bindings.
    • Be mature and stable

    I would also like to be notified of most HID events through callbacks.

    I have considered the following alternatives:

    • libhid - (Unfortunately?) this is GPL and cannot be used in my application.
    • WDK - Seems to be a bit low-level for my use. I don’t need that kind of control.
    • atusbhid - This has an appropriate level of abstraction, but it is firmly tied to the Windows messaging loop

    Are there other alternatives to offer?

  • loverboy
    loverboy about 11 years
    I have created my own HID library in C# and C++/CLI. You can refer to the WDK.
  • pattivacek
    pattivacek over 10 years
    Definitely the best choice if libhid is not an option due to licensing.
  • Alyoshak
    Alyoshak over 4 years
    Fwiw, Hidapi works well on MacOS too. Just built a little utility with it.