Skip to content

Instantly share code, notes, and snippets.

@winhtut
Last active August 2, 2019 15:49
Show Gist options
  • Save winhtut/15ca2ea1f4d5bcb5799cc24b62fbea8c to your computer and use it in GitHub Desktop.
Save winhtut/15ca2ea1f4d5bcb5799cc24b62fbea8c to your computer and use it in GitHub Desktop.
var serialport=require("serialport");
console.log("hi");
var port=new serialport('/dev/ttyACM0',{
baudRate:9600
});
const Readline=serialport.parsers.Readline;
const parser=new Readline();
port.pipe(parser);
port.on('open',onPortOpen);
parser.on('data',onData);
port.on('close',onClose);
port.on('error',onError);
port.write('Hi');
function onPortOpen(){
console.log("port open ");
}
function onData(data){
console.log("data received"+data);
}
function onClose(){
console.log("port closed");
}
function onError(){
console.log("Something went wrong in serial communication");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment