user387184
user387184

Reputation: 11053

need more info about UsbDeviceConnection.bulkTransfer in USB host mode on Android

I am trying to get bulkTransfer to work in USB host mode but the reference docs do not really explain it well.

When calling

bufferTmpLen = mDeviceConnection.bulkTransfer(mEPIN,
        bufferTmp, 4096, TIMEOUT_MS);
  1. why does the real data always seem to start 2 bytes later in index 2, what is represented in index 0 and 1 ? Is this always the case?
  2. what does the TIMEOUT_MS parameter really do? I tried to set it to 5000 but the method did not wait 5 secs to read the data. Data that came after about 1 second was not read. So how to make it accept all data that is received within certain time?
  3. Does the code continue to execute during TIMEOUT period? So for example TIMEOUT=5000, do the subsequent statements get executed after 5 seconds or immediately following the bulkTransfer line ?

I am really confused that such important information about this method is not described anywhere.

Please let me know if there is a better source than the standard ref.

Many thank!

Upvotes: 1

Views: 2278

Answers (1)

usethe4ce
usethe4ce

Reputation: 23819

The timeout is the maximum time to wait on a response before giving up. If a response comes sooner, the method finishes sooner. You may get back less than 4096 bytes. Worst case, five seconds elapses, during which time your thread is blocked, and finally the method returns -1 to indicate failure.

As for the first two bytes, there is nothing special about them. It just depends on the specifics of what the device chooses to communicate over this endpoint.

Upvotes: 5

Related Questions