command view -> properties

This commit is contained in:
Yoonseok Hur 2023-11-21 12:20:38 +09:00
parent ded05cb5b7
commit 1612c103c7
2 changed files with 36 additions and 46 deletions

View File

@ -25,12 +25,13 @@ module.exports = function(RED) {
this.dsr = n.dsr || "none";
this.bin = n.bin || "false";
this.out = n.out || "char";
this.enable = n.enable || true;
this.waitfor = n.waitfor || "";
this.responsetimeout = n.responsetimeout || 10000;
this.changePort = (serialPort) => {
serialPool.close(this.serialport,() => {});
this.serialport = serialPort.newport;
this.serialport = serialPort.serialport || this.serialport;
this.serialbaud = parseInt(serialPort.serialbaud) || this.serialbaud;
this.databits = parseInt(serialPort.databits) || this.databits;
this.parity = serialPort.parity || this.parity;
@ -41,9 +42,7 @@ module.exports = function(RED) {
this.dsr = serialPort.dsr || this.dsr;
this.bin = serialPort.bin || this.bin;
this.out = serialPort.out || this.out;
this.waitfor = serialPort.waitfor || this.waitfor;
this.responsetimeout = n.responsetimeout || 10000;
return serialPool.get(this);
this.enable = serialPort.enable || this.enable;
}
};
@ -227,6 +226,10 @@ module.exports = function(RED) {
// Serial Control Node
function PortSelectNode(n) {
const configProps = [
"serialport", "serialbaud", "databits", "parity", "stopbits",
"dtr", "rts", "cts", "dsr", "bin", "out"
]
RED.nodes.createNode(this,n);
this.serialConfig = RED.nodes.getNode(n.serial);
@ -239,23 +242,20 @@ module.exports = function(RED) {
var node = this;
node.port = serialPool.get(this.serialConfig);
node.on("input",function(msg) {
if (msg.payload.hasOwnProperty("config")) {
if (msg.payload.config === "query") {
node.send({payload: node.serialConfig});
} 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});
msg.payload.enable = msg.payload.hasOwnProperty("enable") ? msg.payload.enable : true;
if (configProps.some((p) =>{return msg.payload.hasOwnProperty(p)})) {
node.serialConfig.changePort(msg.payload);
}
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);

View File

@ -95,42 +95,32 @@
</script>
<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>
<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>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>query the serial port configuration.</li>
<li>query the serial port configuration if empty or no valid configuration parameters are passed.</li>
</ul>
<h3>Inputs</h3>
<p>In order to control the communication, just send these JSON messages to the control node.</p>
<ul>
<li>
<code>{ "stop":"" }</code> stops the communication
</li>
<li>
<code>{ "stop":"" }</code> starts the communication
</li>
<li>
<code> {
"config" : {
"newport": "/dev/tty.usbmodem1234561",
"serialbaud": 115200,
"databits": 8,
"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>
<code>
{
"serialport": "/dev/tty.usbmodem1234561",
"serialbaud": 115200,
"databits": 8,
"parity": "none",
"stopbits": 1
"enable": true
}
</code> changes the serial port and the configuration on the fly.
The following parameters are optional and will change the configuration only if they are present.
"serialport", "serialbaud", "databits", "parity", "stopbits", "dtr", "rts", "cts", "dsr", "bin", "out"
<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.
<h3>Outputs</h3>