Patch for serial node - if no delimiter selected then it was holding onto the last character in the buffer.

This commit is contained in:
Dave C-J 2013-09-23 08:28:40 +01:00
parent 0ecbbca7e4
commit 019a4ff397
1 changed files with 20 additions and 4 deletions

View File

@ -123,10 +123,18 @@ var serialPool = function() {
}
newline = newline.replace("\\n","\n").replace("\\r","\r");
var setupSerial = function() {
obj.serial = new serialp.SerialPort(port,{
baudrate: baud,
parser: serialp.parsers.readline(newline)
});
if (newline == "") {
obj.serial = new serialp.SerialPort(port,{
baudrate: baud,
parser: serialp.parsers.raw
});
}
else {
obj.serial = new serialp.SerialPort(port,{
baudrate: baud,
parser: serialp.parsers.readline(newline)
});
}
obj.serial.on('error', function(err) {
util.log("[serial] serial port "+port+" error "+err);
obj.tout = setTimeout(function() {
@ -147,7 +155,15 @@ var serialPool = function() {
obj._emitter.emit('ready');
});
obj.serial.on('data',function(d) {
if (typeof d !== "string") {
d = d.toString();
for (i=0; i<d.length; i++) {
obj._emitter.emit('data',d.charAt(i));
}
}
else {
obj._emitter.emit('data',d);
}
});
}
setupSerial();