libusb_control_transfer() 从不 returns

libusb_control_transfer() never returns

我正在与 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?我不知道如何调试它。

在某些情况下,我也会在 libusb_control_transfer 中看到 Process finished with exit code 139 (interrupted by signal 11: SIGSEGV).(我打印了一张纸来检查它确实在里面)。

我解决了这个问题。我给它的 device_handle 并不总是相同的。根据它的值,它从函数中得到分段错误或从未 return。

我给了它正确的手柄,现在可以使用了。