cs171027
5 years ago
1 changed files with 31 additions and 0 deletions
@ -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…
Reference in new issue