when using serialport in Node.js I need to parse every byte without using a delimiter

419 Views Asked by At

I have a legacy device from which I need to receive serial data and it does not send a delimiter. Therefore I need to send every byte I receive to a function. My code is written in Javascript and I use node.js with the npm serialport package. I have tried the following code, but it still does not send the data to my serialHandler function unless a return (\r) is received. I was expecting it to send each byte received to the serialHandler function without the need of a delimiter, but in my troubleshooting, it did not send anything to the function until it received the \r delimiter. It then parsed it by each byte as expected. How can I send each byte received to the serialHandler function without using a delimiter? node version 16.17.0 serialport version 10.5.0

Here is the code.

const {SerialPort} = require('serialport');  
const { ByteLengthParser } = require('@serialport/parser-byte-length'); 
const port = new SerialPort({                           //set serial port pins and baudrate
    path: '/dev/ttyAMA1',
    baudRate: 115200
});
const serialParser = port.pipe(new ByteLengthParser({ length: 1 }));
serialParser.on('data', serialHandler);     

function serialHandler(serialChar){
   //does stuff

}

1

There are 1 best solutions below

0
faithaurora On

I've figured out that it was actually the sending software I was testing with(Putty) that was causing my issues. It had local line editing forced on, causing it only to send data when you pressed Enter.