@curium.rocks/serial-emitter
v0.68.0
Published
A IDataEmitter implementation that uses a serial source and emits raw data
Downloads
154
Maintainers
Readme
Serial-Emitter
How To Install
npm install --save @curium.rocks/serial-emitter
API Documentation
You can view the API documentation here.
Example(s)
import {SerialDataFormat, SerialEmitterFactory, SerialParity} from "@curium.rocks/serial-emitter";
import {IDataEmitter, IDataEvent} from "@curium.rocks/data-emitter-base";
const factory:SerialEmitterFactory = new SerialEmitterFactory();
const emitter:IDataEmitter = await factory.build({
portName: '/dev/ttyUSB0',
dataBits: 8,
parity: SerialParity.NONE,
stopBits: 1,
baudRate: 9600,
format: SerialDataFormat.ASCII_LINES
}, 'unique-id', 'my-test-serial-port', 'A longer description')
const dataListener = emitter.onData((dataEvent:IDataEvent) => {
console.log(`data: ${dataEvent.data}, emitted at: ${dataEvent.timestamp}, from: ${dataEvent.emitter.name}`)
})
const statusListener = emitter.onStatus((statusEvent) => {
console.log(`status: connected = ${statusEvent.connected}, at = ${statusEvent.timestamp}, BIT = ${statusEvent.bit}`);
})
dataListener.dispose();
statusListener.dispose();