Add flow control switches to serialport (#579)

* Fix alignment of baud rate setting.

* Add flow control flags DTR and RTS.

* Add flags for flow control RTS and DTR.

* Add pin states for flow control flags

* Change pinstates to linestates

* Remove help text about DTR/RTS defaulting to low.

* Collect flow control setting into one single command.

* Add curly braces.

* Add more curly braces.

* Add CTS and DSR settings. Add default none option. Change settings layout for flow control.
This commit is contained in:
d-tamm 2019-12-04 15:03:58 +01:00 committed by Dave Conway-Jones
parent 23f584268a
commit ae2d601b22
3 changed files with 61 additions and 2 deletions

View File

@ -155,7 +155,7 @@
<td width="110px" data-i18n="serial.label.baudrate"></td>
<td width="70px" data-i18n="serial.label.databits"></td>
<td width="80px" data-i18n="serial.label.parity"></td>
<td width="70px" data-i18n="serial.label.stopbits"></td>
<td data-i18n="serial.label.stopbits"></td>
</tr><tr><td>&nbsp;</td>
<td>
<input type="text" id="node-config-input-serialbaud" style="width:92%">
@ -175,12 +175,46 @@
<option value="space" data-i18n="serial.parity.space"></option>
</select>
</td><td>
<select type="text" id="node-config-input-stopbits" style="width:90%;">
<select type="text" id="node-config-input-stopbits" style="width:60px;">
<option value="2">2</option>
<option value="1">1</option>
</select>
</td></tr></table>
</div>
<div class="form-row">
<table width="100%">
<tr>
<td width="100px"></td>
<td width="90px">DTR</td>
<td width="90px">RTS</td>
<td width="90px">CTS</td>
<td>DSR</td>
</tr>
<tr>
<td></td>
<td><select type="text" id="node-config-input-dtr" style="width:80px;">
<option value="none" data-i18n="serial.linestates.none"></option>
<option value="high" data-i18n="serial.linestates.high"></option>
<option value="low" data-i18n="serial.linestates.low"></option>
</select></td>
<td><select type="text" id="node-config-input-rts" style="width:80px;">
<option value="none" data-i18n="serial.linestates.none"></option>
<option value="high" data-i18n="serial.linestates.high"></option>
<option value="low" data-i18n="serial.linestates.low"></option>
</select></td>
<td><select type="text" id="node-config-input-cts" style="width:80px;">
<option value="none" data-i18n="serial.linestates.none"></option>
<option value="high" data-i18n="serial.linestates.high"></option>
<option value="low" data-i18n="serial.linestates.low"></option>
</select></td>
<td><select type="text" id="node-config-input-dsr" style="width:80px;">
<option value="none" data-i18n="serial.linestates.none"></option>
<option value="high" data-i18n="serial.linestates.high"></option>
<option value="low" data-i18n="serial.linestates.low"></option>
</select></td>
</tr>
</table>
</div>
<div class="form-row" style="margin-top:16px; margin-bottom:0;">
<label><i class="fa fa-sign-in"></i> <span data-i18n="serial.label.input"></span></label>
</div>
@ -239,6 +273,7 @@
<p>Provides configuration options for a serial port.</p>
<p>The search button should return a list of available serial ports to choose from, or you
can type in the location if known.</p>
<p>The DTR, RTS, CTS and DSR switches can be used to permanently pull the corresponding flow control pin high or low, e.g. in order to power devices via those pins.</p>
<p>The node can optionally wait until it matches a pre-defined character.
The data can then be split on a fixed character, after a timeout, or after a fixed number of characters.</p>
<p>If using a character, it can be specified as either the character, the escaped shortcut (e.g. \n), or the hex code (e.g. 0x0d).</p>
@ -255,6 +290,10 @@
parity: {value:"none",required:true},
stopbits: {value:1,required:true},
waitfor: {value:""},
dtr: {value:"none"},
rts: {value:"none"},
cts: {value:"none"},
dsr: {value:"none"},
newline: {value:"\\n"},
bin: {value:"false"},
out: {value:"char"},

View File

@ -18,6 +18,10 @@ module.exports = function(RED) {
this.databits = parseInt(n.databits) || 8;
this.parity = n.parity || "none";
this.stopbits = parseInt(n.stopbits) || 1;
this.dtr = n.dtr || "none";
this.rts = n.rts || "none";
this.cts = n.cts || "none";
this.dsr = n.dsr || "none";
this.bin = n.bin || "false";
this.out = n.out || "char";
this.waitfor = n.waitfor || "";
@ -179,6 +183,10 @@ module.exports = function(RED) {
databits = serialConfig.databits,
parity = serialConfig.parity,
stopbits = serialConfig.stopbits,
dtr = serialConfig.dtr,
rts = serialConfig.rts,
cts = serialConfig.cts,
dsr = serialConfig.dsr,
newline = serialConfig.newline,
spliton = serialConfig.out,
waitfor = serialConfig.waitfor,
@ -342,6 +350,13 @@ module.exports = function(RED) {
obj.serial.on('open',function() {
olderr = "";
RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits}));
// Set flow control pins if necessary. Must be set all in same command.
var flags = {};
if (dtr != "none") { flags.dtr = (dtr!="low"); }
if (rts != "none") { flags.rts = (rts!="low"); }
if (cts != "none") { flags.cts = (cts!="low"); }
if (dsr != "none") { flags.dsr = (dsr!="low"); }
if (dtr != "none" || rts != "none" || cts != "none" || dsr != "none") { obj.serial.set(flags); }
if (obj.tout) { clearTimeout(obj.tout); obj.tout = null; }
//obj.serial.flush();
obj._emitter.emit('ready');

View File

@ -33,6 +33,11 @@
"odd": "Odd",
"space": "Space"
},
"linestates": {
"none": "",
"high": "High",
"low": "Low"
},
"split": {
"character": "on the character",
"timeout": "after a timeout of",