libusb_control_transfer()永不返回

时间:2019-02-01 10:52:31

标签: libusb libusb-1.0

我正在与Cypress FX3 kit设备通信。

我使用以下方式发送信息:

unsigned int file_size;
unsigned short wLength = 16;
unsigned int timeout = 1000;
unsigned short wValue = 0, wIndex = 1;

/* Here I get my file_size value */
file_size = 4000; // For the sake of the example.

rStatus = libusb_control_transfer(
            device_handle,             /* a handle for the device to communicate with */
            WRITE_REQUEST_TYPE,        /* bmRequestType: the request type field for the setup packet */
            VND_CMD_SLAVESER_CFGLOAD,  /* bRequest: the request field for the setup packet */
            wValue,                    /* wValue: the value field for the setup packet */
            wIndex,                    /* wIndex: the index field for the setup packet */
            (unsigned char *) &file_size,  /* *data: a suitably-sized data buffer */
            wLength,                   /* wLength: the length field for the setup packet. The data buffer should be at least this size. */
            timeout);                  /* timeout (in millseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0. */

现在我的计划是获得正确的信息。我向我的计算机发送UART消息,实际上FX3固件正在获取所需的内容,并随其所需的内容进行处理,但是cpp程序从不退出 libusb_control_transfer函数。

至少不应该暂停以防止该函数永不返回吗?还是因为它能够发送数据而不能阻止它……是否在等待FX3固件不发送的ACK?我不知道该如何调试。

在某些情况下,我还会在Process finished with exit code 139 (interrupted by signal 11: SIGSEGV).里面找到libusb_control_transfer(我打印了一下,发现它确实在里面)。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我给它的device_handle并不总是相同的。取决于它的值,它会出现细分错误,或者永远不会从函数返回。

我给了它正确的手柄,现在可以正常工作了。