DCSIMG
WinUSB Read Problem - Asaf Shelly

WinUSB Read Problem

Published Tuesday, December 22, 2009 3:35 PM

Hi All,

I have decided to move forward from my implementation of BulkUSB.sys driver to using the formal implementation called WinUSB. It is a package of a kernel driver and a user-mode API documented as part of the MSDN library.

When I tried to do asynchronous reads I discovered two undocumented / confusing failures:

The first is GetLastError returns 997 - ERROR_IO_PENDING. This is fine for overlapped IO. The function fails and the error code means that there is more data to follow.

The second is somewhat confusing: GetLastError returns 121 - ERROR_SEM_TIMEOUT "The semaphore timeout period has expired". This means that the timeout has expired before the data was ready. The confusing part is that it looks like the call to WinUsb_ReadPipe will also fail with error code 121 if there is data in the buffer.

The read function will wait for the buffer to be full or timeout to expire. This means that the call to read will fail with error code 121 even if some data was read from the device and you must check the number of bytes read to know if read really succeeded or not. The logic behind this is that you don't call GetLastError if the function returns true.

* to set enpoint timeout use WinUsb_SetPipePolicy

 

 

תגים:, ,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: