diff --git a/csharp/App/SaliMax/src/Ess/StatusRecord.cs b/csharp/App/SaliMax/src/Ess/StatusRecord.cs index 96e671a12..7a2b2a447 100644 --- a/csharp/App/SaliMax/src/Ess/StatusRecord.cs +++ b/csharp/App/SaliMax/src/Ess/StatusRecord.cs @@ -17,10 +17,11 @@ public record StatusRecord public Battery48TlRecords Battery { get; init; } = null!; public EmuMeterRegisters? GridMeter { get; init; } public EmuMeterRegisters? LoadOnAcIsland { get; init; } - public AcDevicePower? LoadOnAcGrid { get; init; } = null!; - public AcDevicePower? PvOnAcGrid { get; init; } = null!; - public AcDevicePower? PvOnAcIsland { get; init; } = null!; - public DcDevicePower? LoadOnDc { get; init; } = null!; + public AcPowerDevice? LoadOnAcGrid { get; init; } = null!; + public AcPowerDevice? PvOnAcGrid { get; init; } = null!; + public AcPowerDevice? PvOnAcIsland { get; init; } = null!; + public AcPowerDevice? AcGridToAcIsland { get; init; } = null!; + public DcPowerDevice? LoadOnDc { get; init; } = null!; public RelaysRecord? Relays { get; init; } public AmptStatus PvOnDc { get; init; } = null!; public Config Config { get; init; } = null!; diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 821ec9f11..d94cc3576 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -43,7 +43,6 @@ internal static class Program // private const String InternalMeter = "10.0.4.2"; // "192.168.1.241"; // private const String AmptIp = "10.0.5.1"; // "192.168.1.249"; - private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001); private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002); private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003); @@ -106,32 +105,36 @@ internal static class Program var loadOnAcIsland = acIslandLoadMeter.Read(); var gridMeter = gridMeterDevice.Read(); var pvOnDc = amptDevice.Read(); - - var pvOnAcGrid = AcDevicePower.Null; - var pvOnAcIsland = AcDevicePower.Null; - var loadOnAcGrid = pvOnAcGrid.Power + - pvOnAcIsland.Power + - (gridMeter is null ? AcPower.Null : gridMeter.Ac.Power) + - (loadOnAcIsland is null ? AcPower.Null : loadOnAcIsland.Ac.Power); + var pvOnAcGrid = AcPowerDevice.Null; + var pvOnAcIsland = AcPowerDevice.Null; + var gridPower = gridMeter is null ? AcPower.Null : gridMeter.Ac.Power; + var islandLoadPower = loadOnAcIsland is null ? AcPower.Null : loadOnAcIsland.Ac.Power; + var inverterAcPower = acDc.Ac.Power; + + var loadOnAcGrid = gridPower + + pvOnAcGrid.Power + + pvOnAcIsland.Power + - islandLoadPower + - inverterAcPower; + var gridBusToIslandBusPower = gridPower + + pvOnAcGrid.Power + - loadOnAcGrid; - var dcPowers = new[] - { - acDc?.Dc.Power.Value, - pvOnDc?.Dc?.Power.Value, - dcDc?.Dc.Link.Power.Value - }; + // var dcPower = acDc.Dc.Power.Value + // + pvOnDc.Dc?.Power.Value ?? 0 + // - dcDc.Dc.Link.Power.Value; - var loadOnDc = dcPowers.Any(p => p is null) - ? null - : new DcDevicePower { Power = dcPowers.Sum(p => p)!} ; + var dcPower = 0; + + var loadOnDc = new DcPowerDevice { Power = dcPower} ; return new StatusRecord { - AcDc = acDc ?? AcDcDevicesRecord.Null, - DcDc = dcDc ?? DcDcDevicesRecord.Null, + AcDc = acDc ?? AcDcDevicesRecord.Null, + DcDc = dcDc ?? DcDcDevicesRecord.Null, Battery = battery ?? Battery48TlRecords.Null, Relays = relays, GridMeter = gridMeter, @@ -140,9 +143,10 @@ internal static class Program PvOnAcIsland = pvOnAcIsland, PvOnDc = pvOnDc ?? AmptStatus.Null, - LoadOnAcGrid = new AcDevicePower { Power = -loadOnAcGrid }, - LoadOnAcIsland = loadOnAcIsland, - LoadOnDc = loadOnDc, + AcGridToAcIsland = new AcPowerDevice { Power = gridBusToIslandBusPower }, + LoadOnAcGrid = new AcPowerDevice { Power = loadOnAcGrid }, + LoadOnAcIsland = loadOnAcIsland, + LoadOnDc = loadOnDc, Config = Config.Load() // load from disk every iteration, so config can be changed while running }; @@ -176,6 +180,14 @@ internal static class Program record.Relays.ToCsv().WriteLine(); + var emuMeterRegisters = record.GridMeter; + if (emuMeterRegisters is not null) + { + emuMeterRegisters.Ac.Power.Active.WriteLine("Grid Active"); + //emuMeterRegisters.Ac.Power.Reactive.WriteLine("Grid Reactive"); + } + + record.ControlConstants(); record.ControlSystemState(); @@ -186,8 +198,8 @@ internal static class Program record.EssControl = essControl; - record.AcDc.SystemControl.ApplyDefaultSettingsAc(); - record.DcDc.SystemControl.ApplyDefaultSettingsDc(); + record.AcDc.SystemControl.ApplyAcDcDefaultSettings(); + record.DcDc.SystemControl.ApplyDcDcDefaultSettings(); DistributePower(record, essControl); @@ -322,7 +334,7 @@ internal static class Program }); } - private static void ApplyDefaultSettingsAc(this SystemControlRegisters? sc) + private static void ApplyAcDcDefaultSettings(this SystemControlRegisters? sc) { if (sc is null) return; @@ -343,18 +355,17 @@ internal static class Program sc.ResetAlarmsAndWarnings = true; } - private static void ApplyDefaultSettingsDc(this SystemControlRegisters? sc) + private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc) { if (sc is null) return; sc.SystemConfig = DcDcOnly; - -#if DEBUG + #if DEBUG sc.CommunicationTimeout = TimeSpan.FromMinutes(2); -#else + #else sc.CommunicationTimeout = TimeSpan.FromSeconds(20); -#endif + #endif sc.PowerSetPointActivation = PowerSetPointActivation.Immediate; sc.UseSlaveIdForAddressing = true; @@ -367,7 +378,7 @@ internal static class Program { timeStamp.WriteLine(); - var csv = status.ToCsv();//.WriteLine(); + var csv = status.ToCsv(); var s3Path = timeStamp + ".csv"; var request = S3Config.CreatePutRequest(s3Path); var response = await request.PutAsync(new StringContent(csv)); diff --git a/csharp/App/SaliMax/src/VirtualDevices/AcDevicePower.cs b/csharp/App/SaliMax/src/VirtualDevices/AcPowerDevice.cs similarity index 60% rename from csharp/App/SaliMax/src/VirtualDevices/AcDevicePower.cs rename to csharp/App/SaliMax/src/VirtualDevices/AcPowerDevice.cs index 8f157d789..0775a1018 100644 --- a/csharp/App/SaliMax/src/VirtualDevices/AcDevicePower.cs +++ b/csharp/App/SaliMax/src/VirtualDevices/AcPowerDevice.cs @@ -2,9 +2,9 @@ using InnovEnergy.Lib.Units.Composite; namespace InnovEnergy.App.SaliMax.VirtualDevices; -public class AcDevicePower +public class AcPowerDevice { public AcPower Power { get; init; } = AcPower.Null; - public static AcDevicePower Null { get; } = new AcDevicePower(); + public static AcPowerDevice Null => new AcPowerDevice(); } \ No newline at end of file diff --git a/csharp/App/SaliMax/src/VirtualDevices/DcDevicePower.cs b/csharp/App/SaliMax/src/VirtualDevices/DcPowerDevice.cs similarity index 83% rename from csharp/App/SaliMax/src/VirtualDevices/DcDevicePower.cs rename to csharp/App/SaliMax/src/VirtualDevices/DcPowerDevice.cs index bac183674..d8f612124 100644 --- a/csharp/App/SaliMax/src/VirtualDevices/DcDevicePower.cs +++ b/csharp/App/SaliMax/src/VirtualDevices/DcPowerDevice.cs @@ -2,7 +2,7 @@ using InnovEnergy.Lib.Units.Power; namespace InnovEnergy.App.SaliMax.VirtualDevices; -public class DcDevicePower +public class DcPowerDevice { public DcPower Power { get; init; } = DcPower.Null; } \ No newline at end of file