I have to convert an application from C++(a working one) to C#. However, in the newly C# codes, I fail to read the data using WinUsb_ReadPipe, despite successfully in other operation such WinUsb_GetDescriptor, WinUsb_QueryDeviceInformation, WinUsb_Initialize, WinUsb_WritePipe.
In the WinUsb_SetPipePolicy (Read) I have set,
1) Raw_IO = true
2) AUTO_CLEAR_STALL = True
3) TRANSFER_TIMEOUT = 1000 //1s
While for the WinUsb_SetPipePolicy (Write) I only set the TRANSFER_TIMEOUT = 1000.
At first, I execute the WinUsb_WritePipe, it returns success. When I execute the WinUsb_ReadPipe, the transaction FAIL and the Last error is 121 (ERROR_SEM_TIMEOUT).
This is the codes I used to read the pipe.
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));}
I have debugged the operation line by line and all operation return success, however, when it comes to WinUsb_ReadPipe, It fail with Last Error code is ERROR_SEM_TIMEOUT
Once The code is executed, I get
1) isSuccess = FALSE
2) bytesReaded = 0