Do I always have to reconnect my usb accessory before opening it ?

Dirk A

Member
Licensed User
Hi ,

I'm connecting my Ftdi device using usbserial . I can open the device , read & write data etc... (thanks to Agraham). My only problem is that when I have opened the device once using my program and I restart my program I have to disconnect my usb cable and reconnect it in order to be able to open the device again otherwise I can't communicate with the device. Is there anything I can do about it ?

I also have to give permission each time the cable is reconnected (even though I check to "always use this program for the device" )

When I exit my program I call the close function of usberial ...
 

Dirk A

Member
Licensed User
Yes, I call ExitApplication but it doesn't make a difference.
Is it possible to "re-discover your accessories" ? So that android says "an accessory has been connected" without disconnecting your usb cable ?
 

agraham

Expert
Licensed User
From one of my Arduino ADK Accesssory tutorials.
There also seems to be a bug in the Android USB Accessory handling (what’s new!) when trying to reconnect to a disconnected Accessory. I struggled with for a few hours with an input stream exception when trying to reconnect before finding this.
android - Proper way to close a USB accessory connection - Stack Overflow
From that thread it seems even the official Google demo has this problem. Please post if anyone has any suggestions to overcome this.

In order to reliably connect to an Accessory with your program it is necessary to ensure that the process of any previous instance of your program that communicated with the Arduino has been killed. This is the reason why there is an Exit button in the Basic4ppc program that calls ExitApplication that you should use to kill the program. It is also necessary before restarting the program, or downloading and running a modified version again to either press the reset button on the Arduino or disconnect and reconnect it again. If you merely reaset the Arduino your USB permission seems to be maintained. If you disconnect and reconnect you will get the permission dialog again. In either case you will be offered the choice of opening a browser and going to the Basic4android home page
this is the Stack Overflow link android - Proper way to close a USB accessory connection - Stack Overflow
 

Dirk A

Member
Licensed User
I allready had the exit button that calls exitapplication. So the only option left is look for a way to do a software reset of the device, right ? So that the device itself closes all pending connections... Then I think i wil have to contact FTDI about it because even their demo has the problem
 
Last edited:

agraham

Expert
Licensed User
Then I think i wil have to contact FTDI about it because even their demo has the problem
No real point. It's an Android bug that leaves a FileDescriptor open. Disconnecting and reconnecting the devices makes Android close it as long as your process is also dead.
 
Top