Update Salimax program and Schneider Meter Driver
This commit is contained in:
parent
42bb676784
commit
51407a7846
|
@ -1,4 +1,4 @@
|
||||||
#undef Amax
|
#define Amax
|
||||||
#undef GridLimit
|
#undef GridLimit
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -28,12 +28,12 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
||||||
using InnovEnergy.Lib.Units;
|
using InnovEnergy.Lib.Units;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.App.SaliMax.DataTypes;
|
using InnovEnergy.App.SaliMax.DataTypes;
|
||||||
|
using static System.Int32;
|
||||||
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
|
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
|
||||||
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
|
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
|
||||||
using static InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig;
|
using static InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig;
|
||||||
using DeviceState = InnovEnergy.App.SaliMax.Devices.DeviceState;
|
using DeviceState = InnovEnergy.App.SaliMax.Devices.DeviceState;
|
||||||
|
|
||||||
|
|
||||||
#pragma warning disable IL2026
|
#pragma warning disable IL2026
|
||||||
|
|
||||||
namespace InnovEnergy.App.SaliMax;
|
namespace InnovEnergy.App.SaliMax;
|
||||||
|
@ -448,7 +448,7 @@ internal static class Program
|
||||||
? SalimaxAlarmState.Red
|
? SalimaxAlarmState.Red
|
||||||
: _salimaxAlarmState; // this will be replaced by LedState
|
: _salimaxAlarmState; // this will be replaced by LedState
|
||||||
|
|
||||||
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
||||||
|
|
||||||
var returnedStatus = new StatusMessage
|
var returnedStatus = new StatusMessage
|
||||||
{
|
{
|
||||||
|
@ -685,7 +685,7 @@ internal static class Program
|
||||||
|
|
||||||
var csv = status.ToCsv().LogInfo();
|
var csv = status.ToCsv().LogInfo();
|
||||||
|
|
||||||
await RestApiSavingfile(csv);
|
await RestApiSavingFile(csv);
|
||||||
|
|
||||||
var s3Config = status.Config.S3;
|
var s3Config = status.Config.S3;
|
||||||
|
|
||||||
|
@ -744,28 +744,28 @@ internal static class Program
|
||||||
private static void Heartbit(DateTime timeStamp)
|
private static void Heartbit(DateTime timeStamp)
|
||||||
{
|
{
|
||||||
var s3Bucket = Config.Load().S3?.Bucket;
|
var s3Bucket = Config.Load().S3?.Bucket;
|
||||||
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
var tryParse = TryParse(s3Bucket?.Split("-")[0], out var installationId);
|
||||||
|
var parse = TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
|
||||||
int.TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
|
|
||||||
|
|
||||||
var returnedStatus = new StatusMessage
|
|
||||||
{
|
|
||||||
InstallationId = installationId,
|
|
||||||
Product = 0,
|
|
||||||
Status = _salimaxAlarmState,
|
|
||||||
Type = MessageType.Heartbit,
|
|
||||||
Timestamp = nameOfCsvFile
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (s3Bucket != null)
|
if (tryParse)
|
||||||
RabbitMqManager.InformMiddleware(returnedStatus);
|
{
|
||||||
|
var returnedStatus = new StatusMessage
|
||||||
|
{
|
||||||
|
InstallationId = installationId,
|
||||||
|
Product = 0, // Salimax is always 0
|
||||||
|
Status = _salimaxAlarmState,
|
||||||
|
Type = MessageType.Heartbit,
|
||||||
|
Timestamp = nameOfCsvFile
|
||||||
|
};
|
||||||
|
if (s3Bucket != null)
|
||||||
|
RabbitMqManager.InformMiddleware(returnedStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Byte[] CompresseBytes(String csvToSend)
|
private static Byte[] CompresseBytes(String csvToSend)
|
||||||
{
|
{
|
||||||
//Compress CSV data to a byte array
|
//Compress CSV data to a byte array
|
||||||
byte[] compressedBytes;
|
Byte[] compressedBytes;
|
||||||
using (var memoryStream = new MemoryStream())
|
using (var memoryStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
//Create a zip directory and put the compressed file inside
|
//Create a zip directory and put the compressed file inside
|
||||||
|
@ -785,7 +785,7 @@ internal static class Program
|
||||||
return compressedBytes;
|
return compressedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task RestApiSavingfile(String csv)
|
private static async Task RestApiSavingFile(String csv)
|
||||||
{
|
{
|
||||||
// This is for the Rest API
|
// This is for the Rest API
|
||||||
// Check if the directory exists, and create it if it doesn't
|
// Check if the directory exists, and create it if it doesn't
|
||||||
|
|
|
@ -15,25 +15,26 @@ public static class Config
|
||||||
|
|
||||||
public static TimeSpan TcpTimeout { get; } = TimeSpan.FromSeconds(2);
|
public static TimeSpan TcpTimeout { get; } = TimeSpan.FromSeconds(2);
|
||||||
|
|
||||||
|
private const UInt16 FactorKwToW = 1000;
|
||||||
|
|
||||||
public static readonly TimeSpan UpdatePeriod = TimeSpan.FromSeconds(1);
|
public static readonly TimeSpan UpdatePeriod = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
public static readonly IReadOnlyList<Signal> Signals = new List<Signal>
|
public static readonly IReadOnlyList<Signal> Signals = new List<Signal>
|
||||||
{
|
{
|
||||||
new Signal(s => s._CurrentL1, "/Ac/L1/Current", "0.0 A"),
|
new Signal(s => s.CurrentL1, "/Ac/L1/Current", "0.0 A"),
|
||||||
new Signal(s => s._CurrentL2, "/Ac/L2/Current", "0.0 A"),
|
new Signal(s => s.CurrentL2, "/Ac/L2/Current", "0.0 A"),
|
||||||
new Signal(s => s._CurrentL3, "/Ac/L3/Current", "0.0 A"),
|
new Signal(s => s.CurrentL3, "/Ac/L3/Current", "0.0 A"),
|
||||||
new Signal(s => s._CurrentL1 + s._CurrentL2 + s._CurrentL3, "/Ac/Current", "0.0 A"),
|
new Signal(s => s.CurrentL1 + s.CurrentL2 + s.CurrentL3, "/Ac/Current", "0.0 A"),
|
||||||
|
|
||||||
new Signal(s => s._VoltageL1N, "/Ac/L1/Voltage", "0.0 V"),
|
new Signal(s => s.VoltageL1N, "/Ac/L1/Voltage", "0.0 V"),
|
||||||
new Signal(s => s._VoltageL2N, "/Ac/L2/Voltage", "0.0 V"),
|
new Signal(s => s.VoltageL2N, "/Ac/L2/Voltage", "0.0 V"),
|
||||||
new Signal(s => s._VoltageL3N, "/Ac/L3/Voltage", "0.0 V"),
|
new Signal(s => s.VoltageL3N, "/Ac/L3/Voltage", "0.0 V"),
|
||||||
new Signal(s => (s._VoltageL1N + s._VoltageL2N + s._VoltageL3N) / 3.0f, "/Ac/Voltage", "0.0 V"),
|
new Signal(s => (s.VoltageL1N + s.VoltageL2N + s.VoltageL3N) / 3.0f, "/Ac/Voltage", "0.0 V"),
|
||||||
|
|
||||||
new Signal(s => s.ActivePowerL1, "/Ac/L1/Power", "0 W"),
|
new Signal(s => s.ActivePowerL1 * FactorKwToW, "/Ac/L1/Power", "0 W"),
|
||||||
new Signal(s => s.ActivePowerL2, "/Ac/L2/Power", "0 W"),
|
new Signal(s => s.ActivePowerL2 * FactorKwToW, "/Ac/L2/Power", "0 W"),
|
||||||
new Signal(s => s.ActivePowerL3, "/Ac/L3/Power", "0 W"),
|
new Signal(s => s.ActivePowerL3 * FactorKwToW, "/Ac/L3/Power", "0 W"),
|
||||||
new Signal(s => s.ActivePowerL1 + s.ActivePowerL2 + s.ActivePowerL3, "/Ac/Power", "0 W"),
|
new Signal(s => s.TotalActivePower * FactorKwToW, "/Ac/Power", "0 W"),
|
||||||
|
|
||||||
|
|
||||||
new Signal(s => s.TotalActiveImport, "Ac/Energy/Forward", "0.00 kWh"),
|
new Signal(s => s.TotalActiveImport, "Ac/Energy/Forward", "0.00 kWh"),
|
||||||
|
|
|
@ -3,7 +3,6 @@ using InnovEnergy.Lib.Devices.IEM3kGridMeter;
|
||||||
using InnovEnergy.Lib.Protocols.DBus;
|
using InnovEnergy.Lib.Protocols.DBus;
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.Lib.Utils.Reflection;
|
|
||||||
using InnovEnergy.Lib.Victron.VeDBus;
|
using InnovEnergy.Lib.Victron.VeDBus;
|
||||||
|
|
||||||
namespace InnovEnergy.App.SchneiderDriver;
|
namespace InnovEnergy.App.SchneiderDriver;
|
||||||
|
@ -43,11 +42,11 @@ public static class SchneiderMeterDriver
|
||||||
var property = signal.ToVeProperty(reading);
|
var property = signal.ToVeProperty(reading);
|
||||||
if (property == null)
|
if (property == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Warning: Signal {signal} produced a null property.");
|
// Console.WriteLine($"Warning: Signal {signal} produced a null property.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Transformed Signal to Property: {property}");
|
//Console.WriteLine($"Transformed Signal to Property: {property}");
|
||||||
}
|
}
|
||||||
return property;
|
return property;
|
||||||
})
|
})
|
||||||
|
@ -55,7 +54,7 @@ public static class SchneiderMeterDriver
|
||||||
.Merge()
|
.Merge()
|
||||||
.Do(p =>
|
.Do(p =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Setting property: {p}");
|
// Console.WriteLine($"Setting property: {p}");
|
||||||
properties.Set(p);
|
properties.Set(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
csproj="SchneiderMeterDriver.csproj"
|
csproj="SchneiderMeterDriver.csproj"
|
||||||
exe="SchneiderMeterDriver"
|
exe="SchneiderMeterDriver"
|
||||||
remote="10.2.4.114"
|
remote="10.2.4.114"
|
||||||
|
|
|
@ -12,23 +12,24 @@ using Float32 = Single;
|
||||||
|
|
||||||
|
|
||||||
[AddressOffset(-2)] // why?
|
[AddressOffset(-2)] // why?
|
||||||
public class Iem3KGridMeterRegisters //: IAc3Meter
|
public class Iem3KGridMeterRegisters : IAc3Meter
|
||||||
{
|
{
|
||||||
private const Float32 ZeroBecauseReactivePowerNotSupported = 0;
|
private const Float32 ZeroBecauseReactivePowerNotSupported = 0;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
[HoldingRegister<Float32>(3054)] public Float32 ActivePowerL1;
|
[HoldingRegister<Float32>(3054)] public Float32 ActivePowerL1; // in Kw
|
||||||
[HoldingRegister<Float32>(3056)] public Float32 ActivePowerL2;
|
[HoldingRegister<Float32>(3056)] public Float32 ActivePowerL2; // in Kw
|
||||||
[HoldingRegister<Float32>(3058)] public Float32 ActivePowerL3;
|
[HoldingRegister<Float32>(3058)] public Float32 ActivePowerL3; // in Kw
|
||||||
|
[HoldingRegister<Float32>(3060)] public Float32 TotalActivePower; // in Kw
|
||||||
|
|
||||||
[HoldingRegister<Float32>(3000)] public Float32 _CurrentL1;
|
[HoldingRegister<Float32>(3000)] public Float32 CurrentL1;
|
||||||
[HoldingRegister<Float32>(3002)] public Float32 _CurrentL2;
|
[HoldingRegister<Float32>(3002)] public Float32 CurrentL2;
|
||||||
[HoldingRegister<Float32>(3004)] public Float32 _CurrentL3;
|
[HoldingRegister<Float32>(3004)] public Float32 CurrentL3;
|
||||||
//
|
//
|
||||||
[HoldingRegister<Float32>(3028)] public Float32 _VoltageL1N;
|
[HoldingRegister<Float32>(3028)] public Float32 VoltageL1N;
|
||||||
[HoldingRegister<Float32>(3030)] public Float32 _VoltageL2N;
|
[HoldingRegister<Float32>(3030)] public Float32 VoltageL2N;
|
||||||
[HoldingRegister<Float32>(3032)] public Float32 _VoltageL3N;
|
[HoldingRegister<Float32>(3032)] public Float32 VoltageL3N;
|
||||||
|
|
||||||
[HoldingRegister<Float32>(3518)] public Float32 ActiveEnergyImportL1;
|
[HoldingRegister<Float32>(3518)] public Float32 ActiveEnergyImportL1;
|
||||||
[HoldingRegister<Float32>(3522)] public Float32 ActiveEnergyImportL2;
|
[HoldingRegister<Float32>(3522)] public Float32 ActiveEnergyImportL2;
|
||||||
|
@ -37,45 +38,31 @@ public class Iem3KGridMeterRegisters //: IAc3Meter
|
||||||
[HoldingRegister<Float32>(45100)] public Float32 TotalActiveImport;
|
[HoldingRegister<Float32>(45100)] public Float32 TotalActiveImport;
|
||||||
[HoldingRegister<Float32>(45102)] public Float32 TotalActiveExport;
|
[HoldingRegister<Float32>(45102)] public Float32 TotalActiveExport;
|
||||||
|
|
||||||
|
[HoldingRegister<Float32>(3110)] private Float32 _frequency;
|
||||||
|
|
||||||
|
public Ac3Bus Ac => new Ac3Bus
|
||||||
|
|
||||||
//
|
|
||||||
//[HoldingRegister<Float32>(3110)] private Float32 _Frequency;
|
|
||||||
|
|
||||||
//[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
|
|
||||||
//[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
|
|
||||||
//[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
|
|
||||||
|
|
||||||
//[HoldingRegister<Float32>(9022)] private Float32 _ApparentPowerL1;
|
|
||||||
//[HoldingRegister<Float32>(9024)] private Float32 _ApparentPowerL2;
|
|
||||||
//[HoldingRegister<Float32>(9026)] private Float32 _ApparentPowerL3;
|
|
||||||
|
|
||||||
|
|
||||||
/*public Ac3Bus Ac => new Ac3Bus
|
|
||||||
{
|
{
|
||||||
L1 = new ()
|
L1 = new ()
|
||||||
{
|
{
|
||||||
Current = Abs(_CurrentL1),
|
Current = Abs(CurrentL1),
|
||||||
Voltage = Abs(_VoltageL1N),
|
Voltage = Abs(VoltageL1N),
|
||||||
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL1)
|
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL1)
|
||||||
},
|
},
|
||||||
L2 = new ()
|
L2 = new ()
|
||||||
{
|
{
|
||||||
Current = Abs(_CurrentL2),
|
Current = Abs(CurrentL2),
|
||||||
Voltage = Abs(_VoltageL2N),
|
Voltage = Abs(VoltageL2N),
|
||||||
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL2)
|
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL2)
|
||||||
},
|
},
|
||||||
L3 = new ()
|
L3 = new ()
|
||||||
{
|
{
|
||||||
Current = Abs(_CurrentL3),
|
Current = Abs(CurrentL3),
|
||||||
Voltage = Abs(_VoltageL3N),
|
Voltage = Abs(VoltageL3N),
|
||||||
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL3)
|
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL3)
|
||||||
},
|
},
|
||||||
Frequency = _Frequency
|
Frequency = _frequency
|
||||||
};*/
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue