hidapi
hidapi copied to clipboard
hid_open(0x5F9, 0x2210, NULL)
I have following code and cannot open_hid? I wonder why
// Initialize the hidapi library struct hid_device_info *devs, *cur_dev;
if (hid_init()) return -1;
devs = hid_enumerate(0x5F9, 0x2210); cur_dev = devs; while (cur_dev) { printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number); printf("\n"); printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string); printf(" Product: %ls\n", cur_dev->product_string); printf(" Release: %hx\n", cur_dev->release_number); printf(" Interface: %d\n", cur_dev->interface_number); printf("\n"); cur_dev = cur_dev->next; } hid_free_enumeration(devs);
// Open the device using the VID, PID,
// and optionally the Serial number.
handle = hid_open(0x5F9, 0x2210, NULL);
if (!handle) {
printf("unable to open device\n");
hid_exit();
return 1;
}
and got Output
Device Found type: 05f9 2210 path: \?\hid#vid_05f9&pid_2210#7&26c1f2e0&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} serial_number: S/N E17B08780 Manufacturer: Datalogic ADC, Inc. Product: Handheld Barcode Scanner Release: 70 Interface: -1
unable to open device
If the barcode scanner is showing up as a HID keyboard, the OS is likely claiming the device. (In general, hidapi cannot access keyboards and mice because those devices are managed by the OS). In some OSes, you can get the OS to release its claim on a keyboard, then you could use hidapi with it.
Some scanners can be configured to be in a "HID data" mode: i.e. it's still a HID device but not a keyboard. These can be used with hidapi. Or the scanner can be configured in an RS232 / serial mode, in which case you'd use a standard serial library instead of hidapi.
I had the same problem, and I solved it by patching hidapi.
In open_device function
, set DWORD desired_access
to NULL
instead of (enumerate)? 0: (GENERIC_WRITE | GENERIC_READ);
.