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,
- Raw_IO = true
- AUTO_CLEAR_STALL = True
- TRANSFER_TIMEOUT = 1000 //1s
While for the WinUsb_SetPipePolicy (Write) I only set the TRANSFER_TIMEOUT = 1000.
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));}
Once The code is executed, I get
- isSuccess = FALSE
- bytesReaded = 0