Skip to content

Instantly share code, notes, and snippets.

@Casear
Created December 5, 2016 15:57
Show Gist options
  • Save Casear/2b4fe5e930d9e315af243f493f26d7df to your computer and use it in GitHub Desktop.
Save Casear/2b4fe5e930d9e315af243f493f26d7df to your computer and use it in GitHub Desktop.
test-serial.js
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