Skip to content

Commit de3f93c

Browse files
authored
ABL: add timeout (evcc-io#9241)
1 parent 2d1f18c commit de3f93c

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

charger/abl.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,35 @@ func init() {
8080

8181
// NewABLeMHFromConfig creates a ABLeMH charger from generic config
8282
func NewABLeMHFromConfig(other map[string]interface{}) (api.Charger, error) {
83-
cc := modbus.Settings{
84-
ID: 1,
83+
cc := struct {
84+
modbus.Settings `mapstructure:",squash"`
85+
Timeout time.Duration
86+
}{
87+
Settings: modbus.Settings{
88+
ID: 1,
89+
},
8590
}
8691

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

91-
return NewABLeMH(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.ID)
96+
return NewABLeMH(cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.ID, cc.Timeout)
9297
}
9398

9499
//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)"
95100

96101
// NewABLeMH creates ABLeMH charger
97-
func NewABLeMH(uri, device, comset string, baudrate int, slaveID uint8) (api.Charger, error) {
102+
func NewABLeMH(uri, device, comset string, baudrate int, slaveID uint8, timeout time.Duration) (api.Charger, error) {
98103
conn, err := modbus.NewConnection(uri, device, comset, baudrate, modbus.Ascii, slaveID)
99104
if err != nil {
100105
return nil, err
101106
}
102107

108+
if timeout > 0 {
109+
conn.Timeout(timeout)
110+
}
111+
103112
if !sponsor.IsAuthorized() {
104113
return nil, api.ErrSponsorRequired
105114
}

templates/definition/charger/abl.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ params:
1414
choice: ["rs485"]
1515
baudrate: 38400
1616
comset: 8E1
17+
- name: timeout
1718
render: |
1819
type: abl
1920
{{- include "modbus" . }}
21+
timeout: {{ .timeout }}

templates/docs/charger/abl_0.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ render:
2020
id: 1
2121
host: 192.0.2.2 # Hostname
2222
port: 502 # Port
23+
advanced: |
24+
type: template
25+
template: abl
26+
27+
# RS485 via adapter (Modbus RTU)
28+
modbus: rs485serial
29+
id: 1
30+
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
31+
baudrate: 38400 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
32+
comset: "8E1" # Kommunikationsparameter für den Adapter
33+
34+
# RS485 via TCP/IP (Modbus RTU)
35+
modbus: rs485tcpip
36+
id: 1
37+
host: 192.0.2.2 # Hostname
38+
port: 502 # Port
39+
timeout: 10s # Optional

templates/docs/charger/abl_1.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ render:
2020
id: 1
2121
host: 192.0.2.2 # Hostname
2222
port: 502 # Port
23+
advanced: |
24+
type: template
25+
template: abl
26+
27+
# RS485 via adapter (Modbus RTU)
28+
modbus: rs485serial
29+
id: 1
30+
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
31+
baudrate: 38400 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
32+
comset: "8E1" # Kommunikationsparameter für den Adapter
33+
34+
# RS485 via TCP/IP (Modbus RTU)
35+
modbus: rs485tcpip
36+
id: 1
37+
host: 192.0.2.2 # Hostname
38+
port: 502 # Port
39+
timeout: 10s # Optional

0 commit comments

Comments
 (0)