Chat about Node-Serialport and projects using node serialport for specfic problems or bugs please open a github issue.
//Start
port.on('open', function(){
console.log('Port Opened');
port.write('ATE1');
});
port.on('data', function(data){
data = data.toString();
console.log(data);
});
const SerialPort = require('serialport')
const Readline = require('@serialport/parser-readline')
const port = new SerialPort('/dev/tty-usbserial1')
const parser = new Readline()
port.pipe(parser)
// Here we wait for data and do console.log
parser.on('data', console.log)
// Here we send data and do nothing else
port.write('ROBOT PLEASE RESPOND\n')
``` const SerialPort = require('serialport')
const port = new SerialPort('/dev/ttyAMA0', {
baudRate: 9600,
autoOpen: false
},function(err){
console.log(err);
})
setTimeout(function(){
port.open(function (err) {
if (err) {
return console.log('Error opening port: ', err.message)
}
})
},5000);
// The open event is always emitted
port.on('open', function() {
// open logic
console.log('opened ')
var buf = new Buffer([ 0xC1, 0xC1, 0xC1 ]);
port.write(buf, function(err,n) {
if (err) {
return console.log('Error on write: ', err.message)
}
console.log('message written')
})
}) ```