From d90a801f415219c7703bfc96373da29645867b6e Mon Sep 17 00:00:00 2001 From: cs171027 Date: Wed, 22 Jan 2020 04:32:16 +0000 Subject: [PATCH] Upload files to '' --- nodeserial.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 nodeserial.js diff --git a/nodeserial.js b/nodeserial.js new file mode 100644 index 0000000..f045e29 --- /dev/null +++ b/nodeserial.js @@ -0,0 +1,31 @@ + //Configure serial connection with serial port "/dev/ttyACM0" + var SerialPort = require('serialport'); + + var port=new SerialPort('/dev/ttyACM0', { + + baudRate: 115200 + + }); + + //initialize json Objects + var jsonData=SerialPort.parsers.Readline; + + var jsonParser=new jsonData(); + + port.pipe(jsonParser); + + jsonParser.on('data', function (data) { + + jsonStr=data.toString(); //Convert to string + + jsonStr=jsonStr.replace("\/r?\n|\r/g",""); //remove tab from this String + + jsonStr=JSON.stringify(data); //Convert string to json + + jsonStr=JSON.parse(data); //Parse JSON data from json object 'str' + + console.log(jsonStr); + +}); + +