Skip to main content
Version: 8.0.3

hardware

The sos.hardware API groups together methods for working with hardware. It allows opening serials ports, using bar scanner or controlling LEDs.

Methods

openSerialPort()

Learn more about using this API here

The openSerialPort() method opens a serial port for reading/writing. After the port is opened the method returns ISerialPort interface.

openSerialPort(options: ISerialPortOptions): Promise<ISerialPort>;

Params

NameTypeDescription
options.device (optional)stringSpecifies the address of the external device.
options.baudRatenumberSpecifies the data transmission speed in bits per second.
options.parity (optional)ParitySpecifies the form of error checking, whether (or what) extra bits are added to a byte.
options.databits (optional)numberSpecifies the number of bits in a byte.
options.stopbits (optional)numberSpecifies the number of bits used to signal the end of a communication packet.
options.rtscts (optional)booleanEnables or disables RTS/CTS handshaking over the serial port. Currently supported by selected models of BrightSign.

API Example

import { sos } from '@signageos/front-applet';

void sos.onReady(async () => {
// Open default serial port based platform
const serialPort = await sos.hardware.openSerialPort({
baudRate: 115200,
});

await serialPort.close();
});

void sos.onReady(async () => {
// Open specific serial port
const serialPort = await sos.hardware.openSerialPort({
device: '/dev/ttyUSB0',
baudRate: 115200,
});

serialPort.onData((data) => {
const dataString = [...data].map((char) => String.fromCharCode(char)).join('');
console.log(dataString);
});

await serialPort.write('68656c6c6f'); // hexadecimal string
await serialPort.write([10, 20, 30, 40]); // array of numbers
await serialPort.write(Uint8Array.from([10, 20, 30, 40])); // Uint8Array

await serialPort.close();
});