Com
interface Com
The {@link Com} interface provide methods that enables the use of the serial communication port.
Implementation of the {@link Com} interface is provided in the class {@link SerialCommunication}.
To start using the serial communication an instance of the class {@link SerialCommunication} needs to be created.
Below examples show how to connect to the serial communication port,
setup callback to get notification when data is available for reading and method to write data.
Create instance of the SerialCommunication class and do connect.
... {@code SerialCommunication = _serialCommunication = new SerialCommunication(); if (_serialCommunication.connect(_baudRate)) { setDataAvailableCallback(); Toast.makeText(SerialComActivity.this, "Successful connect!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(SerialComActivity.this, "Unsuccessful connect!", Toast.LENGTH_SHORT).show(); } } ...Setup data available callback and read data when it is available.
{@code private void setDataAvailableCallback() { _serialCommunication.setDataAvailableCallback(new DataAvailable() { Override public void onDataAvailable(SerialCommunication.EventTypes event) { if (event == SerialCommunication.EventTypes.DATA_AVAILABLE) { byte [] buffer = new byteMAX_BUFFER_SIZE; _serialCommunication.read(buffer, buffer.length); } } }); } }Write to the serial port.
... {@code byte[] buffer = text.getBytes(); _serialCommunication.write(buffer, buffer.length); } ...
Types
Link copied to clipboard
Baud rates
Link copied to clipboard
Number of data bits.
Link copied to clipboard
Event types.
Link copied to clipboard
Parity.
Link copied to clipboard
Stop bits.
Functions
Link copied to clipboard
abstract fun connect(baudRate: Com.BaudRates?, stopBits: Com.StopBits?, dataBits: Com.DataBits?, parity: Com.Parity?): Boolean
Open and connect to the serial port.
Link copied to clipboard
Disconnect the connected port.
Link copied to clipboard
Set data available callback for the application layer.