Kathrein: fix phase switching (#21350)
This commit is contained in:
parent
6b9ac47eee
commit
8bae78ce83
1 changed files with 24 additions and 36 deletions
|
|
@ -67,8 +67,7 @@ const (
|
|||
kathreinRegCurrents = 0x0036 // float32 Line 1 Current (A)
|
||||
kathreinRegPowers = 0x003C // float32 Line 1 Power (W)
|
||||
kathreinRegTotalActivePower = 0x0054 // float32 Total active power (W)
|
||||
kathreinRegTotalEnergy = 0x005C // float32 Total Energy (since production) (kWh)
|
||||
kathreinRegFrequencyLine = 0x005E // float32 Frequency line (Hz)
|
||||
kathreinRegTotalEnergy = 0x005C // float32 Total Energy (since production) (Wh)
|
||||
|
||||
// EVSE - Charging state (uint16)
|
||||
// 0 : Idle
|
||||
|
|
@ -253,6 +252,11 @@ func (wb *Kathrein) Enable(enable bool) error {
|
|||
u = wb.curr
|
||||
}
|
||||
|
||||
// EMS-Control must be enabled before sending first WriteReg Command
|
||||
if _, err := wb.conn.WriteSingleRegister(kathreinRegEMSControlRegister, 0x8000); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := wb.conn.WriteSingleRegister(kathreinRegEMSSetpointChargingCurrent, u)
|
||||
|
||||
return err
|
||||
|
|
@ -340,7 +344,7 @@ func (wb *Kathrein) TotalEnergy() (float64, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
return float64(math.Float32frombits(binary.BigEndian.Uint32(b))), err
|
||||
return float64(math.Float32frombits(binary.BigEndian.Uint32(b))) / 1e3, err
|
||||
}
|
||||
|
||||
var _ api.PhaseSwitcher = (*Kathrein)(nil)
|
||||
|
|
@ -358,23 +362,27 @@ func (wb *Kathrein) Phases1p3p(phases int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// EMS-Control must be enabled before sending first WriteReg Command
|
||||
if _, err := wb.conn.WriteSingleRegister(kathreinRegEMSControlRegister, 0x8000); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Switch phases
|
||||
if _, err := wb.conn.WriteSingleRegister(kathreinRegEMSSetpointRelais, u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Disable and re-enable charging to apply the new phase setting
|
||||
if enabled {
|
||||
if err = wb.Enable(false); err != nil {
|
||||
if err := wb.Enable(false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := wb.Enable(true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Switch phases
|
||||
if _, err = wb.conn.WriteSingleRegister(kathreinRegEMSSetpointRelais, u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Re-enable charging if it was previously enabled
|
||||
if enabled {
|
||||
err = wb.Enable(true)
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ api.PhaseGetter = (*Kathrein)(nil)
|
||||
|
|
@ -420,18 +428,6 @@ func (wb *Kathrein) Diagnose() {
|
|||
fmt.Printf("Device - Serial:\t%s\n", b)
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegTotalActivePower, 2); err == nil {
|
||||
fmt.Printf("Meter - P tot (active):\t%f W\n", float64(math.Float32frombits(binary.BigEndian.Uint32(b))))
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegTotalEnergy, 2); err == nil {
|
||||
fmt.Printf("Meter - W tot:\t%f kWh\n", float64(math.Float32frombits(binary.BigEndian.Uint32(b))))
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegFrequencyLine, 2); err == nil {
|
||||
fmt.Printf("Meter - W tot:\t%f Hz\n", float64(math.Float32frombits(binary.BigEndian.Uint32(b))))
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegChargingState, 1); err == nil {
|
||||
fmt.Printf("EVSE - Charging-State:\t%d\n", b[1])
|
||||
}
|
||||
|
|
@ -456,14 +452,6 @@ func (wb *Kathrein) Diagnose() {
|
|||
fmt.Printf("EVSE - Granted Power:\t%d W\n", b[1])
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegChargingDuration, 2); err == nil {
|
||||
fmt.Printf("Charging - Duration:\t%d s\n", b)
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegChargingEnergy, 2); err == nil {
|
||||
fmt.Printf("Charging - Energy:\t%d Wh\n", b)
|
||||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegEMSControlRegister, 1); err == nil {
|
||||
fmt.Printf("EMS-Control - Control-Register:\t%d\n", b[1])
|
||||
}
|
||||
|
|
@ -485,6 +473,6 @@ func (wb *Kathrein) Diagnose() {
|
|||
}
|
||||
|
||||
if b, err := wb.conn.ReadHoldingRegisters(kathreinRegEMSTimeOutFallbackCurrent, 1); err == nil {
|
||||
fmt.Printf("EMS-Control - Timeout Fallback Pattern:\t%d mA\n", b[1])
|
||||
fmt.Printf("EMS-Control - Timeout Fallback Current:\t%d mA\n", b[1])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue