Hello there! It’s been a while since my last post, and I’m back here again.
Today I’d like to write a small note about the USB Android Open Accessory protocol. In short, it allows an android device to communicate with external devices over USB, even if it can’t be a host. When using it on Android, I got an
EBADF code. What to do?
First of all, I had used this very helpful page with sources as the basis for both parts (Android and computer): http://android.serverbox.ch/?p=262.
The stacktrace I got when trying to send data after a certain delay looks like this:
1 2 3 4 5 6 7 8 9 10 11
When opening a USB accessory, I saved the references to the following variables required for communication:
1 2 3 4 5 6
Long story short, turned out the parent
FileDescriptor got garbage collected and thus invalid, causing the aforementioned exception. So I need to keep
Here’s some extract of the connecting code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
All in all, the AOA protocol seems to be somewhat incomplete. For example, when one end disconnects, the other one doesn’t get notified. In case of Android code, the
read() call is blocking and cannot be interrupted only by new data or physical USB disconnect. But that’s another story…