You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
648 B
32 lines
648 B
5 years ago
|
//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);
|
||
|
|
||
|
});
|
||
|
|
||
|
|