20

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Torleif
  • 2,334
  • 3
  • 27
  • 28
  • I found out through testing that libusb-win32-src-1.2.6.0 does not initailized the devices element of struct usb_bus. Please try something else. – Frank Dec 26 '15 at 04:16

6 Answers6

10

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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Femi
  • 64,273
  • 8
  • 118
  • 148
  • Definitely the best choice if libhid is not an option due to licensing. – pattivacek Oct 23 '13 at 14:00
  • Fwiw, Hidapi works well on MacOS too. Just built a little utility with it. – Alyoshak Jan 22 '20 at 20:32
  • [signal11/hidapi][1] is no longer developed or supported (the author is missing). But [libusb/hidapi][2] is very well supported and gets a lot of improvements. [1]: https://github.com/signal11/hidapi [2]: https://github.com/libusb/hidapi – Youw Oct 26 '22 at 21:02
5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael Kohne
  • 11,888
  • 3
  • 47
  • 79
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.

Dave Van den Eynde
  • 17,020
  • 7
  • 59
  • 90
2

HIDmaker software suite from Trace systems is an option.

Pros:

  • Easy to use (excellent for learning how to program for USB HID)
  • Generates working applications source code in a various project formats (Visual Studio and Borland)
  • Generates stable example code for both host and device (stable in my experience)
  • High performance (if HID can even be said to have high performance in the first place)

Cons:

  • Only works on Microsoft Windows
  • Uses its own USB library I think (ActiveX)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • So in effect, it just provides you with a C++ binding to their ActiveX control. Also, it's meant to produce the code on the hardware side for a variety of microcontrollers. That seems a bit overkill to me. – Dave Van den Eynde Nov 14 '08 at 10:29
2

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).

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Coderer
  • 25,844
  • 28
  • 99
  • 154
2

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Potter
  • 21
  • 1