@@ -34,7 +34,7 @@ import (
34
34
type Em2Go struct {
35
35
log * util.Logger
36
36
conn * modbus.Connection
37
- current int64
37
+ current uint16
38
38
workaround bool
39
39
phases int
40
40
}
@@ -99,7 +99,7 @@ func NewEm2Go(uri string, slaveID uint8) (api.Charger, error) {
99
99
wb := & Em2Go {
100
100
log : log ,
101
101
conn : conn ,
102
- current : 6 ,
102
+ current : 60 ,
103
103
workaround : false ,
104
104
}
105
105
@@ -177,30 +177,41 @@ func (wb *Em2Go) Enable(enable bool) error {
177
177
}
178
178
179
179
// re-set 1p if required
180
- if wb .workaround && wb .phases == 1 && enable {
181
- binary .BigEndian .PutUint16 (b , uint16 (wb .phases ))
182
- if _ , err := wb .conn .WriteMultipleRegisters (em2GoRegPhases , 1 , b ); err != nil {
183
- return err
180
+ if wb .workaround && enable {
181
+ if wb .phases == 1 {
182
+ binary .BigEndian .PutUint16 (b , uint16 (wb .phases ))
183
+ if _ , err := wb .conn .WriteMultipleRegisters (em2GoRegPhases , 1 , b ); err != nil {
184
+ return err
185
+ }
184
186
}
185
187
186
188
// send default current
187
- return wb .MaxCurrent (wb .current )
189
+ return wb .setCurrent (wb .current )
188
190
}
189
191
190
192
return nil
191
193
}
192
194
195
+ func (wb * Em2Go ) setCurrent (current uint16 ) error {
196
+ b := make ([]byte , 2 )
197
+ binary .BigEndian .PutUint16 (b , current )
198
+
199
+ _ , err := wb .conn .WriteMultipleRegisters (em2GoRegCurrentLimit , 1 , b )
200
+ return err
201
+ }
202
+
193
203
// MaxCurrent implements the api.Charger interface
194
204
func (wb * Em2Go ) MaxCurrent (current int64 ) error {
195
205
return wb .maxCurrentMillis (float64 (current ))
196
206
}
197
207
198
208
// maxCurrentMillis implements the api.ChargerEx interface
199
209
func (wb * Em2Go ) maxCurrentMillis (current float64 ) error {
200
- b := make ([]byte , 2 )
201
- binary .BigEndian .PutUint16 (b , uint16 (10 * current ))
202
-
203
- _ , err := wb .conn .WriteMultipleRegisters (em2GoRegCurrentLimit , 1 , b )
210
+ curr := uint16 (current * 10 )
211
+ err := wb .setCurrent (curr )
212
+ if err == nil {
213
+ wb .current = curr
214
+ }
204
215
return err
205
216
}
206
217
0 commit comments