Browse Source

Incoming serial data is llap-packetized.

master
flabbergast 9 years ago
parent
commit
e70f196eef
  1. 13
      modules/serial_node.js

13
modules/serial_node.js

@ -87,10 +87,21 @@ var detectSerialOnRaspberryPI = function()
});
}
var incomingData = "";
var llapParser = function(emitter, buffer){
incomingData += buffer.toString();
// remove any stuff before a signature 'a' appears
incomingData = incomingData.replace(/^[^]*?a/,'a');
while (incomingData.length >= 12) {
emitter.emit('data',incomingData.substr(0,12));
incomingData = incomingData.substr(12).replace(/^[^]*?a/,'a');
}
}
var attemptConnection = function(port)
{
console.log('* attempting to connect to serial at :', port, ' *');
serport = new serialport.SerialPort(port, { baudrate: 9600 });
serport = new serialport.SerialPort(port, { baudrate: 9600, parser: llapParser });
serport.on("open", function () {
console.log('* connection to a serial port successful ! *');
serport.on('data', function(data){

Loading…
Cancel
Save