Skip to content

Commit

Permalink
Modbus: add delay setting (#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jan 7, 2022
1 parent 7c88e50 commit d8a652f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions meter/modbus.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions provider/modbus.go
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit d8a652f

Please sign in to comment.