0

最后更新 :

现在我有一个与我的设备兼容的字符串(它必须采用特定格式的不可打印字节),但是是一个无限循环。该程序永远不会退出 WinUsb_WritePipe。

原始问题:

在初始化我所有的 WinUsb 接口之后(正如这个做得很好的 MSDN 教程中所精确的那样:https ://msdn.microsoft.com/en-us/library/windows/hardware/ff540174(v=vs.85).aspx )

除了最后一步,我得到了一切顺利的设置并发送 true 没有错误。

PWINUSB_INTERFACE_HANDLE piUsbHandle = new WINUSB_INTERFACE_HANDLE();
USB_INTERFACE_DESCRIPTOR *eUsbInterfaceDescriptor = new USB_INTERFACE_DESCRIPTOR();

WinUsb_Initialize(sfhDeviceHandle, piUsbHandle) //true

devInfo->winUsbHandle = *piUsbHandle;

WinUsb_QueryInterfaceSettings(*piUsbHandle, 1, eUsbInterfaceDescriptor) //true

for (int i= 0; i <= eUsbInterfaceDescriptor->bNumEndpoints - 1; i++)
{
        if (!WinUsb_QueryPipe((WINUSB_INTERFACE_HANDLE)devInfo->winUsbHandle, 1, (unsigned char)i, &eWinUsbPipeInformation))
        {
            return NULL;
        }
        if (((eWinUsbPipeInformation.PipeType == UsbdPipeTypeBulk)
             & this->isUsbEndPointDirectionIn(eWinUsbPipeInformation.PipeId)))
        {
            UtilityFunctions::displayTrace("initializeDevice : devInfo->bulkInPipe set");
            std::cout << "New In Pipe = " <<  (int)eWinUsbPipeInformation.PipeId << std::endl;
            devInfo->bulkInPipe = eWinUsbPipeInformation.PipeId;
        }
        else if (((eWinUsbPipeInformation.PipeType == UsbdPipeTypeBulk)
                  & this->isUsbEndpointDirectionOut(eWinUsbPipeInformation.PipeId)))
        {
            UtilityFunctions::displayTrace("initializeDevice : devInfo->bulkOutPipe set");
            std::cout << "New Out Pipe = " <<  (int)eWinUsbPipeInformation.PipeId << std::endl;
            devInfo->bulkOutPipe = eWinUsbPipeInformation.PipeId;
        }
        else if (((eWinUsbPipeInformation.PipeType == UsbdPipeTypeInterrupt)
                  & this->isUsbEndPointDirectionIn(eWinUsbPipeInformation.PipeId)))
        {
            UtilityFunctions::displayTrace("initializeDevice : devInfo->InterruptInPipe set");
            devInfo->interruptInPipe = eWinUsbPipeInformation.PipeId;
        }
        else if (((eWinUsbPipeInformation.PipeType == UsbdPipeTypeInterrupt)
                  & this->isUsbEndpointDirectionOut(eWinUsbPipeInformation.PipeId)))
        {
            UtilityFunctions::displayTrace("initializeDevice : devInfo->InterruptOutPipe set");
            devInfo->interruptOutPipe = eWinUsbPipeInformation.PipeId;
        }
        else
        {
            std::cout << "No settings for " << i << std::endl;
            continue;
        }
}

(devInfo 是一个自定义对象,包含 aWINUSB_INTERFACE_HANDLE和在PipeId设备上写入所需的内容)

它打印

initializeDevice : bNumEndpoints => 6
initializeDevice : devInfo->bulkOutPipe set
New Out Pipe = 1
initializeDevice : devInfo->bulkInPipe set
New In Pipe = 129
initializeDevice : devInfo->bulkOutPipe set
New Out Pipe = 2
initializeDevice : devInfo->bulkOutPipe set
New Out Pipe = 4
initializeDevice : devInfo->bulkInPipe set
New In Pipe = 134
initializeDevice : devInfo->bulkInPipe set
New In Pipe = 136

但是对于最后一步,即编写:

UCHAR ucBuffer[] = "Hello world";
ULONG uiBytesToWrite = 11;
ULONG ulBytesWritten = 0;

if (devInfo->winUsbHandle == INVALID_HANDLE_VALUE)
{
    return;
}


WinUsb_WritePipe(devInfo->winUsbHandle, devInfo->bulkOutPipe, ucBuffer, uiBytesToWrite, &ulBytesWritten, 0);//ERROR 87 : INVALID PARAMETER

我已经尝试了所有可能的 PipeId(从 0 到 255,因为它在一个字节上),但仍然得到相同的错误。 WinUsb_WritePipe MSDN 文档没有说明错误 87。

4

0 回答 0