My node.js script uses the serialport npm package to read and write to COM5 port, which is connected to an RS-232 device. This device only writes to the serial port when it receives a command sent by the PC connected to it.
How can I read what is returned by the RS-232 device after writing to it?
var SerialPort = require('serialport');
var port = new SerialPort('COM5', {
parser: SerialPort.parsers.readline('\r')
}, function() {
port.write('#01RD\r', function(err) {
if(err)
console.log('Write error')
else {
// HOW TO READ RESPONSE FROM DEVICE?
}
});
port.write('#01VER\r', function(err) {
if(err)
console.log('Write error')
else {
// HOW TO READ RESPONSE FROM DEVICE?
}
});
});