Skip to content

Instantly share code, notes, and snippets.

@Casear
Created December 20, 2016 04:15
Show Gist options
  • Save Casear/cf01265bf857c223e1926e4f15ea4541 to your computer and use it in GitHub Desktop.
Save Casear/cf01265bf857c223e1926e4f15ea4541 to your computer and use it in GitHub Desktop.
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyS0", {
baudrate: 9600
});
serialPort.on("open", function() {
serialPort.on('data', function(data) {
console.log(data.toString())
})
var stdin = process.openStdin();
stdin.addListener("data", function(d) {
serialPort.write(d.toString()+'\n')
console.log("you send: [" + d.toString().trim() + "]");
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment