Created
December 5, 2016 15:57
-
-
Save Casear/2b4fe5e930d9e315af243f493f26d7df to your computer and use it in GitHub Desktop.
test-serial.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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