USB Data vanish

Hi All,

I am using the usbsamp driver to communicate with a USB device. When i am doing a ReadFile of nNumberOfBytesToRead as 64 bytes, the ReadFile method call is returning with the expected data but if i do a second ReadFile of nNumberOfBytesToRead as 896 bytes then the method is not returning with the expected data.
On the other side if i do the second ReadFile of nNumberOfBytesToRead as 64 bytes then the method returns with the expected data.

I used a software sniffer to check the packets…(1st case) It showed that the second IN packet did not return with IRP succeeded but on sending another IN packet it returned with the expected data.
On the other hand when i used a hardware sniffer…it showed that the IN packet is returning with the expected data but is reaching till the usbsamp driver.

Is there an issue with the usbhub.sys…if not then how to handle this situation.?

Subhashis Sikder wrote:

I am using the usbsamp driver to communicate with a USB
device. When i am doing a ReadFile of nNumberOfBytesToRead
as 64 bytes, the ReadFile method call is returning with the
expected data but if i do a second ReadFile of
nNumberOfBytesToRead as 896 bytes then the method is not
returning with the expected data.

According to the USB spec, a bulk IN URB will be completed back to you only in the following cases:

  • a short packet is received (i.e. one smaller than the endpoint’s specified packet size), including a zero-length packet

  • the number of bytes requested has been received

You asked for 896 bytes, and the device sent 64. Therefore, because the device sent a maximum packet, the hub driver is waiting for more packets to coalesce into your original read request of 896 bytes.

So if you want this transfer to finish, you need to either ask for 64 bytes at a time, or program your device to send a zero-length packet when it’s done communicating.