]> git.basschouten.com Git - openhab-addons.git/commitdiff
[modbus] Add support for after connection delays required by some devices. (#12642)
authorŁukasz Dywicki <luke@code-house.org>
Sat, 7 May 2022 10:02:04 +0000 (12:02 +0200)
committerGitHub <noreply@github.com>
Sat, 7 May 2022 10:02:04 +0000 (12:02 +0200)
Fixes #12641.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
bundles/org.openhab.binding.modbus/README.md
bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusSerialConfiguration.java
bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusTcpConfiguration.java
bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusSerialThingHandler.java
bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusTcpThingHandler.java
bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/i18n/modbus.properties
bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-serial.xml
bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-tcp.xml

index b676b87a1dbf3b9d518be0e7ba03e284faabd045..cd967d5f51c8ee5bebc0336f37986275b399f829 100644 (file)
@@ -122,6 +122,7 @@ Advanced parameters
 | `timeBetweenTransactionsMillis` |          | integer | `60`               | How long to delay we must have at minimum between two consecutive MODBUS transactions. In milliseconds.                                                            |
 | `timeBetweenReconnectMillis`    |          | integer | `0`                | How long to wait to before trying to establish a new connection after the previous one has been disconnected. In milliseconds.                                     |
 | `connectMaxTries`               |          | integer | `1`                | How many times we try to establish the connection. Should be at least 1.                                                                                           |
+| `afterConnectionDelayMillis`    |          | integer | `0`                | Connection warm-up time. Additional time which is spent on preparing connection which should be spent waiting while end device is getting ready to answer first modbus call. In milliseconds.  |
 | `reconnectAfterMillis`          |          | integer | `0`                | The connection is kept open at least the time specified here. Value of zero means that connection is disconnected after every MODBUS transaction. In milliseconds. |
 | `connectTimeoutMillis`          |          | integer | `10000`            | The maximum time that is waited when establishing the connection. Value of zero means that system/OS default is respected. In milliseconds.                        |
 | `enableDiscovery`                |          | boolean | false               | Enable auto-discovery feature. Effective only if a supporting extension has been installed. |
@@ -158,6 +159,7 @@ Advanced parameters
 | `flowControlOut`                |          | text    | `"none"`           | Type of flow control for sending. Valid values are: `"none"`, `"xon/xoff out"`, `"rts/cts out"`.                                           |
 | `timeBetweenTransactionsMillis` |          | integer | `35`               | How long to delay we must have at minimum between two consecutive MODBUS transactions. In milliseconds.                                    |
 | `connectMaxTries`               |          | integer | `1`                | How many times we try to establish the connection. Should be at least 1.                                                                   |
+| `afterConnectionDelayMillis`    |          | integer | `0`                | Connection warm-up time. Additional time which is spent on preparing connection which should be spent waiting while end device is getting ready to answer first modbus call. In milliseconds.   |
 | `connectTimeoutMillis`          |          | integer | `10000`            | The maximum time that is waited when establishing the connection. Value of zero means thatsystem/OS default is respected. In milliseconds. |
 | `enableDiscovery`                |          | boolean | false               | Enable auto-discovery feature. Effective only if a supporting extension has been installed. |
 
index a86c23da813b85a595ccc1c1201bfd9314277ed3..062713828bb10c584245994bf982d9dcc31f7583 100644 (file)
@@ -36,6 +36,7 @@ public class ModbusSerialConfiguration {
     private String flowControlOut = "none";
     private int timeBetweenTransactionsMillis = 35;
     private int connectMaxTries = 1;
+    private int afterConnectionDelayMillis;
     private int connectTimeoutMillis = 10_000;
     private boolean enableDiscovery;
 
@@ -143,6 +144,14 @@ public class ModbusSerialConfiguration {
         this.connectMaxTries = connectMaxTries;
     }
 
+    public int getAfterConnectionDelayMillis() {
+        return afterConnectionDelayMillis;
+    }
+
+    public void setAfterConnectionDelayMillis(int afterConnectionDelayMillis) {
+        this.afterConnectionDelayMillis = afterConnectionDelayMillis;
+    }
+
     public int getConnectTimeoutMillis() {
         return connectTimeoutMillis;
     }
index 0acec24bbc66ad8cb5ed8c286a7e8f115016b69f..f1bcd0e06dd92a569df9ee6e42393c53f522dae1 100644 (file)
@@ -30,6 +30,7 @@ public class ModbusTcpConfiguration {
     private int timeBetweenReconnectMillis;
     private int connectMaxTries = 1;
     private int reconnectAfterMillis;
+    private int afterConnectionDelayMillis;
     private int connectTimeoutMillis = 10_000;
     private boolean enableDiscovery;
     private boolean rtuEncoded;
@@ -94,6 +95,14 @@ public class ModbusTcpConfiguration {
         this.reconnectAfterMillis = reconnectAfterMillis;
     }
 
+    public int getAfterConnectionDelayMillis() {
+        return afterConnectionDelayMillis;
+    }
+
+    public void setAfterConnectionDelayMillis(int afterConnectionDelayMillis) {
+        this.afterConnectionDelayMillis = afterConnectionDelayMillis;
+    }
+
     public int getConnectTimeoutMillis() {
         return connectTimeoutMillis;
     }
index 82040e26009d0484631a166fc923eb35fd10e042..71eef640d6d8c04805aee5e2b237e9e26465f8fd 100644 (file)
@@ -62,6 +62,7 @@ public class ModbusSerialThingHandler
         EndpointPoolConfiguration poolConfiguration = new EndpointPoolConfiguration();
         this.poolConfiguration = poolConfiguration;
         poolConfiguration.setConnectMaxTries(config.getConnectMaxTries());
+        poolConfiguration.setAfterConnectionDelayMillis(config.getAfterConnectionDelayMillis());
         poolConfiguration.setConnectTimeoutMillis(config.getConnectTimeoutMillis());
         poolConfiguration.setInterTransactionDelayMillis(config.getTimeBetweenTransactionsMillis());
 
index e8620ca4c2611c8e003c29f8fc36622d11ffcc6b..f1ace5ca6d8fe37759d6f2764d131c61c676e1da 100644 (file)
@@ -56,6 +56,7 @@ public class ModbusTcpThingHandler
         EndpointPoolConfiguration poolConfiguration = new EndpointPoolConfiguration();
         this.poolConfiguration = poolConfiguration;
         poolConfiguration.setConnectMaxTries(config.getConnectMaxTries());
+        poolConfiguration.setAfterConnectionDelayMillis(config.getAfterConnectionDelayMillis());
         poolConfiguration.setConnectTimeoutMillis(config.getConnectTimeoutMillis());
         poolConfiguration.setInterConnectDelayMillis(config.getTimeBetweenReconnectMillis());
         poolConfiguration.setInterTransactionDelayMillis(config.getTimeBetweenTransactionsMillis());
index 47a24dbe01294f39043722ef8d373187dbb5f382..038370585910ead063e625e819dd7ad2e32ee877 100644 (file)
@@ -77,6 +77,8 @@ thing-type.config.modbus.poller.type.option.coil = coil, or digital out (DO)
 thing-type.config.modbus.poller.type.option.discrete = discrete input, or digital in (DI)
 thing-type.config.modbus.poller.type.option.holding = holding register
 thing-type.config.modbus.poller.type.option.input = input register
+thing-type.config.modbus.serial.afterConnectionDelayMillis.label = Connection warm-up time
+thing-type.config.modbus.serial.afterConnectionDelayMillis.description = Connection warm-up time. Additional time which is spent on preparing connection which should be spent waiting while end device is getting ready to answer first modbus call. In milliseconds.
 thing-type.config.modbus.serial.baud.label = Baud
 thing-type.config.modbus.serial.baud.description = Baud of the connection
 thing-type.config.modbus.serial.baud.option.75 = 75
@@ -137,6 +139,8 @@ thing-type.config.modbus.serial.stopBits.option.1.5 = 1.5
 thing-type.config.modbus.serial.stopBits.option.2.0 = 2
 thing-type.config.modbus.serial.timeBetweenTransactionsMillis.label = Time Between Transactions
 thing-type.config.modbus.serial.timeBetweenTransactionsMillis.description = How long to delay we must have at minimum between two consecutive MODBUS transactions. In milliseconds.
+thing-type.config.modbus.tcp.afterConnectionDelayMillis.label = Connection warm-up time
+thing-type.config.modbus.tcp.afterConnectionDelayMillis.description = Connection warm-up time. Additional time which is spent on preparing connection which should be spent waiting while end device is getting ready to answer first modbus call. In milliseconds.
 thing-type.config.modbus.tcp.connectMaxTries.label = Maximum Connection Tries
 thing-type.config.modbus.tcp.connectMaxTries.description = How many times we try to establish the connection. Should be at least 1.
 thing-type.config.modbus.tcp.connectTimeoutMillis.label = Timeout for Establishing the Connection
index 021009985c30dea49ffba4e4d417b8d86e000410..1348ff4388a21f6cf0b84a3647261ac7054ada8f 100644 (file)
                                <default>1</default>
                                <advanced>true</advanced>
                        </parameter>
+                       <parameter name="afterConnectionDelayMillis" type="integer" min="0" unit="ms">
+                               <label>Connection warm-up time</label>
+                               <description>Connection warm-up time. Additional time which is spent on preparing connection which should be spent
+                                       waiting while end device is getting ready to answer first modbus call. In milliseconds.</description>
+                               <default>0</default>
+                               <advanced>true</advanced>
+                       </parameter>
                        <parameter name="connectTimeoutMillis" type="integer" min="0" unit="ms">
                                <label>Timeout for Establishing the Connection</label>
                                <description>The maximum time that is waited when establishing the connection. Value of zero means that system/OS
index 3d40067485e1ae23829b47973ad91c95c9dbe5f2..519b6a5a6f3c03e622738b86f58a62c22ceec6ed 100644 (file)
                                <default>1</default>
                                <advanced>true</advanced>
                        </parameter>
+                       <parameter name="afterConnectionDelayMillis" type="integer" min="0" unit="ms">
+                               <label>Connection warm-up time</label>
+                               <description>Connection warm-up time. Additional time which is spent on preparing connection which should be spent
+                                       waiting while end device is getting ready to answer first modbus call. In milliseconds.</description>
+                               <default>0</default>
+                               <advanced>true</advanced>
+                       </parameter>
                        <parameter name="reconnectAfterMillis" type="integer" min="0" unit="ms">
                                <label>Reconnect Again After</label>
                                <description>The connection is kept open at least the time specified here. Value of zero means that connection is