gpt4 book ai didi

c - 我如何使用 libusb-1.0 接收 HID 报告?

转载 作者:太空狗 更新时间:2023-10-29 15:27:42 24 4
gpt4 key购买 nike

我有一个 USB HID 秤,我需要从中获取称重报告。我可以通过一次从 /dev/hidraw# 读取 7 个字节在 Linux 上执行此操作,但我想使用 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]);
}

最佳答案

使用 libusb-win 从 USB HID 读卡器读取的示例 -

http://rowsandcolumns.blogspot.com/2011/02/read-from-magtek-card-swipe-reader-in.html

关于c - 我如何使用 libusb-1.0 接收 HID 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4844692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com