1

I have the following use case:

  1. App is running on phone.
  2. User connects accessory to phone.
  3. Accessory puts phone in accessory mode.
  4. After reconnecting and opening the right USB endpoint, accessory immediately tries to send data to app.

At step 4, I get USB error 7: Transfer error on bulk endpoint: Operation timed out on the accessory. Presumably this happens because the app has not yet opened the InputStream.

What is the correct way to handle this situation?

Frank Kusters
  • 2,544
  • 2
  • 21
  • 30

2 Answers2

0

As you are probably aware, USB is flaky at best so I'd be looking at problems with driver and/or restarting the host machine and phone. This is the only suggestion I have assuming the USB settings are good on device.

This StackOverflow Question has a lot of answers that are things that I'd look at, some are not as obvious like not using a USB3 port.

Community
  • 1
  • 1
Rich Bianco
  • 4,141
  • 3
  • 29
  • 48
  • This has no bearing on the question asked, which *does not* involve connecting the phone to an ordinary desktop computer. Please take time to research what accessory mode actually is. – Chris Stratton Jan 06 '15 at 14:55
  • The [answer](http://stackoverflow.com/a/4786299/971090) to that question proved to be very helpful, though. See my answer. – Frank Kusters Jan 08 '15 at 15:32
0

The solution turned out to be to increase the timeout for USB transfers. I'm using USB4Java, and it has a default timeout of 5 seconds. When the timeout was increased, it turned out that it took 15 seconds for the first transfer to complete. So I set it to 30 seconds.

Frank Kusters
  • 2,544
  • 2
  • 21
  • 30