C# WinUsb_ReadPipe返回False和超时

C# WinUsb_ReadPipe返回False和超时,c#,winusb,C#,Winusb,我必须将一个应用程序从C++(一个正常工作的应用程序)转换为C#。然而,在新的C代码中,我无法使用WinUsb#ReadPipe读取数据,尽管在其他操作中,如WinUsb#GetDescriptor、WinUsb#QueryDevice Information、WinUsb#Initialize、WinUsb#WritePie成功 在我设置的WinUsb_SetPipePolicy(读取)中 原始值=真值 自动清除失速=真 传输超时=1000//1s 而对于WinUsb_SetPipePol

我必须将一个应用程序从C++(一个正常工作的应用程序)转换为C#。然而,在新的C代码中,我无法使用WinUsb#ReadPipe读取数据,尽管在其他操作中,如WinUsb#GetDescriptor、WinUsb#QueryDevice Information、WinUsb#Initialize、WinUsb#WritePie成功

在我设置的WinUsb_SetPipePolicy(读取)中

  • 原始值=真值
  • 自动清除失速=真
  • 传输超时=1000//1s
而对于WinUsb_SetPipePolicy(Write),我只将传输超时设置为1000

当我执行WinUsb读取管道时,事务失败,最后一个错误是121(错误超时)

这是我用来读取管道的代码

        if (!(InTEGRAusbHandle.IsInvalid)) 
        {
            do
            {
                bytesReaded = nBytesToRead;

                try
                {
                    isSuccess = NativeMethods.WinUsb_ReadPipe(
                                              InTEGRAusbHandle,
                                              InTEGRA_BULK_IN.PipeId, //PipeId = 131
                                              bRxBuffer, //bRxBuffer[65536]
                                              nBytesToRead, //64
                                              ref bytesReaded,
                                              IntPtr.Zero);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    return false;
                    throw;
                }
                if (!isSuccess)
                {
                    System.Console.WriteLine(Marshal.GetLastWin32Error()); 
                }

                timeoutCounter++;
            } while ((isSuccess == false) && (timeoutCounter <= 1));}
if(!(InTEGRAusbHandle.IsInvalid))
{
做
{
字节读取=nBytesToRead;
尝试
{
isSuccess=NativeMethods.WinUsb\u ReadPipe(
英格拉斯邦德,
InTEGRA\u BULK\u IN.PipeId,//PipeId=131
bRxBuffer,//bRxBuffer[65536]
nBytesToRead,//64
参考ByteReaded,
IntPtr.0);
}
捕获(例外情况除外)
{
isSuccess=false;
返回false;
投掷;
}
如果(!isSuccess)
{
System.Console.WriteLine(Marshal.GetLastWin32Error());
}
timeoutCounter++;

}而((issucess==false)&(timeoutCounter您是否检查了异常内容
ex
?没有异常内容,因为在执行try..catch code..TQI时没有错误。我已解决了问题。这是关于错误检查的问题。请将您的解决方案作为答案,以供参考。好的..我今晚上载它。您检查了异常内容吗在
ex
?没有异常ex的内容,因为在执行try..catch code..TQI时没有错误。我已经解决了问题。这是关于错误检查的问题。请将您的解决方案作为答案,以供参考。好的..我今晚上传它。