Conversation with HID

I have a sensor developed by PNI Corp called Spacepoint-Fusion. I need to interact with this device in C ++ and constantly read new data from the device.

When I connect the device to the computer, I see / dev / hidraw 1 and / dev / hidraw2. Also appears / dev / usb / hiddev 0.

My problem is that I have no idea how to read these devices. I can not find any examples or documentation on the Internet. I don’t even know where to start. I considered libhid and hiddev as possible solutions, but I still can’t figure out how to use any of these libraries.

So, how can I read this human interface device in C ++ on a Linux machine? Examples would be very helpful. Thanks.

+4
source share
3 answers

You should use the libusb library: http://libusb.sourceforge.net/doc/index.html

#include <libusb.h> 

Another way is to read / dev / usb / hiddev 0 as a simple file with reading, writing system calls. See: man is open, man 2 is reading, man 2 is writing.

  #include <fcntl.h> #include <unistd.h> 
+1
source

You have a difficult path ahead. First you will need information about "spacepoint-fusion" (I hope it comes with documentation).

Some initial values, such as product identifier / vendor identifier, can be obtained using the terminal command:

 lsusb 

Next, you will probably need endpoints that could be found using:

 lsusb -v 

From this you can find which addresses on the device can be written and which addresses can be read (and possibly the size of the read / write buffers). But this is as much as you can get without proper paperwork. You will need to know what values ​​need to be written to the device, and what values ​​to expect from the device.

Assuming you DO NOT know what values ​​to read / write from / to the device, the following example will try:

http://www.lvr.com/code/generic_hid.c

I also believe that your device is HID compatible, which is not necessary at all. In any case, I wish you the very best in your journey via USB.

+1
source

Try running hexdump on hidraw devices and create some input in your "spacepoint-fusion".

 $ hexdump -C /dev/hidraw1 

If you get some useful data, the easiest way would be to use open() and read() to get input from the device. Each read() should return one packet of information from your device. You will need documentation for your device or be prepared to reverse engineer what the packages mean.

+1
source

Source: https://habr.com/ru/post/1335748/


All Articles