When using USB Bulk transfer, here is a list of things to check when a transaction fails.
a) Check the direction of the endpoint , you passed the bulkTransfer function
b) make sure the buffer is long enough to hold incoming data
c) Perhaps the most important is the length field. If you know the exact size of the answer, use it.
d) Timeout parameter. If you send a request to the device and do not provide a sufficient timeout when listening to the response, bulkTransfer may return -1.
It seems that the timeout affects the behavior of your case. My suggestion is to use the exact number of bytes in the length fields for each response and use a longer timeout (e.g. 1000), so you give enough time to complete the bulk request.
Srikanth K.
source share