Version: 9.x.x

What are Parsers?

Parsers are collections of transform streams to processes incoming data

The default Parsers are Transform streams that process incoming data. To use the parsers, you must create them and then pipe the Serialport to the parser. Be careful to only write to the SerialPort object and not the parser.

Example#

const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = new Readline()
port.pipe(parser)
parser.on('data', console.log)
port.write('ROBOT PLEASE RESPOND\n')

Creating the parser and piping can be shortened to

const parser = port.pipe(new Readline());
Last updated on by Francis Gulotta