Back

CreateUSBSerial

Hello World
Content:
- Methods

The USBSerial component can be used to communicate with other USB devices connected to yours.

usb = app.CreateUSBSerial( baudRate, dataBits, stopBits, parity, device ) → app object: USBSerial

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:

GetCD()
GetDTR()
GetRTS()
GetType() → String: “USBSerial”
IsConnected() → Boolean
Method( name, types, p1, p2, p3, p4 ) → all types
Start()
Stop()
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
Number: pid
String: Hex or Int or Text or “<encoding>”
String: “End” or “Start-End” or “Size”
String: “US-ASCII” or “UTF16L/BE”
String
Number: integer
Object: { COMMAND }
List: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function( data )
usb.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
usb.GetCD
Raises the Carrier Detect bit from the unterlying UART protocol. It can usually be used to detect if a serial device is connected or has been terminated.
usb.GetDTR
Get the Data Terminal Ready state which indicates the terminal is ready for communications and may initiate a communication channel.
usb.GetRTS
Get the Request To Send state that indicates that you may send data to the target device.
usb.GetType
Returns the control class name.
usb.IsConnected
Returns whether a USB serial device is connected by actively checking the presence of a device.
usb.Method
Allows 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 to indicate that you may now receive data from the target device.
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 to indicate that you want to send data to the target device.
usb.SetSplitMode
Tells 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:
modep1p2
SizeSize of one data package-
EndByte indicating end of data-
Start-EndByte indicating start of dataByte indicating end of data
usb.SetTimeout
Set timeout
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.