Android bulkTransfer returns -1 when reading data, but there really is some data in the buffer

I am writing an application on the p7300 galaxy tab to communicate with a key (scsi device) via an otg cable. I can read the data first with bulkTransfer (), but I can't next time. Then I use Ellisys Visual USB to sniff the data, and I found that the key really returns 13 bytes of data. But in the android client (GT-P7300) I get -1, which returns bulkTransfer. I have exhausted my idea. Thanks for anyone who can give me some tips.

+7
source share
2 answers

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.

+6
source

It is too late to publish the decision, but if in the future someone needs help, he can get an answer from here.

I ran into the same problem. I used Android (Samsung galaxy s3) as a USB device. I found out about the read endpoint and wrote the endpoint without crosshatching data using USB BulkTransfer. I tried switching the endpoints for the host mode case, it recognized and successfully wrote / read data.

mReadEndpoint = mDataInterface.getEndpoint(0);// tweaking endpoints // 1 was for read and 0 was for write mWriteEndpoint = mDataInterface.getEndpoint(1); 

PS there is an application available for android with the name "USB Device Information". This helped me in understanding the interfaces and endpoints of my USB device.

+1
source

All Articles