4

I need to access a USB device from C++ under Linux and am totally new to USB interfacing. The device I'm accessing does not come with any driver - but shows up as an HID device. The device is similar to a machine controller (simple shorts commands in/out). It's not like a mouse/keyboard - so I'm not sure if it SHOULD show up as a HID device.

From what I've read, my options are to access it as a HID device, or blacklist it and access it using libusb. (Please correct me if I got that wrong). It seems like HID access is the way to go - otherwise I have to write a kernel driver for the device.

It would seem like HID access is preferable. Is there an example of how to communicate with a device using HID under Linux? This is a simple USB device with one USB configuration, one read endpoint and one write endpoint.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TSG
  • 4,242
  • 9
  • 61
  • 121

1 Answers1

4

I recommend using hidapi. If your device is already setup to work as such, this is a better way than libusb. libusb will work, but you will likely need to implement the HID spec as well as the protocol for your device. If you just use hidapi then you should just have to implement the protocol for the device on top of the hidapi layer. I think I recall that hidapi is also implemented on top of libusb anyway.

Preston
  • 2,543
  • 1
  • 17
  • 26
  • Since I know the read/write endpoints, is there an example (C++, ideally Qt) which talks to a simple device by HID? – TSG Mar 28 '16 at 15:30
  • 1
    Look at the link I provided, it has everything you should need, included a sample usage right on the first page and a link to the [github](https://github.com/signal11/hidapi/blob/master/hidtest/hidtest.cpp) with all the source. – Preston Mar 28 '16 at 15:46
  • FYI: the libusb project has forked hidapi as of 4Jun2019 and is supporting it actively. https://github.com/libusb/hidapi for more info. – Erik Jun 21 '20 at 20:44