All of the answers I found are for the old API, and I can't get the current documentation working.
I am trying to read serial data from a Raspberry Pi GPIO. Here is the code:
const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline')
const port = new SerialPort('/dev/serial0', {
baudRate: 9600
})
port.open(() => {
console.log("port open");
})
port.on('data', function (data) {
console.log('Data:', data) // <----- This code works
})
const parser = port.pipe(new Readline({ delimiter: '\r\n' }))
parser.on('data', (data) => {
console.log(data)
})
The port.on() works when I get serial data. However, the parser.on() does not i.e. reading the buffer.
What am I doing wrong?