From 7c7f030aa8e8a2e8c6ea80c8de59f9a736a85563 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Tue, 24 Jun 2014 22:27:02 +0100 Subject: [PATCH] Tweak serial to outpur correct number of chars from buffer. Having counted the correct number into the buffer it seems a shame not to send them all out to the next node... (Also allow separator char to be specified as hex (eg 0x0a)) --- nodes/core/io/25-serial.html | 5 ++--- nodes/core/io/25-serial.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nodes/core/io/25-serial.html b/nodes/core/io/25-serial.html index aad37dce8..225e4dc3b 100644 --- a/nodes/core/io/25-serial.html +++ b/nodes/core/io/25-serial.html @@ -27,10 +27,9 @@ diff --git a/nodes/core/io/25-serial.js b/nodes/core/io/25-serial.js index a24dcdf03..5a3f92d1d 100644 --- a/nodes/core/io/25-serial.js +++ b/nodes/core/io/25-serial.js @@ -114,7 +114,13 @@ module.exports = function(RED) { this.serialConfig.stopbits, this.serialConfig.newline ); - var splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); + + if (node.serialConfig.newline.substr(0,2) == "0x") { + var splitc = new Buffer([parseInt(node.serialConfig.newline)]); + } else { + var splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); + } + this.port.on('data', function(msg) { // single char buffer if ((node.serialConfig.newline == 0)||(node.serialConfig.newline == "")) { @@ -145,9 +151,9 @@ module.exports = function(RED) { else if (node.serialConfig.out === "count") { buf[i] = msg; i += 1; - if ( i >= Number(node.serialConfig.newline)) { + if ( i >= parseInt(node.serialConfig.newline)) { var m = new Buffer(i); - buf.copy(m,0,0,i-1); + buf.copy(m,0,0,i); if (node.serialConfig.bin !== "bin") { m = m.toString(); } node.send({"payload":m}); m = null;