mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
command view -> properties
This commit is contained in:
parent
ded05cb5b7
commit
1612c103c7
@ -25,12 +25,13 @@ module.exports = function(RED) {
|
|||||||
this.dsr = n.dsr || "none";
|
this.dsr = n.dsr || "none";
|
||||||
this.bin = n.bin || "false";
|
this.bin = n.bin || "false";
|
||||||
this.out = n.out || "char";
|
this.out = n.out || "char";
|
||||||
|
this.enable = n.enable || true;
|
||||||
this.waitfor = n.waitfor || "";
|
this.waitfor = n.waitfor || "";
|
||||||
this.responsetimeout = n.responsetimeout || 10000;
|
this.responsetimeout = n.responsetimeout || 10000;
|
||||||
|
|
||||||
this.changePort = (serialPort) => {
|
this.changePort = (serialPort) => {
|
||||||
serialPool.close(this.serialport,() => {});
|
serialPool.close(this.serialport,() => {});
|
||||||
this.serialport = serialPort.newport;
|
this.serialport = serialPort.serialport || this.serialport;
|
||||||
this.serialbaud = parseInt(serialPort.serialbaud) || this.serialbaud;
|
this.serialbaud = parseInt(serialPort.serialbaud) || this.serialbaud;
|
||||||
this.databits = parseInt(serialPort.databits) || this.databits;
|
this.databits = parseInt(serialPort.databits) || this.databits;
|
||||||
this.parity = serialPort.parity || this.parity;
|
this.parity = serialPort.parity || this.parity;
|
||||||
@ -41,9 +42,7 @@ module.exports = function(RED) {
|
|||||||
this.dsr = serialPort.dsr || this.dsr;
|
this.dsr = serialPort.dsr || this.dsr;
|
||||||
this.bin = serialPort.bin || this.bin;
|
this.bin = serialPort.bin || this.bin;
|
||||||
this.out = serialPort.out || this.out;
|
this.out = serialPort.out || this.out;
|
||||||
this.waitfor = serialPort.waitfor || this.waitfor;
|
this.enable = serialPort.enable || this.enable;
|
||||||
this.responsetimeout = n.responsetimeout || 10000;
|
|
||||||
return serialPool.get(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -227,6 +226,10 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// Serial Control Node
|
// Serial Control Node
|
||||||
function PortSelectNode(n) {
|
function PortSelectNode(n) {
|
||||||
|
const configProps = [
|
||||||
|
"serialport", "serialbaud", "databits", "parity", "stopbits",
|
||||||
|
"dtr", "rts", "cts", "dsr", "bin", "out"
|
||||||
|
]
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.serialConfig = RED.nodes.getNode(n.serial);
|
this.serialConfig = RED.nodes.getNode(n.serial);
|
||||||
|
|
||||||
@ -239,23 +242,20 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
node.port = serialPool.get(this.serialConfig);
|
node.port = serialPool.get(this.serialConfig);
|
||||||
node.on("input",function(msg) {
|
node.on("input",function(msg) {
|
||||||
if (msg.payload.hasOwnProperty("config")) {
|
msg.payload.enable = msg.payload.hasOwnProperty("enable") ? msg.payload.enable : true;
|
||||||
if (msg.payload.config === "query") {
|
if (configProps.some((p) =>{return msg.payload.hasOwnProperty(p)})) {
|
||||||
node.send({payload: node.serialConfig});
|
node.serialConfig.changePort(msg.payload);
|
||||||
} else {
|
|
||||||
node.serialConfig.changePort(msg.payload.config);
|
|
||||||
node.serialConfig.emit('start',msg.payload.config);
|
|
||||||
node.send({payload: msg.payload.config});
|
|
||||||
}
|
|
||||||
} else if (msg.payload.hasOwnProperty("start")) {
|
|
||||||
node.serialConfig.emit('start',msg.payload);
|
|
||||||
node.send({payload: node.serialConfig});
|
|
||||||
} else if (msg.payload.hasOwnProperty("stop")) {
|
|
||||||
serialPool.close(node.serialConfig.serialport,() => {
|
|
||||||
RED.log.info("[serialconfig:"+node.serialConfig.id+"] " + RED._("serial.stopped",{port:node.serialConfig.serialport}));
|
|
||||||
});
|
|
||||||
node.send({payload: node.serialConfig});
|
|
||||||
}
|
}
|
||||||
|
if (msg.payload.hasOwnProperty("enable")) {
|
||||||
|
if (msg.payload.enable === true) {
|
||||||
|
node.serialConfig.emit('start');
|
||||||
|
} else {
|
||||||
|
serialPool.close(node.serialConfig.serialport,() => {
|
||||||
|
RED.log.info("[serialconfig:"+node.serialConfig.id+"] " + RED._("serial.stopped",{port:node.serialConfig.serialport}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.send({payload: node.serialConfig});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("serial control", PortSelectNode);
|
RED.nodes.registerType("serial control", PortSelectNode);
|
||||||
|
@ -95,42 +95,32 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="serial control">
|
<script type="text/html" data-help-name="serial control">
|
||||||
<p>Stops, starts the serial communication and controls the serial port configuration.</p>
|
<p>Stops, starts the serial communication and changes the serial port configuration.</p>
|
||||||
|
|
||||||
<p>This node provides the serial port control capability to</p>
|
<p>This node provides the serial port control capability to</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>stop the communication and releasing the serial port so, for example the Arduino can upload the new binary without shutting down the nodered.</li>
|
<li>stop the communication and releasing the serial port so, for example the Arduino can upload the new binary without shutting down the nodered.</li>
|
||||||
<li>start the communication after stopped with this `Serial Control` node for above reason or the like.</li>
|
<li>start the communication after stopped with this `Serial Control` node for above reason or the like.</li>
|
||||||
<li>change the serial port and the configuration on the run time programatically.</li>
|
<li>change the serial port and the configuration on the run time programatically.</li>
|
||||||
<li>query the serial port configuration.</li>
|
<li>query the serial port configuration if empty or no valid configuration parameters are passed.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>Inputs</h3>
|
<h3>Inputs</h3>
|
||||||
<p>In order to control the communication, just send these JSON messages to the control node.</p>
|
<p>In order to control the communication, just send these JSON messages to the control node.</p>
|
||||||
<ul>
|
<code>
|
||||||
<li>
|
{
|
||||||
<code>{ "stop":"" }</code> stops the communication
|
"serialport": "/dev/tty.usbmodem1234561",
|
||||||
</li>
|
"serialbaud": 115200,
|
||||||
<li>
|
"databits": 8,
|
||||||
<code>{ "stop":"" }</code> starts the communication
|
"parity": "none",
|
||||||
</li>
|
"stopbits": 1
|
||||||
<li>
|
"enable": true
|
||||||
<code> {
|
}
|
||||||
"config" : {
|
</code> changes the serial port and the configuration on the fly.
|
||||||
"newport": "/dev/tty.usbmodem1234561",
|
The following parameters are optional and will change the configuration only if they are present.
|
||||||
"serialbaud": 115200,
|
"serialport", "serialbaud", "databits", "parity", "stopbits", "dtr", "rts", "cts", "dsr", "bin", "out"
|
||||||
"databits": 8,
|
<code>{"enable":true}</code> or <code>{"enable":false}</code> will stop or start the communication. And 'enable' can be passed along with the other configuration parameters as well, which will then change the configuration and either start or just stopped and ready to start.
|
||||||
"parity": "none",
|
|
||||||
"stopbits": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code> changes the serial port and the configuration on the fly. the <code>newport</code> is the mandatory field, and other fields are optional. All of <code>serial-port</code> node specified parameters can be passed to change.
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<code>{ "config":"query" }</code> querys the serial port configuration and returns the result in the <code>msg.payload</code>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user