npm.io
0.0.25 • Published 3 years ago

@juanjofp/serialport-observable

Licence
MIT
Version
0.0.25
Deps
3
Size
27 kB
Vulns
0
Weekly
0

Publish package in npm

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