diff --git a/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs b/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs index cae0fbb1c..54eece404 100644 --- a/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs +++ b/csharp/Lib/Devices/Trumpf/TruConvertAc/AcDcDevicesRecord.cs @@ -1,15 +1,12 @@ using InnovEnergy.Lib.Devices.Trumpf.SystemControl; using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; -using InnovEnergy.Lib.StatusApi.DeviceTypes; using InnovEnergy.Lib.Units.Composite; namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc; -public class AcDcDevicesRecord : IAcDc3 +public class AcDcDevicesRecord { - - // private static readonly AcPhase NoAcPhase = Ac3Bus.FromPhasesAndFrequency() - // private static readonly Ac3Bus NoAcDevice = Ac3Bus.FromPhasesAndFrequency() + public static AcDcDevicesRecord Null { get; } = new AcDcDevicesRecord(null, Array.Empty()); public AcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList devices) { @@ -60,11 +57,26 @@ public class AcDcDevicesRecord : IAcDc3 } } - public DcBus Dc => Devices.Count == 0 - ? DcBus.Null - : DcBus.FromVoltageCurrent - ( - voltage: Devices.Average(d => d.Status.Dc.Voltage), - current: Devices.Sum(d => d.Status.Dc.Current) - ); + public DcBus Dc + { + get + { + if (Devices.Count == 0) + return DcBus.Null; + + var u = Devices + .Select(d => d.Status.DcVoltages.Extern) + .Select(vs => vs.LowerHalf + vs.UpperHalf) + .Average(); + + var p = Ac.Power.Active.Value; + var i = u == 0 ? 0 : p / u; + + return DcBus.FromVoltageCurrent + ( + voltage: u, + current: i + ); + } + } } \ No newline at end of file