/** * Returned by sos.hardware.openSerialPort() method. * This interface provides methods to read/write data from/to the serial port. */ export default interface ISerialPort { /** * The `onData()` method sets up a listener, which is called whenever new data are received. The listener will stop after the serial port * is closed. * * @param listener A function that will be called with the received data as a Uint8Array. * @returns {void} Returns when the listener is set up. */ onData(listener: (data: Uint8Array) => void): void; /** * The `write()` method writes data to the serial port. The data can be a string of hexadecimal digits, array of numbers or Uint8Array. * * @param data The data to write to the serial port. * @returns {Promise} Returns a promise that resolves when the data is successfully written to the serial port. * @throws {Error} If the data cannot be written to the serial port. * @throws {Error} If the serial port is not open. * @throws {Error} If any other error occurs while writing to the serial port. * * @example * // serial port instance previously created via sos.hardware.openSerialPort() * 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 */ write(data: string | number[] | Uint8Array): Promise; /** * The `close()` method closes the serial port. * * @returns {Promise} Returns a promise that resolves when the serial port is successfully closed. * @throws {Error} If the serial port cannot be closed. */ close(): Promise; }