我有一个 USB HID 秤,需要从中获取称重报告。我可以通过一次读取 7 个字节在 Linux 上执行此操作/dev/hidraw#
,但我想使用 libusb-1.0 获得相同的信息。
即使我确实得到了一些非空字节,我也会得到错误-9:LIBUSB_ERROR_PIPE
我正在尝试使用这样的控制转移:
#define WEIGH_REPORT_SIZE 7
/*
* Open a handle to the found scale
*/
libusb_open(dev, &handle);
#ifdef __linux__
libusb_detach_kernel_driver(handle, 0);
#endif
libusb_claim_interface(handle, 0);
/*
* Try to transfer data about status
*
*/
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,
//wValue => hid report, no report ID
0x0100,
0x00, //windex => interface 0
data,
WEIGH_REPORT_SIZE, //wLength
10000 //timeout => 10 sec
);
int i;
printf("Got %d bytes from control transfer:\n", len);
for(i = 0; i < WEIGH_REPORT_SIZE; i++) {
printf("%x\n", data[i]);
}