Skip to main content

hardware

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

warning
  • Before using this API, ensure that the display supports serial via sos.display.supports("SERIAL").
  • Samsung Kiosk serial connection only works over serial ports, not over USB ports.

List of supported serial ports

Bellow is example list of serial ports that can be used with sos.hardware.openSerialPort() method.

Device typeDefault valueOther available values
RaspberryPi / Linux/dev/ttyS0/dev/ttyS1, /dev/ttyUSB0, /dev/ttyUSB1
WindowsCOM3COM1, COM2, COM4 etc. Usually it's always COM3
Samsung KioskPORT1PORT2, PORT3, PORT4
Android/dev/ttyusb0/dev/ttyusb1, /dev/ttyusb2
BrightSign00 (Serial Jack as /dev/ttyS0), 1 (GPIO port as /dev/ttyS1), USB:A/0 (USB-to-serial as /dev/ttyUSB0)

Methods

openSerialPort()

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

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

Params

NameTypeRequiredDescription
options.devicestring
No
Specifies the address of the external device, check the table above for ports.
options.baudRatenumber
Yes
Specifies the data transmission speed in bits per second.
options.parityParity
No
Specifies the form of error checking, whether (or what) extra bits are added to a byte.
options.databitsnumber
No
Specifies the number of bits in a byte.
options.stopbitsnumber
No
Specifies the number of bits used to signal the end of a communication packet.
options.rtsctsboolean
No
Enables or disables RTS/CTS handshaking over the serial port. Currently supported by selected models of BrightSign.

Return value

Returns a promise that resolves to an instance of

Possible errors

  • If the serial port cannot be opened.
  • If the device address is not supported by the platform.
  • If the device fails to process the data.
  • If any other error occurs while opening the serial port.

Example

// Open serial port on BrightSign with default settings
const serialPort = await sos.hardware.openSerialPort({
device: '0',
baudRate: 9600,
});
serialPort.write('68656c6c6f'); // Write "hello" in hexadecimal

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();
});