Browse Source

Upload files to ''

master
cs171027 5 years ago
parent
commit
d90a801f41
  1. 31
      nodeserial.js

31
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);
});
Loading…
Cancel
Save