Skip to content

Commit

Permalink
[modbus] Add support for after connection delays required by some dev…
Browse files Browse the repository at this point in the history
…ices. (#12642)

Fixes #12641.

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
  • Loading branch information
splatch authored May 7, 2022
1 parent 8d92e9d commit 7323b2e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.binding.modbus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@
<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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
<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
Expand Down

0 comments on commit 7323b2e

Please sign in to comment.