我有一個USB HID刻度,我需要從中獲取稱量報告。我可以在Linux上通過從/dev/hidraw#
一次讀取7個字節來完成此操作,但我希望使用libusb-1.0獲得相同的信息。如何使用libusb-1.0接收HID報告?
即使當我得到一些非空字節,我得到錯誤-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]);
}
謝謝!這似乎做到了。 – erjiang 2011-02-14 01:47:55