自定义parsing器的节点串行端口?

随着像STX(0x02)..Data..ETX(0x03)数据STX(0x02)..Data..ETX(0x03)

我可以通过byte sequence parser来处理数据:

 var SerialPort = require('serialport'); var port = new SerialPort('/dev/tty-usbserial1', { parser: SerialPort.parsers.byteDelimiter([3]) }); port.on('data', function (data) { console.log('Data: ' + data); }); 

但是我的实际数据是STX(0x02)..Data..ETX(0x03)..XX(plus 2 characters to validate data)

我怎样才能得到适当的数据?

谢谢!

       

网上收集的解决方案 "自定义parsing器的节点串行端口?"

解决了!

我写我自己的parsing器:

 var SerialPort = require('serialport'); var incommingData = new Buffer(0); var myParser = function(emitter, buffer) { incommingData = Buffer.concat([incommingData, buffer]); if (incommingData.length > 3 && incommingData[incommingData.length - 3] == 3) { emitter.emit("data", incommingData); incommingData = new Buffer(0); } }; var port = new SerialPort('COM1', {parser: myParser}); port.on('data', function(data) { console.log(data); });