I use the HIDAPI from here https://github.com/signal11/hidapi
This is the HIDAPI API http://www.signal11.us/oss/hidapi/hidapi/doxygen/html/group__API.html#ga1e87518670f88540c920dc451df608ee
Question 1: I can use hid_open() method with my Barcode scanning gun's VID & PID, but in this way my application cannot use other Barcode scanning gun. Also I found hid_open_path() method, but I cannot determine which path to use /dev/hidraw0 ?or /dev/hidraw1? or will change on different pc?
Question 2: is the read permission.when I connect the Barcode scanning gun with PC, it cannot read & write, my solution is use udev to definde my own rules to use VID & PID,it really worked! But it doesn't work for Barcode scanning gun.
You should use hid_enumerate(<vid>, <pid>)
, which will return linked list of hid_device_info
structures. hid_device_info
has a member variable called path
, which is the device path you are looking for. The path may change depending on the pc or on even on the same pc, if you have other devices plugged in. To distinguish between different devices, you can check their serial number using hid_get_serial_number_string
function.
Check permissions on the corresponding device. I've seen people recommend adding udev rules to change them to 666 on various forums (Ubuntu, Arch). However, I think this is incorrect. Instead, check what group the device belongs to and add yourself to that group. It could be usb
or plugdev
or something else.