The USBSerial component can be used to communicate with other USB devices connected to yours.
The default constructor values are:
baudrate: 9600
To find out more about RTD and DTR or USB serial at all visit Wikipedia: RS-232
Note: this application only works on devices that support OTG and allow access to external serial devices.
Known to work: Nexus7, GalaxyS3/S4, ExperiaZUltra, TescoHudl
Dont work: Nexus4, GalaxyS1, AsusMemo
Methods
The following methods are available on the USBSerial object:
boolean
string
number: integer
number: milliseconds
number: integer: 300 or 600 or 1200 or 2400 or 4800 or 9600 or 19200 or 38400 or 57600 or 115200 or 230400 or 460800 or 921600
number: integer: 5 or 6 or 7 or 8
number: integer: 1 or 2 or 15
number: integer: 0 or
1 or
2 or
3 or
4
string: “1st” or “2nd” or “3rd” or “...”
string: “Hex” or
“Int” or
“Text” or
“<encoding>”
string: “End” or “Start-End” or “Size”
string: “US-ASCII” or “UTF16L/BE”
string
number: integer
list: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
usb.GetType
Returns the control class name.
usb.IsConnected
Returns whether a USB serial device is connected.
usb.MethodAllows access to other functions defined on the object in Java via reflection.
Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
usb.SetDataMode
Enable sending data in several modes.
usb.SetDTR
Raises the Data Terminal Ready state.
usb.SetMaxRead
Define the maximum amount of bytes you want to receive at once.
usb.SetMaxWrite
Define maximum amount of bytes to send at once.
usb.SetOnReceive
The SetOnReceive callback is called automatically after data has been received via the USB serial connection.
usb.SetRTS
Raises the Request To Send state.
usb.SetSplitModeTells the serial listener how to split received data. Splitted data will result in multiple OnReceive calls.
p2 and p3 have different purposes for different modes:
mode | p1 | p2 |
---|
Size | Size of one data package | - |
End | Byte indicating end of data | - |
Start-End | Byte indicating start of data | Byte indicating end of data |
usb.SetTimeout
SetTimeout
usb.Start
Start listening to the USB serial connection.
usb.Stop
Stop listening on USB serial connection
usb.Write
Send data over the USB serial connection to the other device.