Android Question USB Serial Connection Issue

walterf25

Expert
Licensed User
Hello all, i really need some help to brainstorm in order to find a solution to this problem, from what i've read is an android bug that has been there for years, i'm surprised it hasn't been fixed.

I have a device that communicates with my application through an USB Serial cable, I can open the port just fine and get the required permissions. If I run the application the first time I can communicate and download the data from the device just fine, but If i try to send the download command again to the device to do another download the usb port seems to not work anymore, I would have to physically disconnect the usb port from the phone and re-connect it in order for the usb to regain connection, i read this post here http://www.b4x.com/android/forum/th...ccessory-before-opening-it.30222/#post-175546

From what I understand it seems to be an android bug, in the link provided in that post they mention dong a soft reset, but i have no idea what that is, or even how to do that with B4A, if someone has more experience with this would you please shine some light on this issue, My application requires to be pinging the device all the time, and only when the user placed the device in download mode it would start downloading the data and check if there's new data available. But after the first succesful download it seems that the usb doesn'tt keep working.

Any thought or ideas would be greatly appreciated.

Thanks,
Walter
 

raphaelcno

Active Member
Licensed User
A soft reset is just a restart of the phone.
The post you refer to seems to be related to Accessory connection. Are you using your USB device as an Accessory?
 

walterf25

Expert
Licensed User
A soft reset is just a restart of the phone.
The post you refer to seems to be related to Accessory connection. Are you using your USB device as an Accessory?
Thanks for your reply Raphael, i'm using my device as a usb serial device.
 

walterf25

Expert
Licensed User
Thanks for your reply Raphael, i'm using my device as a usb serial device.
I'm using my device in host mode, in any case I should be able to close the usb connection and astreams connections and still be able to re-initialize or re-open the connections to start download again, in my case i have to disconnect and reconnect the usb device from my phone to re-gain connection again.

any ideas why this may be?

Walter
 

raphaelcno

Active Member
Licensed User
Difficult to say where the problem is.
Do you know if the log contains error messages generated by the AStreams_Error or AStreams_Terminated subs?
You probably need to log some events to try to understand when the connection stops.
 

walterf25

Expert
Licensed User
Difficult to say where the problem is.
Do you know if the log contains error messages generated by the AStreams_Error or AStreams_Terminated subs?
You probably need to log some events to try to understand when the connection stops.
Ok, I just fixed that issue, all i had to do was to kill the service and restartt it again every time i want to download data again.
Now i have another issue, event though i placed the Vendor Id Number and Product ID number in the device_filter.xml file, if I disconnect the usb cable and then reconnect it i get asked for usb permissions everytime, any idea why this would be?

Thanks,
Walter
 

walterf25

Expert
Licensed User

raphaelcno

Active Member
Licensed User
Do you also use the device_filter.xml file as explained in http://www.b4x.com/android/forum/threads/usbserial-library-2-0-supports-more-devices.28176/

As with the original UsbSerial library you can add the following code to the manifest editor

Code:
AddActivityText(main, <intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />)
Then copy device_filter.xml from the demo in the attached archive to: <your project>\objects\res\xml and mark it as read-only. Note that this is an expanded version of the original device_filter.xml file.

Finally install the program and attach the USB device. A dialog will appear asking whether you want to start your program. If you check the “Use by default…” checkbox from now on when the USB device is plugged in your program will be started. If you don’t check the checkbox then you will be asked each time the device is plugged in.
 

walterf25

Expert
Licensed User
Top