From d8a652ffe25423bd8a1dc759e549d9177c93da8f Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 7 Jan 2022 19:58:41 +0100 Subject: [PATCH] Modbus: add delay setting (#2228) --- meter/modbus.go | 6 ++++++ provider/modbus.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/meter/modbus.go b/meter/modbus.go index 5f81b5547..abb2b6904 100644 --- a/meter/modbus.go +++ b/meter/modbus.go @@ -35,6 +35,7 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) { modbus.Settings `mapstructure:",squash"` Power, Energy, SoC string Currents []string + Delay time.Duration Timeout time.Duration }{ Power: "Power", @@ -63,6 +64,11 @@ func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) { return nil, err } + // set non-default delay + if cc.Delay > 0 { + conn.Delay(cc.Delay) + } + // set non-default timeout if cc.Timeout > 0 { conn.Timeout(cc.Timeout) diff --git a/provider/modbus.go b/provider/modbus.go index a6fffeb6b..56f08fdee 100644 --- a/provider/modbus.go +++ b/provider/modbus.go @@ -37,6 +37,7 @@ func NewModbusFromConfig(other map[string]interface{}) (IntProvider, error) { Register modbus.Register Value string Scale float64 + Delay time.Duration Timeout time.Duration }{ Scale: 1, @@ -62,6 +63,11 @@ func NewModbusFromConfig(other map[string]interface{}) (IntProvider, error) { return nil, err } + // set non-default delay + if cc.Delay > 0 { + conn.Delay(cc.Delay) + } + // set non-default timeout if cc.Timeout > 0 { conn.Timeout(cc.Timeout)