Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/home/root/tty1", {
baudrate: 115200
});
var count = 0;
serialPort.on("open", function () {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
count++;
if(count >= 6) {
console.log('sending A');
serialPort.write("A", function(err, results) {
if(err) console.log('err ' + err);
});
count = 0;
}
if(count == 3) {
console.log('sending B');
serialPort.write("B", function(err, results) {
if(err) console.log('err ' + err);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.