I am able to get a list of serial ports, and successfully open my desired port. However, The data received event never fires. The port sends a small amount of data after being opened. I have verified that the port is sending data by using a usb monitor.
// Open event example
const SerialPort = require('serialport');
var port = new SerialPort('COM220', { autoOpen:true, baudRate: 921600 });
port.on('open', () => {
console.log('Port Opened');
});
// Switches the port into "flowing mode"
port.on('data', function (data) {
console.log('Data:', data);
});
// Read data that is available but keep the stream from entering "flowing mode"
port.on('readable', function () {
console.log('Data:', port.read());
});
I have some ideas:
The readable mode is different than the normal. What are the results from this?
port.on('data', function(data) { console.log(data.toString()); }
You can make your own buffer by appending a string with the data char.
var bfr = ""; port.on('data', function(data) { bfr += data.toString(); console.log(bfr); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.