Talking to a HID
I have a sensor developed by PNI Corp called the spacepoint-fusion. I need to interface with this device in C++ and continuously read new data from the device.
When I plug the device into my computer, I see /dev/hidraw1 and /dev/hidraw2 show up. Also /dev/usb/hiddev0 shows up.
My prob开发者_开发问答lem is that I have no idea how to read these devices. I can't find any examples or documentation online. I don't even know where to start with this. I have been looking at libhid and hiddev as possible solutions, but as of yet, I can't figure out how to use either of these libraries.
So how do I read from this human interface device in c++ on a linux machine? Examples would be greatly appreciated. Thanks.
Try running hexdump on the hidraw devices and create some input on your 'spacepoint-fusion'.
$ hexdump -C /dev/hidraw1
If you get some useful data, then the easiest way would be to use open()
and read()
to get the input from the device. Each read()
should return one packet of information from your device. You'll need some documentation for your device, or be prepared to reverse engineer what the packets mean.
You should use the libusb library: http://libusb.sourceforge.net/doc/index.html
#include <libusb.h>
Another way is read /dev/usb/hiddev0 as simple file with read, write system calls. See the: man open, man 2 read, man 2 write.
#include <fcntl.h>
#include <unistd.h>
You've got a complicated road ahead of you. You will first need information about the "spacepoint-fusion" (hopefully it came with documentation).
Some initial values such as Product ID/Vendor ID can be gained with the terminal command:
lsusb
Next, you will probably need to know the Endpoints, which could again be found using:
lsusb -v
From this, you can find what addresses on the device can be written to, and what addresses can be read from (and possibly the size of the read/write buffers). But this is as far as you can get without proper documents. You will need to know what values to write to the device, and what values to expect back from the device.
Assuming you DO know what values to read/write from/to the device try and follow this example:
http://www.lvr.com/code/generic_hid.c
I am also making the assumption that your device is HID compliant, which does not have to be the case at all. Anyway, I wish you well on your USB journey.
精彩评论