From ae2d601b22b600bd192b068fafd4d9234ce89895 Mon Sep 17 00:00:00 2001 From: d-tamm Date: Wed, 4 Dec 2019 15:03:58 +0100 Subject: [PATCH] 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. --- io/serialport/25-serial.html | 43 +++++++++++++++++++++- io/serialport/25-serial.js | 15 ++++++++ io/serialport/locales/en-US/25-serial.json | 5 +++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/io/serialport/25-serial.html b/io/serialport/25-serial.html index 0021e99b..5782b72c 100644 --- a/io/serialport/25-serial.html +++ b/io/serialport/25-serial.html @@ -155,7 +155,7 @@ - +   @@ -175,12 +175,46 @@ - +
+ + + + + + + + + + + + + + + +
DTRRTSCTSDSR
+
@@ -239,6 +273,7 @@

Provides configuration options for a serial port.

The search button should return a list of available serial ports to choose from, or you can type in the location if known.

+

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.

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.

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).

@@ -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"}, diff --git a/io/serialport/25-serial.js b/io/serialport/25-serial.js index 6fdd34a8..17035d14 100644 --- a/io/serialport/25-serial.js +++ b/io/serialport/25-serial.js @@ -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'); diff --git a/io/serialport/locales/en-US/25-serial.json b/io/serialport/locales/en-US/25-serial.json index 46ea9641..da669763 100644 --- a/io/serialport/locales/en-US/25-serial.json +++ b/io/serialport/locales/en-US/25-serial.json @@ -33,6 +33,11 @@ "odd": "Odd", "space": "Space" }, + "linestates": { + "none": "", + "high": "High", + "low": "Low" + }, "split": { "character": "on the character", "timeout": "after a timeout of",