Created
February 17, 2023 10:15
-
-
Save zoutepopcorn/09db89f3af9991f759725bd9f9269ee5 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
const serialport = require('serialport'); | |
const SerialPort = serialport.SerialPort; | |
const PORT = "/dev/ttyUSB0"; | |
serialPort = new SerialPort({ | |
path: PORT, | |
baudRate: 115200, | |
}); | |
serialPort.on("open", () => { | |
console.log("-- Connection opened --"); | |
serialPort.on("data", (data) => { | |
const SERIAL_IN = data.toString(); | |
const [from, command] = SERIAL_IN.split("::").filter(Boolean); | |
console.log(`from: \t\t${from}`); | |
console.log(`command: \t${command}`); | |
}); | |
}); |
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
{ | |
"name": "serial", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"serialport": "^10.5.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment