USB serial communication

111 views
Skip to first unread message

Steve Baker

unread,
Mar 19, 2023, 2:25:39 PM3/19/23
to DroidScript
I'm having trouble communicating with 2 USB devices. Mostly the last link created dominates and I can't get anything from the first link. Stop and Start seem to work once or twice then I get 'object is null' type error. Much of the problem seems to do with data that's waiting and not READ before I say Stop, but that's just an impression.

Does anyone have code samples for two simultaneous USB connections? I'm pretty sure there's a lot going on that isn't documented (eg '2nd', '3rd' for PID).

Thank you.

Right2TheV0id

unread,
Mar 19, 2023, 3:05:10 PM3/19/23
to DroidScript
I have no experience with USB Serial but I will try to help you anyway.
I read your post a couple of times and I think it's missing some information:
1. "2 USB devices" -> What are those devices?
2. "the last link created (...) the first link" -> What do you call a "link" in this situation?
3. "two simultaneous USB connections" -> Could you elaborate it?
4. "(eg '2nd', '3rd' for PID)" -> Are those parameters that aren't documented?

Also:
Did you look at the "USB" labelled samples? (USB Serial, USB GPS, USB Espruino, USB Arduino)
Did you search the forum for "usb serial"?

It would be useful if you could post some code you tested.

Dave

unread,
Mar 19, 2023, 3:49:11 PM3/19/23
to DroidScript
When you can't find something in the docs, it's worth checking the release notes.  If you look at the release notes for version 177b you will see these notes - 

- Changed 'device' parameter of app.CreateUSBSerial() to select by PID not index.
- Allowed app.GetPermission( "usb:"+pid ) for USB devices.

You can get the PID (Product ID) and  VID (Vendor ID) of a USB device by plugging it into a windows machine and going to Device Manager/Properties for that device.

Release notes and APKs are here - 
http://androidscript.org/apk

You can then post an issue here telling the docs guys that that info is missing or out-dated- 

Steve Baker

unread,
Mar 19, 2023, 5:29:11 PM3/19/23
to DroidScript
WORKING!! So it works with the actual PIDs as the 'device' argument. My confusion came from the fact that the older modes, no device argument and '2nd' as an argument, still <sort of> worked.

Thanks to each and all for responding.
Reply all
Reply to author
Forward
0 new messages