Skip to content

Commit

Permalink
ABL: add timeout (evcc-io#9241)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Aug 4, 2023
1 parent 2d1f18c commit de3f93c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
17 changes: 13 additions & 4 deletions charger/abl.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,35 @@ func init() {

// NewABLeMHFromConfig creates a ABLeMH charger from generic config
func NewABLeMHFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := modbus.Settings{
ID: 1,
cc := struct {
modbus.Settings `mapstructure:",squash"`
Timeout time.Duration
}{
Settings: modbus.Settings{
ID: 1,
},
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

return NewABLeMH(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.ID)
return NewABLeMH(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.ID, cc.Timeout)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateABLeMH -b *ABLeMH -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)"

// NewABLeMH creates ABLeMH charger
func NewABLeMH(uri, device, comset string, baudrate int, slaveID uint8) (api.Charger, error) {
func NewABLeMH(uri, device, comset string, baudrate int, slaveID uint8, timeout time.Duration) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, device, comset, baudrate, modbus.Ascii, slaveID)
if err != nil {
return nil, err
}

if timeout > 0 {
conn.Timeout(timeout)
}

if !sponsor.IsAuthorized() {
return nil, api.ErrSponsorRequired
}
Expand Down
2 changes: 2 additions & 0 deletions templates/definition/charger/abl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ params:
choice: ["rs485"]
baudrate: 38400
comset: 8E1
- name: timeout
render: |
type: abl
{{- include "modbus" . }}
timeout: {{ .timeout }}
17 changes: 17 additions & 0 deletions templates/docs/charger/abl_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ render:
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port
advanced: |
type: template
template: abl
# RS485 via adapter (Modbus RTU)
modbus: rs485serial
id: 1
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
baudrate: 38400 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
comset: "8E1" # Kommunikationsparameter für den Adapter
# RS485 via TCP/IP (Modbus RTU)
modbus: rs485tcpip
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port
timeout: 10s # Optional
17 changes: 17 additions & 0 deletions templates/docs/charger/abl_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ render:
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port
advanced: |
type: template
template: abl
# RS485 via adapter (Modbus RTU)
modbus: rs485serial
id: 1
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
baudrate: 38400 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
comset: "8E1" # Kommunikationsparameter für den Adapter
# RS485 via TCP/IP (Modbus RTU)
modbus: rs485tcpip
id: 1
host: 192.0.2.2 # Hostname
port: 502 # Port
timeout: 10s # Optional

0 comments on commit de3f93c

Please sign in to comment.