SerialPort
Version and platform compatibility
This feature was introduced in version 4.26.0 of the JourneyApps Container for Android and Windows desktop.
Support for binary data was introduced in version 4.59.0 of the JourneyApps Container for Android and Windows desktop.
USB-based SerialPort devices are only supported on Windows.
The SerialPort API is currently only available for customers on the Enterprise plan.
The SerialPort API allows applications to directly communicate to external devices that support the serial port protocol. On Android, the devices have to support the Bluetooth Serial Port Profile or SPP.
To use the SerialPort API, a global SerialPort
object is available.
Checking if SerialPort is supported
A SerialPort.info()
function is available to check if the user's device has access to the serial port. It returns an object:
Field | Type | Description |
---|---|---|
| boolean | Indicates if SerialPort is supported on the current device. Supported on Android and Windows only. |
| boolean | Some devices are able to connect to more than one device at a time. This property indicates if the device is able to do so. Multiple connections are only supported on Windows. |
| boolean | Indicates if the device supports reading data in raw (binary) mode. |
Since the SerialPort object is not available in containers below 4.26, a check is needed to avoid an error, for example:
Listing SerialPort devices
Connecting and pairing of devices happens outside of the the JourneyApps Container i.e. the user is responsible for pairing an external device using their specific device's instructions. To get a list of paired devices, call the SerialPort.list()
function. It returns an array of device objects that contain the following fields:
Field | Type | Description |
---|---|---|
| string | The device's physical address. On Android, this will be a MAC address. On Windows, this will be a COM port. The |
| string | Sometimes a device has a descriptive name that makes it easier for the user to identify the device they are trying to connect to. If it isn't available, it will default to |
Connecting to a device
To connect to a device, the address
is required from SerialPort.list()
, but can also be entered manually or hardcoded if known.
To connect, use SerialPort.connect(address, options, readHandler)
.
Parameter | Description |
---|---|
| Address from |
| Object with configuration options. See below for more details. |
| Callback that gets called containing all data that was received from the serial port. |
The following fields can exist in the options
object:
Option | Type | Description |
---|---|---|
| integer | The Baud Rate of the device that you are trying to connect to. This is only applicable on Windows, since Android manages this. |
| boolean | If the connection should be opened in raw (binary) mode. Defaults to |
Writing to a device
The SerialPort.connect
function returns a SerialPort instance. From the example above, to write:
Note that the readHandler
that was passed to the connect
function will receive responses from the serial port if given, and not the write
function.
Closing and resetting
To close a connection, call close()
on the connection object, e.g. serialPort.close()
.
To reset the serial port, call SerialPort.reset()
. This closes all open ports.
Last updated