1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
This commit is contained in:
Dave Conway-Jones 2019-12-04 14:04:13 +00:00
commit aa8dc4f7a1
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
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="110px" data-i18n="serial.label.baudrate"></td>
<td width="70px" data-i18n="serial.label.databits"></td> <td width="70px" data-i18n="serial.label.databits"></td>
<td width="80px" data-i18n="serial.label.parity"></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> </tr><tr><td>&nbsp;</td>
<td> <td>
<input type="text" id="node-config-input-serialbaud" style="width:92%"> <input type="text" id="node-config-input-serialbaud" style="width:92%">
@ -175,12 +175,46 @@
<option value="space" data-i18n="serial.parity.space"></option> <option value="space" data-i18n="serial.parity.space"></option>
</select> </select>
</td><td> </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="2">2</option>
<option value="1">1</option> <option value="1">1</option>
</select> </select>
</td></tr></table> </td></tr></table>
</div> </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;"> <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> <label><i class="fa fa-sign-in"></i> <span data-i18n="serial.label.input"></span></label>
</div> </div>
@ -239,6 +273,7 @@
<p>Provides configuration options for a serial port.</p> <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 <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> 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. <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> 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> <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}, parity: {value:"none",required:true},
stopbits: {value:1,required:true}, stopbits: {value:1,required:true},
waitfor: {value:""}, waitfor: {value:""},
dtr: {value:"none"},
rts: {value:"none"},
cts: {value:"none"},
dsr: {value:"none"},
newline: {value:"\\n"}, newline: {value:"\\n"},
bin: {value:"false"}, bin: {value:"false"},
out: {value:"char"}, out: {value:"char"},

View File

@ -18,6 +18,10 @@ module.exports = function(RED) {
this.databits = parseInt(n.databits) || 8; this.databits = parseInt(n.databits) || 8;
this.parity = n.parity || "none"; this.parity = n.parity || "none";
this.stopbits = parseInt(n.stopbits) || 1; 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.bin = n.bin || "false";
this.out = n.out || "char"; this.out = n.out || "char";
this.waitfor = n.waitfor || ""; this.waitfor = n.waitfor || "";
@ -179,6 +183,10 @@ module.exports = function(RED) {
databits = serialConfig.databits, databits = serialConfig.databits,
parity = serialConfig.parity, parity = serialConfig.parity,
stopbits = serialConfig.stopbits, stopbits = serialConfig.stopbits,
dtr = serialConfig.dtr,
rts = serialConfig.rts,
cts = serialConfig.cts,
dsr = serialConfig.dsr,
newline = serialConfig.newline, newline = serialConfig.newline,
spliton = serialConfig.out, spliton = serialConfig.out,
waitfor = serialConfig.waitfor, waitfor = serialConfig.waitfor,
@ -342,6 +350,13 @@ module.exports = function(RED) {
obj.serial.on('open',function() { obj.serial.on('open',function() {
olderr = ""; olderr = "";
RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits})); 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; } if (obj.tout) { clearTimeout(obj.tout); obj.tout = null; }
//obj.serial.flush(); //obj.serial.flush();
obj._emitter.emit('ready'); obj._emitter.emit('ready');

View File

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