Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android bulkTransfer return -1 when read data but there is really some data in the buffer

Tags:

android

host

usb

I write a app in galaxy tab p7300 to communicate with a key (scsi device) via otg cable. I can read data first time with bulkTransfer(),but can not the next time . Then I use Ellisys Visual USB to sniff data and I find that the key really return 13 bytes data. But in the android client (GT-P7300) I receive -1 that bulkTransfer return. I have run out my idea. Thanks for anybody that can give me a piece of clues.

like image 531
Wayne.liu Avatar asked Dec 24 '12 04:12

Wayne.liu


1 Answers

When using the USB Bulk transfer, here is a list of things to check when transaction fails

a) Verify the direction of the endpoint you have passed the bulkTransfer function

b) ensure that the buffer has sufficient length to store incoming data

c) The length field is perhaps the most important. If you know the exact size of the response, use it.

d) The Timeout parameter. If you send a query to the device and do not provide enough timeout when listening to the response, the bulkTransfer can return -1.

It looks like the timeout is affecting behavior in your Case. My suggestion is to use the exact number of bytes in the length fields for each response, and use a longer timeout (like 1000) so you give enough time for the bulk request to complete.

like image 94
Srikanth K. Avatar answered Sep 27 '22 16:09

Srikanth K.