J'ai une balance USB HID dont j'ai besoin pour récupérer les rapports de pesage. Je suis capable de faire cela sur Linux en lisant 7 octets à la fois de /dev/hidraw#
, mais je voudrais obtenir la même information en utilisant libusb-1.0.Comment recevoir des rapports HID en utilisant libusb-1.0?
Même quand je reçois des octets non nuls, j'obtiens l'erreur -9: LIBUSB_ERROR_PIPE
Je tente d'utiliser un transfert de contrôle comme si:
#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]);
}
Merci! Cela semblait le faire. – erjiang