Modbus: use context (#19301)
This commit is contained in:
parent
766a6f6b2b
commit
45623bfa15
49 changed files with 241 additions and 183 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
|
@ -24,11 +25,11 @@ type ModbusSunspec struct {
|
|||
}
|
||||
|
||||
func init() {
|
||||
registry.Add("sunspec", NewModbusSunspecFromConfig)
|
||||
registry.AddCtx("sunspec", NewModbusSunspecFromConfig)
|
||||
}
|
||||
|
||||
// NewModbusSunspecFromConfig creates Modbus plugin
|
||||
func NewModbusSunspecFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||
func NewModbusSunspecFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||
cc := struct {
|
||||
modbus.Settings `mapstructure:",squash"`
|
||||
Value []string
|
||||
|
|
@ -47,7 +48,7 @@ func NewModbusSunspecFromConfig(other map[string]interface{}) (Plugin, error) {
|
|||
modbus.Lock()
|
||||
defer modbus.Unlock()
|
||||
|
||||
conn, err := modbus.NewConnection(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.Settings.Protocol(), cc.ID)
|
||||
conn, err := modbus.NewConnection(ctx, cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.Settings.Protocol(), cc.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue