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

@@ -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');