WinUsb_WritePipe 进入无限循环

WinUsb_WritePipe goes into an infinite loop

我正在使用 WinUsb_WritePipe function 在 USB 设备上写入数据。

唯一的问题是该函数执行无限循环。

//bulkOutPipe is a pipeId set precedently
//ucBuffer is an unsigned char array
//uiBytesToWrite corresponds to the size of the array
//ulBytesWritten is a unsigned long to stock the bytes written

std::cout << "Started writing" << std::endl;

WinUsb_WritePipe(devInfo->winUsbHandle, devInfo->bulkOutPipe, ucBuffer, uiBytesToWrite, &ulBytesWritten, 0);

//never gets here

这个函数 used to return false 但现在 return 没有任何作用。

为了避免无限循环,我建议总是为这样的 I/O 操作设置超时。您可以使用 WinUSB Functions for Pipe Policy Modification.