Modbus: unify delay and timeout settings (BC) (#31996)
This commit is contained in:
parent
ff2905a366
commit
02a66252ca
82 changed files with 410 additions and 369 deletions
|
|
@ -37,12 +37,12 @@ func NewCfosPowerBrainFromConfig(ctx context.Context, other map[string]any) (api
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return NewCfosPowerBrain(ctx, cc.URI, cc.ID)
|
||||
return NewCfosPowerBrain(ctx, cc)
|
||||
}
|
||||
|
||||
// NewCfosPowerBrain creates a cFos meter
|
||||
func NewCfosPowerBrain(ctx context.Context, uri string, id uint8) (*CfosPowerBrain, error) {
|
||||
conn, err := modbus.NewConnection(ctx, uri, "", "", 0, modbus.Tcp, id)
|
||||
func NewCfosPowerBrain(ctx context.Context, settings modbus.TcpSettings) (*CfosPowerBrain, error) {
|
||||
conn, err := settings.Connection(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ func NewHoymilesDTUModbusTcpFromConfig(ctx context.Context, other map[string]any
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return newHoymilesDTUModbusTCP(ctx, cc.URI, cc.ID, cc.pvMaxACPower.Decorator(), cc.Cache)
|
||||
return newHoymilesDTUModbusTCP(ctx, cc.TcpSettings, cc.pvMaxACPower.Decorator(), cc.Cache)
|
||||
}
|
||||
|
||||
func newHoymilesDTUModbusTCP(ctx context.Context, uri string, id uint8, maxACPower func() float64, cache time.Duration) (api.Meter, error) {
|
||||
conn, err := modbus.NewConnection(ctx, uri, "", "", 0, modbus.Tcp, id)
|
||||
func newHoymilesDTUModbusTCP(ctx context.Context, settings modbus.TcpSettings, maxACPower func() float64, cache time.Duration) (api.Meter, error) {
|
||||
conn, err := settings.Connection(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/api/implement"
|
||||
|
|
@ -39,8 +38,6 @@ func NewMbmdFromConfig(ctx context.Context, other map[string]any) (api.Meter, er
|
|||
Currents []string
|
||||
Voltages []string
|
||||
Powers []string
|
||||
Delay time.Duration
|
||||
Timeout time.Duration
|
||||
}{
|
||||
Power: "Power",
|
||||
Settings: modbus.Settings{
|
||||
|
|
@ -62,17 +59,11 @@ func NewMbmdFromConfig(ctx context.Context, other map[string]any) (api.Meter, er
|
|||
modbus.Lock()
|
||||
defer modbus.Unlock()
|
||||
|
||||
conn, err := modbus.NewConnection(ctx, cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.Settings.Protocol(), cc.ID)
|
||||
conn, err := cc.Settings.Connection(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set non-default timeout
|
||||
conn.Timeout(cc.Timeout)
|
||||
|
||||
// set non-default delay
|
||||
conn.Delay(cc.Delay)
|
||||
|
||||
log := util.NewLogger("modbus")
|
||||
conn.Logger(log.TRACE)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue