Can't read data from SerialPort, callback never called #2398
-
I have a USB to serial (RS-232) cable plugged into my Windows PC and would like to read the data from the serial device. This is my code:
const serialPort = require('serialport'); const port = new serialPort( 'COM4', { baudRate: 9600 , dataBits: 8, stopBits: 1, parity: 'none' } ) const parser = new serialPort.parsers.Readline() port.pipe(parser) //abre el puerto port.on('open', (err) => { //Verifica si hay error al abrir el puerto if (err) { return console.log('Error opening port: ', err.message); } console.log('Port Opened'); //console.log(port); }); port.on('error', function (err) { console.log('Error: ', err.message); }) //lee el puerto port.on('readable', function (err) { if (err) { return console.log('Error al leer el puerto: ', err.message); } console.log('Data:', port.read()); port.resume(); }); parser.on('data', (line) => { console.log(line); port.resume(); }); port.on('close', function (err) { console.log(err); }); When I use the debuger, this is the result: |
Beta Was this translation helpful? Give feedback.
Answered by
M0hammedImran
May 10, 2022
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
reconbot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
port.resume()
does not work if there is a readable listener.