1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Add msg.port to serial port input node

This commit is contained in:
Dave Conway-Jones 2018-03-01 18:21:22 +00:00
parent 26458522dd
commit 0253f67882
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 8 additions and 7 deletions

View File

@ -16,6 +16,7 @@
<li>Wait for a timeout in milliseconds from the first character received</li> <li>Wait for a timeout in milliseconds from the first character received</li>
<li>Wait to fill a fixed sized buffer</li></ul></p> <li>Wait to fill a fixed sized buffer</li></ul></p>
<p>It then outputs <code>msg.payload</code> as either a UTF8 ascii string or a binary Buffer object.</p> <p>It then outputs <code>msg.payload</code> as either a UTF8 ascii string or a binary Buffer object.</p>
<p><code>msg.port</code> is set to the name of the port selected.</p>
<p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters <p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters
is sent - again either as ascii chars or size 1 binary buffers.</p> is sent - again either as ascii chars or size 1 binary buffers.</p>
</script> </script>

View File

@ -117,8 +117,8 @@ module.exports = function(RED) {
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), port:node.serialConfig.serialport}); }
else { node.send({"payload": new Buffer([msg])}); } else { node.send({"payload": new Buffer([msg]), port:node.serialConfig.serialport}); }
} }
else { else {
// do the timer thing // do the timer thing
@ -133,7 +133,7 @@ module.exports = function(RED) {
var m = new Buffer(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, port:node.serialConfig.serialport});
m = null; m = null;
}, node.serialConfig.newline); }, node.serialConfig.newline);
i = 0; i = 0;
@ -148,7 +148,7 @@ module.exports = function(RED) {
var m = new Buffer(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, port:node.serialConfig.serialport});
m = null; m = null;
i = 0; i = 0;
} }
@ -161,7 +161,7 @@ module.exports = function(RED) {
var n = new Buffer(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, port:node.serialConfig.serialport});
n = null; n = null;
i = 0; i = 0;
} }

View File

@ -1,9 +1,9 @@
{ {
"name" : "node-red-node-serialport", "name" : "node-red-node-serialport",
"version" : "0.6.4", "version" : "0.6.5",
"description" : "Node-RED nodes to talk to serial ports", "description" : "Node-RED nodes to talk to serial ports",
"dependencies" : { "dependencies" : {
"serialport" : "^6.0.5" "serialport" : "^6.1.1"
}, },
"repository" : { "repository" : {
"type":"git", "type":"git",