@juanjofp/serialport-observable
v0.0.25
Published
Serialport-observable is a library for RxJS that allows you to read and write data from/to a serial port.
Downloads
26
Readme
Serialport Observable
Serialport-observable is a library for RxJS that allows you to read and write data from/to a serial port.
install
npm install @juanjofp/serialport-observable
Usage
const uartDevice = createSerialPortObservable('/dev/ttyAMA0', {
baudRate: 9600,
highWaterMark: 100000
});
await uartDevice.open();
let subscription: Subscription | undefined;
const obsValue = await new Promise<Buffer>(resolve => {
subscription = uartDevice.data().subscribe(resolve);
uartDevice.write([0x01, 0x02, 0x03]);
});
subscription?.unsubscribe();
await uartDevice.close();
expect(uartDevice.isConnected()).toBe(false);
expect(obsValue.byteLength).toBeGreaterThanOrEqual(1);