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

标签 c usb hid libusb libusb-1.0

我有一个 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/

相关文章:

sockets - 数据传输Windows Embedded Compact 7和计算机VIA USB连接

Android 设备无法识别

usb - 将输出发送到设备以更改 Logitech 鼠标/键盘中的 channel

调试代码后找不到问题所在

c - 如何在不使用循环和默认转换的情况下一一打印联系人号码?

c - PIC32 - PWM 和正弦波

macos - 在 Mac OS X 中禁用鼠标加速

python - 使用 cython 将模块移植到 python 3.1

android - 无法将 Samsung Galaxy Tab2 GT- P3100 连接到 PC

objective-c - 在 OS X 中模拟单击和拖动