Last active
August 2, 2019 15:49
-
-
Save winhtut/15ca2ea1f4d5bcb5799cc24b62fbea8c to your computer and use it in GitHub Desktop.
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"); | |
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