Add calculated powers (loads etc.), Dc Load is still broken

This commit is contained in:
ig 2023-06-22 10:17:06 +02:00
parent d1d9575052
commit f7ee9276a3
4 changed files with 50 additions and 38 deletions

View File

@ -17,10 +17,11 @@ public record StatusRecord
public Battery48TlRecords Battery { get; init; } = null!; public Battery48TlRecords Battery { get; init; } = null!;
public EmuMeterRegisters? GridMeter { get; init; } public EmuMeterRegisters? GridMeter { get; init; }
public EmuMeterRegisters? LoadOnAcIsland { get; init; } public EmuMeterRegisters? LoadOnAcIsland { get; init; }
public AcDevicePower? LoadOnAcGrid { get; init; } = null!; public AcPowerDevice? LoadOnAcGrid { get; init; } = null!;
public AcDevicePower? PvOnAcGrid { get; init; } = null!; public AcPowerDevice? PvOnAcGrid { get; init; } = null!;
public AcDevicePower? PvOnAcIsland { get; init; } = null!; public AcPowerDevice? PvOnAcIsland { get; init; } = null!;
public DcDevicePower? LoadOnDc { get; init; } = null!; public AcPowerDevice? AcGridToAcIsland { get; init; } = null!;
public DcPowerDevice? LoadOnDc { get; init; } = null!;
public RelaysRecord? Relays { get; init; } public RelaysRecord? Relays { get; init; }
public AmptStatus PvOnDc { get; init; } = null!; public AmptStatus PvOnDc { get; init; } = null!;
public Config Config { get; init; } = null!; public Config Config { get; init; } = null!;

View File

@ -43,7 +43,6 @@ internal static class Program
// private const String InternalMeter = "10.0.4.2"; // "192.168.1.241"; // 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 const String AmptIp = "10.0.5.1"; // "192.168.1.249";
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001); private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002); private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003); private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
@ -107,31 +106,35 @@ internal static class Program
var gridMeter = gridMeterDevice.Read(); var gridMeter = gridMeterDevice.Read();
var pvOnDc = amptDevice.Read(); var pvOnDc = amptDevice.Read();
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 pvOnAcGrid = AcDevicePower.Null; var loadOnAcGrid = gridPower
var pvOnAcIsland = AcDevicePower.Null; + pvOnAcGrid.Power
var loadOnAcGrid = pvOnAcGrid.Power + + pvOnAcIsland.Power
pvOnAcIsland.Power + - islandLoadPower
(gridMeter is null ? AcPower.Null : gridMeter.Ac.Power) + - inverterAcPower;
(loadOnAcIsland is null ? AcPower.Null : loadOnAcIsland.Ac.Power);
var gridBusToIslandBusPower = gridPower
+ pvOnAcGrid.Power
- loadOnAcGrid;
var dcPowers = new[] // var dcPower = acDc.Dc.Power.Value
{ // + pvOnDc.Dc?.Power.Value ?? 0
acDc?.Dc.Power.Value, // - dcDc.Dc.Link.Power.Value;
pvOnDc?.Dc?.Power.Value,
dcDc?.Dc.Link.Power.Value
};
var loadOnDc = dcPowers.Any(p => p is null) var dcPower = 0;
? null
: new DcDevicePower { Power = dcPowers.Sum(p => p)!} ; var loadOnDc = new DcPowerDevice { Power = dcPower} ;
return new StatusRecord return new StatusRecord
{ {
AcDc = acDc ?? AcDcDevicesRecord.Null, AcDc = acDc ?? AcDcDevicesRecord.Null,
DcDc = dcDc ?? DcDcDevicesRecord.Null, DcDc = dcDc ?? DcDcDevicesRecord.Null,
Battery = battery ?? Battery48TlRecords.Null, Battery = battery ?? Battery48TlRecords.Null,
Relays = relays, Relays = relays,
GridMeter = gridMeter, GridMeter = gridMeter,
@ -140,9 +143,10 @@ internal static class Program
PvOnAcIsland = pvOnAcIsland, PvOnAcIsland = pvOnAcIsland,
PvOnDc = pvOnDc ?? AmptStatus.Null, PvOnDc = pvOnDc ?? AmptStatus.Null,
LoadOnAcGrid = new AcDevicePower { Power = -loadOnAcGrid }, AcGridToAcIsland = new AcPowerDevice { Power = gridBusToIslandBusPower },
LoadOnAcIsland = loadOnAcIsland, LoadOnAcGrid = new AcPowerDevice { Power = loadOnAcGrid },
LoadOnDc = loadOnDc, LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc,
Config = Config.Load() // load from disk every iteration, so config can be changed while running 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(); 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.ControlConstants();
record.ControlSystemState(); record.ControlSystemState();
@ -186,8 +198,8 @@ internal static class Program
record.EssControl = essControl; record.EssControl = essControl;
record.AcDc.SystemControl.ApplyDefaultSettingsAc(); record.AcDc.SystemControl.ApplyAcDcDefaultSettings();
record.DcDc.SystemControl.ApplyDefaultSettingsDc(); record.DcDc.SystemControl.ApplyDcDcDefaultSettings();
DistributePower(record, essControl); 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) if (sc is null)
return; return;
@ -343,18 +355,17 @@ internal static class Program
sc.ResetAlarmsAndWarnings = true; sc.ResetAlarmsAndWarnings = true;
} }
private static void ApplyDefaultSettingsDc(this SystemControlRegisters? sc) private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc)
{ {
if (sc is null) if (sc is null)
return; return;
sc.SystemConfig = DcDcOnly; sc.SystemConfig = DcDcOnly;
#if DEBUG
#if DEBUG
sc.CommunicationTimeout = TimeSpan.FromMinutes(2); sc.CommunicationTimeout = TimeSpan.FromMinutes(2);
#else #else
sc.CommunicationTimeout = TimeSpan.FromSeconds(20); sc.CommunicationTimeout = TimeSpan.FromSeconds(20);
#endif #endif
sc.PowerSetPointActivation = PowerSetPointActivation.Immediate; sc.PowerSetPointActivation = PowerSetPointActivation.Immediate;
sc.UseSlaveIdForAddressing = true; sc.UseSlaveIdForAddressing = true;
@ -367,7 +378,7 @@ internal static class Program
{ {
timeStamp.WriteLine(); timeStamp.WriteLine();
var csv = status.ToCsv();//.WriteLine(); var csv = status.ToCsv();
var s3Path = timeStamp + ".csv"; var s3Path = timeStamp + ".csv";
var request = S3Config.CreatePutRequest(s3Path); var request = S3Config.CreatePutRequest(s3Path);
var response = await request.PutAsync(new StringContent(csv)); var response = await request.PutAsync(new StringContent(csv));

View File

@ -2,9 +2,9 @@ using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.App.SaliMax.VirtualDevices; namespace InnovEnergy.App.SaliMax.VirtualDevices;
public class AcDevicePower public class AcPowerDevice
{ {
public AcPower Power { get; init; } = AcPower.Null; public AcPower Power { get; init; } = AcPower.Null;
public static AcDevicePower Null { get; } = new AcDevicePower(); public static AcPowerDevice Null => new AcPowerDevice();
} }

View File

@ -2,7 +2,7 @@ using InnovEnergy.Lib.Units.Power;
namespace InnovEnergy.App.SaliMax.VirtualDevices; namespace InnovEnergy.App.SaliMax.VirtualDevices;
public class DcDevicePower public class DcPowerDevice
{ {
public DcPower Power { get; init; } = DcPower.Null; public DcPower Power { get; init; } = DcPower.Null;
} }