I have a USB HID scale with which I need to receive weighing reports. I can do this on Linux by reading 7 bytes at a time from /dev/hidraw#, but I would like to get the same information using libusb-1.0.
Even when I get a few non-zero bytes, I get a -9 error: LIBUSB_ERROR_PIPE
I am trying to use control transfer like this:
#define WEIGH_REPORT_SIZE 7
libusb_open(dev, &handle);
#ifdef __linux__
libusb_detach_kernel_driver(handle, 0);
#endif
libusb_claim_interface(handle, 0);
unsigned char data[WEIGH_REPORT_SIZE];
unsigned int len = libusb_control_transfer(
handle,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS |
LIBUSB_RECIPIENT_INTERFACE,
HID_REPORT_GET,
0x0100,
0x00,
data,
WEIGH_REPORT_SIZE,
10000
);
int i;
printf("Got %d bytes from control transfer:\n", len);
for(i = 0; i < WEIGH_REPORT_SIZE; i++) {
printf("%x\n", data[i]);
}
source
share