Modbus: add delay setting (#2228)

This commit is contained in:
andig 2022-01-07 19:58:41 +01:00 • committed by GitHub
parent 7c88e5099c
commit d8a652ffe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

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

View file

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