"revert" serial port and base64 nodes forwards....

undo buffer syntax updates
This commit is contained in:
Dave Conway-Jones 2017-06-30 19:52:20 +01:00
parent 0609645375
commit f6e71bf962
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
4 changed files with 13 additions and 13 deletions

View File

@ -52,7 +52,7 @@ module.exports = function(RED) {
payload += node.addCh; payload += node.addCh;
} }
else if (node.addCh !== "") { else if (node.addCh !== "") {
payload = Buffer.concat([payload,new Buffer.from(node.addCh)]); payload = Buffer.concat([payload,new Buffer(node.addCh)]);
} }
node.port.write(payload,function(err,res) { node.port.write(payload,function(err,res) {
if (err) { if (err) {
@ -94,8 +94,8 @@ module.exports = function(RED) {
var node = this; var node = this;
node.tout = null; node.tout = null;
var buf; var buf;
if (node.serialConfig.out != "count") { buf = new Buffer.alloc(bufMaxSize); } if (node.serialConfig.out != "count") { buf = new Buffer(bufMaxSize); }
else { buf = new Buffer.alloc(Number(node.serialConfig.newline)); } else { buf = new Buffer(Number(node.serialConfig.newline)); }
var i = 0; var i = 0;
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"}); node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"});
node.port = serialPool.get(this.serialConfig.serialport, node.port = serialPool.get(this.serialConfig.serialport,
@ -108,17 +108,17 @@ module.exports = function(RED) {
var splitc; var splitc;
if (node.serialConfig.newline.substr(0,2) == "0x") { if (node.serialConfig.newline.substr(0,2) == "0x") {
splitc = new Buffer.from([parseInt(node.serialConfig.newline)]); splitc = new Buffer([parseInt(node.serialConfig.newline)]);
} }
else { else {
splitc = new Buffer.from(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line
} }
this.port.on('data', function(msg) { this.port.on('data', function(msg) {
// single char buffer // single char buffer
if ((node.serialConfig.newline === 0)||(node.serialConfig.newline === "")) { if ((node.serialConfig.newline === 0)||(node.serialConfig.newline === "")) {
if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); } if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); }
else { node.send({"payload": new Buffer.from([msg])}); } else { node.send({"payload": new Buffer([msg])}); }
} }
else { else {
// do the timer thing // do the timer thing
@ -130,7 +130,7 @@ module.exports = function(RED) {
else { else {
node.tout = setTimeout(function () { node.tout = setTimeout(function () {
node.tout = null; node.tout = null;
var m = new Buffer.alloc(i+1); var m = new Buffer(i+1);
buf.copy(m,0,0,i+1); buf.copy(m,0,0,i+1);
if (node.serialConfig.bin !== "bin") { m = m.toString(); } if (node.serialConfig.bin !== "bin") { m = m.toString(); }
node.send({"payload": m}); node.send({"payload": m});
@ -145,7 +145,7 @@ module.exports = function(RED) {
buf[i] = msg; buf[i] = msg;
i += 1; i += 1;
if ( i >= parseInt(node.serialConfig.newline)) { if ( i >= parseInt(node.serialConfig.newline)) {
var m = new Buffer.alloc(i); var m = new Buffer(i);
buf.copy(m,0,0,i); buf.copy(m,0,0,i);
if (node.serialConfig.bin !== "bin") { m = m.toString(); } if (node.serialConfig.bin !== "bin") { m = m.toString(); }
node.send({"payload":m}); node.send({"payload":m});
@ -158,7 +158,7 @@ module.exports = function(RED) {
buf[i] = msg; buf[i] = msg;
i += 1; i += 1;
if ((msg === splitc[0]) || (i === bufMaxSize)) { if ((msg === splitc[0]) || (i === bufMaxSize)) {
var n = new Buffer.alloc(i); var n = new Buffer(i);
buf.copy(n,0,0,i); buf.copy(n,0,0,i);
if (node.serialConfig.bin !== "bin") { n = n.toString(); } if (node.serialConfig.bin !== "bin") { n = n.toString(); }
node.send({"payload":n}); node.send({"payload":n});

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-serialport", "name" : "node-red-node-serialport",
"version" : "0.4.3", "version" : "0.4.4",
"description" : "Node-RED nodes to talk to serial ports", "description" : "Node-RED nodes to talk to serial ports",
"dependencies" : { "dependencies" : {
"serialport" : "~4.0.7" "serialport" : "~4.0.7"

View File

@ -16,12 +16,12 @@ module.exports = function(RED) {
// Take base64 string and make into binary buffer // Take base64 string and make into binary buffer
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$'); var regexp = new RegExp('^[A-Za-z0-9+\/=]*$');
if ( regexp.test(msg.payload) && (msg.payload.length % 4 === 0) ) { if ( regexp.test(msg.payload) && (msg.payload.length % 4 === 0) ) {
msg.payload = new Buffer.from(msg.payload,'base64'); msg.payload = new Buffer(msg.payload,'base64');
node.send(msg); node.send(msg);
} }
else { else {
//node.log("Not a Base64 string - maybe we should encode it..."); //node.log("Not a Base64 string - maybe we should encode it...");
msg.payload = (new Buffer.from(msg.payload,"binary")).toString('base64'); msg.payload = (new Buffer(msg.payload,"binary")).toString('base64');
node.send(msg); node.send(msg);
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-base64", "name" : "node-red-node-base64",
"version" : "0.0.5", "version" : "0.0.6",
"description" : "A Node-RED node to pack and unpack objects to base64 format", "description" : "A Node-RED node to pack and unpack objects to base64 format",
"dependencies" : { "dependencies" : {
}, },