Em2Go: work around current being reset (#17050)

This commit is contained in:
andig 2024-11-03 11:47:36 +01:00 • committed by GitHub
parent c148080673
commit ec91e5261e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,7 +34,7 @@ import (
type Em2Go struct {
log *util.Logger
conn *modbus.Connection
current int64
current uint16
workaround bool
phases int
}
@ -99,7 +99,7 @@ func NewEm2Go(uri string, slaveID uint8) (api.Charger, error) {
wb := &Em2Go{
log: log,
conn: conn,
current: 6,
current: 60,
workaround: false,
}
@ -177,19 +177,29 @@ func (wb *Em2Go) Enable(enable bool) error {
}
// re-set 1p if required
if wb.workaround && wb.phases == 1 && enable {
binary.BigEndian.PutUint16(b, uint16(wb.phases))
if _, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b); err != nil {
return err
if wb.workaround && enable {
if wb.phases == 1 {
binary.BigEndian.PutUint16(b, uint16(wb.phases))
if _, err := wb.conn.WriteMultipleRegisters(em2GoRegPhases, 1, b); err != nil {
return err
}
}
// send default current
return wb.MaxCurrent(wb.current)
return wb.setCurrent(wb.current)
}
return nil
}
func (wb *Em2Go) setCurrent(current uint16) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, current)
_, err := wb.conn.WriteMultipleRegisters(em2GoRegCurrentLimit, 1, b)
return err
}
// MaxCurrent implements the api.Charger interface
func (wb *Em2Go) MaxCurrent(current int64) error {
return wb.maxCurrentMillis(float64(current))
@ -197,10 +207,11 @@ func (wb *Em2Go) MaxCurrent(current int64) error {
// maxCurrentMillis implements the api.ChargerEx interface
func (wb *Em2Go) maxCurrentMillis(current float64) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(10*current))
_, err := wb.conn.WriteMultipleRegisters(em2GoRegCurrentLimit, 1, b)
curr := uint16(current * 10)
err := wb.setCurrent(curr)
if err == nil {
wb.current = curr
}
return err
}