From 7323b2e4eb0dc8feb086c8d0735c3363ff4fb73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dywicki?= Date: Sat, 7 May 2022 12:02:04 +0200 Subject: [PATCH] [modbus] Add support for after connection delays required by some devices. (#12642) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12641. Signed-off-by: Ɓukasz Dywicki --- bundles/org.openhab.binding.modbus/README.md | 2 ++ .../internal/config/ModbusSerialConfiguration.java | 9 +++++++++ .../modbus/internal/config/ModbusTcpConfiguration.java | 9 +++++++++ .../internal/handler/ModbusSerialThingHandler.java | 1 + .../modbus/internal/handler/ModbusTcpThingHandler.java | 1 + .../src/main/resources/OH-INF/i18n/modbus.properties | 4 ++++ .../src/main/resources/OH-INF/thing/bridge-serial.xml | 7 +++++++ .../src/main/resources/OH-INF/thing/bridge-tcp.xml | 7 +++++++ 8 files changed, 40 insertions(+) diff --git a/bundles/org.openhab.binding.modbus/README.md b/bundles/org.openhab.binding.modbus/README.md index b676b87a1dbf3..cd967d5f51c8e 100644 --- a/bundles/org.openhab.binding.modbus/README.md +++ b/bundles/org.openhab.binding.modbus/README.md @@ -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. | diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusSerialConfiguration.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusSerialConfiguration.java index a86c23da813b8..062713828bb10 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusSerialConfiguration.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusSerialConfiguration.java @@ -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 void setConnectMaxTries(int connectMaxTries) { this.connectMaxTries = connectMaxTries; } + public int getAfterConnectionDelayMillis() { + return afterConnectionDelayMillis; + } + + public void setAfterConnectionDelayMillis(int afterConnectionDelayMillis) { + this.afterConnectionDelayMillis = afterConnectionDelayMillis; + } + public int getConnectTimeoutMillis() { return connectTimeoutMillis; } diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusTcpConfiguration.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusTcpConfiguration.java index 0acec24bbc66a..f1bcd0e06dd92 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusTcpConfiguration.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/config/ModbusTcpConfiguration.java @@ -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 void setReconnectAfterMillis(int reconnectAfterMillis) { this.reconnectAfterMillis = reconnectAfterMillis; } + public int getAfterConnectionDelayMillis() { + return afterConnectionDelayMillis; + } + + public void setAfterConnectionDelayMillis(int afterConnectionDelayMillis) { + this.afterConnectionDelayMillis = afterConnectionDelayMillis; + } + public int getConnectTimeoutMillis() { return connectTimeoutMillis; } diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusSerialThingHandler.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusSerialThingHandler.java index 82040e26009d0..71eef640d6d8c 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusSerialThingHandler.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusSerialThingHandler.java @@ -62,6 +62,7 @@ protected void configure() throws ModbusConfigurationException { EndpointPoolConfiguration poolConfiguration = new EndpointPoolConfiguration(); this.poolConfiguration = poolConfiguration; poolConfiguration.setConnectMaxTries(config.getConnectMaxTries()); + poolConfiguration.setAfterConnectionDelayMillis(config.getAfterConnectionDelayMillis()); poolConfiguration.setConnectTimeoutMillis(config.getConnectTimeoutMillis()); poolConfiguration.setInterTransactionDelayMillis(config.getTimeBetweenTransactionsMillis()); diff --git a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusTcpThingHandler.java b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusTcpThingHandler.java index e8620ca4c2611..f1ace5ca6d8fe 100644 --- a/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusTcpThingHandler.java +++ b/bundles/org.openhab.binding.modbus/src/main/java/org/openhab/binding/modbus/internal/handler/ModbusTcpThingHandler.java @@ -56,6 +56,7 @@ protected void configure() throws ModbusConfigurationException { 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()); diff --git a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/i18n/modbus.properties b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/i18n/modbus.properties index 47a24dbe01294..038370585910e 100644 --- a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/i18n/modbus.properties +++ b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/i18n/modbus.properties @@ -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 diff --git a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-serial.xml b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-serial.xml index 021009985c30d..1348ff4388a21 100644 --- a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-serial.xml +++ b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-serial.xml @@ -136,6 +136,13 @@ 1 true + + + 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. + 0 + true + The maximum time that is waited when establishing the connection. Value of zero means that system/OS diff --git a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-tcp.xml b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-tcp.xml index 3d40067485e1a..519b6a5a6f3c0 100644 --- a/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-tcp.xml +++ b/bundles/org.openhab.binding.modbus/src/main/resources/OH-INF/thing/bridge-tcp.xml @@ -58,6 +58,13 @@ 1 true + + + 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. + 0 + true + The connection is kept open at least the time specified here. Value of zero means that connection is