Skip to content

Instantly share code, notes, and snippets.

@chrwei
Created November 25, 2015 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrwei/e76e38633f54233048e5 to your computer and use it in GitHub Desktop.
Save chrwei/e76e38633f54233048e5 to your computer and use it in GitHub Desktop.
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