Thursday, 18 July 2019

How to parse data from serial with node ?

Hi, i'm trying to parse data receveid from serial, i want to parse all data between "[ <---->]" (json array)and how can i extract the data from "serialPort.on('data'')" and re use it ?​With JSON.stringify data is :​"[{temperature:26.10, humidite:6.00}]" ​but match with regex return null every times ;s​Any idea ?serialPort.on("open", function () { console.log('open serial communication'); // Listens to incoming data serialPort.on('data', function(data) { var CurrentVar = data.toString('utf8').replace(/\n/g, ''); CurrentVar = CurrentVar.replace(/\r/g, ''); //console.log(JSON.stringify(encodeURI(CurrentVar))); console.log(JSON.stringify(CurrentVar)); var Current = JSON.stringify(CurrentVar).match(/\(([^)]+)\)/gi); if(Current != null){ console.log(Current); } }); });

Submitted July 18, 2019 at 10:56AM by diapoelledicietla

No comments:

Post a Comment