简体   繁体   English

使用Libusb 1.0发送中断传输会返回LIBUSB_ERROR_IO,但在接收时不会

[英]Sending a interrupt transfer using Libusb 1.0 returns an LIBUSB_ERROR_IO but not when receiving

I am setting up a testing framework (Google Test Framework) for some custom firmware. 我正在为一些自定义固件设置测试框架(Google Test Framework)。 I am using USB with the Libusb 1.0 library to receive outputs from the firmware, but I also need to simulate an input to the firmware. 我正在使用带有Libusb 1.0库的USB来接收固件的输出,但我还需要模拟固件的输入。 I am able to receive the outputs to the host ok, but am not able to send the transfer from the host. 我能够将输出接收到主机ok,但无法从主机发送传输。

The USB descriptor indicates that interrupt transfers to the host contain 3/4 pieces of data which I capture using this data structure: USB描述符表明中断传输到主机包含3/4条数据,我使用这种数据结构捕获这些数据:

typedef struct
{
    uint8_t reportId;
    uint8_t axis[NUM_AXIS];
    uint8_t button;
}usb_report_t;

This works fine using this call from libusb 使用libusb的这个调用可以正常工作

transfer_error = libusb_interrupt_transfer(dev_handle, 0x81, (unsigned char*)&report, sizeof(report), &transfer_length, 200);

My second task namely sending an interrupt transfer I set up using this structure 我的第二个任务是发送使用此结构设置的中断传输

typedef struct
{
    uint8_t reportId;
    uint8_t thumper;
}usb_out_report_t;

And I send the interrupt transfer using this call 我使用此调用发送中断传输

transfer_error = libusb_interrupt_transfer(dev_handle, 0x01, (unsigned char*)&out_report, sizeof(out_report), &length, 200);

This call returns a -1 which is a LIBUSB_ERROR_IO. 该调用返回-1,即LIBUSB_ERROR_IO。

While I was attempting to solve this issue I discovered a work around. 当我试图解决这个问题时,我发现了一个解决方法。 If I remove the report ID from the USB descriptor which consequently turns the two structs to 如果我从USB描述符中删除报告ID,从而将两个结构转换为

typedef struct
{
    //uint8_t reportId;
    uint8_t axis[NUM_AXIS];
    uint8_t button;
}usb_report_t;
typedef struct
{
    //uint8_t reportId;
    uint8_t thumper;
}usb_out_report_t;

Then the interrupt transfers both in and out work fine. 然后中断传入和传出工作正常。 This is ok as a temporary work around but is not an ideal long term solution. 这可以作为临时工作,但不是理想的长期解决方案。

Is there a way to keep the report ID field but have the transfer work both for IN and OUT endpoints? 有没有办法保留报告ID字段,但是IN和OUT端点的传输都有效?

Had a co-worker help me figure this one out. 有一个同事帮我解决这个问题。 So apparently in the libusb source code the hid_open() function parses the USB Descriptor and uses the capabilities.NumberOutputValueCaps to determine whether the report ID is needed for writing the output report. 显然,在libusb源代码中,hid_open()函数解析USB描述符并使用capabilities.NumberOutputValueCaps来确定编写输出报告是否需要报告ID。 The USB Descriptor in my custom firmware gets parsed by this such that the capabilities.NumberOutputValueCaps = 0. This means the api call does not expect a report ID to be used. 我的自定义固件中的USB描述符由此进行解析,使得capabilities.NumberOutputValueCaps = 0.这意味着api调用不期望使用报告ID。

To solve this, we just hard coded a particular value for NumberOutputValueCaps and recompiled the libusb library. 为了解决这个问题,我们只是对NumberOutputValueCaps的特定值进行了硬编码,并重新编译了libusb库。 This let us have a working test framework for the production version of the firmware. 这让我们为固件的生产版本提供了一个有效的测试框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM