0

I developed an Android application which connects to an external USB device to send and receive messages.

I followed the guidelines of the official Android Host USB API here (as well as a few other SO posts): https://developer.android.com/guide/topics/connectivity/usb/host.html

Everything works fine except for one thing: It seems that the external USB device is sending data when my app is not connected which causes it's USB buffers to overflow - which stops the device.

According to the device manufacturer the solution would be to enable DTR/DTE (which I have to admit I don't really understand what it is). But this apparently would enable them to check if my app is listening and only then send their data.

So, could you please share a code example of how to enable DTR/DTE on an Android USB connection?

Update:

After some more searching it seems that I'd need use the UsbDeviceConnection.controlTransfer method - but I have no idea what the parameters should be.

Daniel
  • 304
  • 2
  • 12
  • You're talking about a USB-to-serial adapter, right? How about you get a better one that does not "stop" when its buffers overflow? A buffer filling up is a normal thing that a USB-to-serial adapter must be prepared for, and if your device cannot handle it, then it is flawed. I suspect the adapter is OK and you are just having a software issue, like maybe you need to flush the RX buffer when your application starts up so you don't end up reading old data into your application. With the level of info you have given, it's hard to tell what the right solution is. – David Grayson Oct 17 '17 at 19:09
  • Thanks David, that was my first thought as well - the USB device should handle the buffer filling issue - but, still, I was hopping to find a way to solve this from the Android side – Daniel Oct 18 '17 at 06:04
  • @DavidGrayson: how do I flush the RX buffer, could you please share the code? – Daniel Oct 18 '17 at 06:25

1 Answers1

0

I finally found the answer:

connection.controlTransfer(0x21, 0x22, 0x1, 0, null, 0, 0);

I found it here: Android USB host read from device

Daniel
  • 304
  • 2
  • 12