do not use common Null device (new for every use), it's ugly but it broke .ToCsv's cycle detector

This commit is contained in:
ig 2023-06-22 10:13:21 +02:00
parent 5976ce3a8c
commit 0582b26ec7
11 changed files with 22 additions and 16 deletions

View File

@ -13,7 +13,7 @@ public class AmptStatus
public DcBus? Dc { get; } public DcBus? Dc { get; }
public IReadOnlyList<DcBus> Strings { get; } public IReadOnlyList<DcBus> Strings { get; }
public static AmptStatus Null { get; } = new AmptStatus(null, Array.Empty<DcBus>()); public static AmptStatus Null => new AmptStatus(null, Array.Empty<DcBus>());
} }

View File

@ -34,5 +34,5 @@ public class Battery48TlRecords
public IReadOnlyList<Battery48TlRecord> Devices { get; init; } public IReadOnlyList<Battery48TlRecord> Devices { get; init; }
public static Battery48TlRecords Null { get; } = new Battery48TlRecords(Array.Empty<Battery48TlRecord>()); public static Battery48TlRecords Null => new Battery48TlRecords(Array.Empty<Battery48TlRecord>());
} }

View File

@ -6,7 +6,7 @@ namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
public class AcDcDevicesRecord public class AcDcDevicesRecord
{ {
public static AcDcDevicesRecord Null { get; } = new AcDcDevicesRecord(null, Array.Empty<AcDcRecord>()); public static AcDcDevicesRecord Null => new AcDcDevicesRecord(null, Array.Empty<AcDcRecord>());
public AcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<AcDcRecord> devices) public AcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<AcDcRecord> devices)
{ {

View File

@ -75,13 +75,13 @@ public partial class AcDcRecord
[InputRegister<Int16>(5141)] internal readonly Double ActivePowerL2; [InputRegister<Int16>(5141)] internal readonly Double ActivePowerL2;
[InputRegister<Int16>(5142)] internal readonly Double ActivePowerL3; [InputRegister<Int16>(5142)] internal readonly Double ActivePowerL3;
[InputRegister(5231)] internal readonly Double ReactivePowerL1; [InputRegister<Int16>(5231)] internal readonly Double ReactivePowerL1;
[InputRegister(5232)] internal readonly Double ReactivePowerL2; [InputRegister<Int16>(5232)] internal readonly Double ReactivePowerL2;
[InputRegister(5233)] internal readonly Double ReactivePowerL3; [InputRegister<Int16>(5233)] internal readonly Double ReactivePowerL3;
[InputRegister(5150, Scale = .01)] internal readonly Double GridCurrentL1; [InputRegister<Int16>(5150, Scale = .01)] internal readonly Double GridCurrentL1;
[InputRegister(5151, Scale = .01)] internal readonly Double GridCurrentL2; [InputRegister<Int16>(5151, Scale = .01)] internal readonly Double GridCurrentL2;
[InputRegister(5152, Scale = .01)] internal readonly Double GridCurrentL3; [InputRegister<Int16>(5152, Scale = .01)] internal readonly Double GridCurrentL3;
[InputRegister(5160, Scale = .1)] internal readonly Double GridVoltageL1; [InputRegister(5160, Scale = .1)] internal readonly Double GridVoltageL1;
[InputRegister(5161, Scale = .1)] internal readonly Double GridVoltageL2; [InputRegister(5161, Scale = .1)] internal readonly Double GridVoltageL2;

View File

@ -38,5 +38,5 @@ public class DcDcDevicesRecord
public IEnumerable<AlarmMessage> Alarms => Devices.SelectMany(d => d.Status.Alarms ).Distinct(); public IEnumerable<AlarmMessage> Alarms => Devices.SelectMany(d => d.Status.Alarms ).Distinct();
public IEnumerable<WarningMessage> Warnings => Devices.SelectMany(d => d.Status.Warnings).Distinct(); public IEnumerable<WarningMessage> Warnings => Devices.SelectMany(d => d.Status.Warnings).Distinct();
public static DcDcDevicesRecord Null { get; } = new DcDcDevicesRecord(null, Array.Empty<DcDcRecord>()); public static DcDcDevicesRecord Null => new DcDcDevicesRecord(null, Array.Empty<DcDcRecord>());
} }

View File

@ -21,5 +21,5 @@ public sealed class Ac1Bus
Power = AcPower.FromVoltageCurrentPhi(voltageRms, currentRms, phi) Power = AcPower.FromVoltageCurrentPhi(voltageRms, currentRms, phi)
}; };
public static Ac1Bus Null { get; } = FromVoltageCurrentFrequencyPhi(0, 0, 0, 0); public static Ac1Bus Null => FromVoltageCurrentFrequencyPhi(0, 0, 0, 0);
} }

View File

@ -24,5 +24,5 @@ public sealed class Ac3Bus
Frequency = frequency, Frequency = frequency,
}; };
public static Ac3Bus Null { get; } = FromPhasesAndFrequency(AcPhase.Null, AcPhase.Null, AcPhase.Null, 0); public static Ac3Bus Null => FromPhasesAndFrequency(AcPhase.Null, AcPhase.Null, AcPhase.Null, 0);
} }

View File

@ -41,7 +41,7 @@ public sealed class AcPhase
Power = AcPower.FromActiveReactiveApparent(activePower, reactivePower, apparentPower) Power = AcPower.FromActiveReactiveApparent(activePower, reactivePower, apparentPower)
}; };
public static AcPhase Null { get; } = FromVoltageCurrentPhi(0, 0, 0); public static AcPhase Null => FromVoltageCurrentPhi(0, 0, 0);

View File

@ -84,7 +84,7 @@ public sealed class AcPower
}; };
} }
public static AcPower Null { get; } = FromVoltageCurrentPhi(0, 0, 0); public static AcPower Null => FromVoltageCurrentPhi(0, 0, 0);
public static AcPower operator +(AcPower left, AcPower right) => FromActiveReactive public static AcPower operator +(AcPower left, AcPower right) => FromActiveReactive
( (
@ -92,6 +92,12 @@ public sealed class AcPower
left.Reactive + right.Reactive left.Reactive + right.Reactive
); );
public static AcPower operator -(AcPower left, AcPower right) => FromActiveReactive
(
left.Active - right.Active,
left.Reactive - right.Reactive
);
public static AcPower operator -(AcPower p) => FromActiveReactive(-p.Active, p.Reactive); public static AcPower operator -(AcPower p) => FromActiveReactive(-p.Active, p.Reactive);

View File

@ -17,5 +17,5 @@ public sealed class DcBus
Power = current.Value * voltage.Value, Power = current.Value * voltage.Value,
}; };
public static DcBus Null { get; } = FromVoltageCurrent(0, 0); public static DcBus Null => FromVoltageCurrent(0, 0);
} }

View File

@ -12,5 +12,5 @@ public sealed class DcPower : AcPower
public static implicit operator Double(DcPower d) => d.Value; public static implicit operator Double(DcPower d) => d.Value;
public static DcPower Null { get; } = new DcPower(0); public static DcPower Null => new DcPower(0);
} }