mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Patch for serial node - if no delimiter selected then it was holding onto the last character in the buffer.
This commit is contained in:
parent
0ecbbca7e4
commit
019a4ff397
@ -123,10 +123,18 @@ var serialPool = function() {
|
|||||||
}
|
}
|
||||||
newline = newline.replace("\\n","\n").replace("\\r","\r");
|
newline = newline.replace("\\n","\n").replace("\\r","\r");
|
||||||
var setupSerial = function() {
|
var setupSerial = function() {
|
||||||
obj.serial = new serialp.SerialPort(port,{
|
if (newline == "") {
|
||||||
baudrate: baud,
|
obj.serial = new serialp.SerialPort(port,{
|
||||||
parser: serialp.parsers.readline(newline)
|
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) {
|
obj.serial.on('error', function(err) {
|
||||||
util.log("[serial] serial port "+port+" error "+err);
|
util.log("[serial] serial port "+port+" error "+err);
|
||||||
obj.tout = setTimeout(function() {
|
obj.tout = setTimeout(function() {
|
||||||
@ -147,7 +155,15 @@ var serialPool = function() {
|
|||||||
obj._emitter.emit('ready');
|
obj._emitter.emit('ready');
|
||||||
});
|
});
|
||||||
obj.serial.on('data',function(d) {
|
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);
|
obj._emitter.emit('data',d);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setupSerial();
|
setupSerial();
|
||||||
|
Loading…
Reference in New Issue
Block a user