Update IEM3kGridMeter

This commit is contained in:
atef 2024-02-20 17:43:23 +01:00
parent e026d7303a
commit 1768dbb504
1 changed files with 48 additions and 21 deletions

View File

@ -1,6 +1,8 @@
using InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes;
using InnovEnergy.Lib.StatusApi.DeviceTypes;
using InnovEnergy.Lib.Units.Composite;
using static System.Math;
#pragma warning disable CS0649
@ -12,34 +14,59 @@ using Float32 = Single;
[AddressOffset(-2)] // why?
public class Iem3KGridMeterRegisters : IAc3Meter
{
private const Float32 ZeroBecauseReactivePowerNotSupported = 0;
// TODO
// The registers below are kept as example (from EmuMeter)
// replace with actual registers from datasheet
[HoldingRegister<Float32>(9002)] private Float32 _ActivePowerL1;
[HoldingRegister<Float32>(9004)] private Float32 _ActivePowerL2;
[HoldingRegister<Float32>(9006)] private Float32 _ActivePowerL3;
[HoldingRegister<Float32>(3054)] private Float32 _ActivePowerL1;
[HoldingRegister<Float32>(3056)] private Float32 _ActivePowerL2;
[HoldingRegister<Float32>(3058)] private Float32 _ActivePowerL3;
[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
[HoldingRegister<Float32>(3000)] private Float32 _CurrentL1;
[HoldingRegister<Float32>(3002)] private Float32 _CurrentL2;
[HoldingRegister<Float32>(3004)] private Float32 _CurrentL3;
[HoldingRegister<Float32>(9022)] private Float32 _ApparentPowerL1;
[HoldingRegister<Float32>(9024)] private Float32 _ApparentPowerL2;
[HoldingRegister<Float32>(9026)] private Float32 _ApparentPowerL3;
[HoldingRegister<Float32>(3028)] private Float32 _VoltageL1N;
[HoldingRegister<Float32>(3030)] private Float32 _VoltageL2N;
[HoldingRegister<Float32>(3032)] private Float32 _VoltageL3N;
[HoldingRegister<Float32>(9102)] private Float32 _CurrentL1;
[HoldingRegister<Float32>(9104)] private Float32 _CurrentL2;
[HoldingRegister<Float32>(9106)] private Float32 _CurrentL3;
[HoldingRegister<Float32>(3110)] private Float32 _Frequency;
[HoldingRegister<Float32>(9200)] private Float32 _VoltageL1N;
[HoldingRegister<Float32>(9202)] private Float32 _VoltageL2N;
[HoldingRegister<Float32>(9204)] private Float32 _VoltageL3N;
//[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
//[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
//[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
[HoldingRegister<Float32>(9310)] private Float32 _Frequency;
//[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
//[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
//[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
public Ac3Bus Ac => throw new NotImplementedException();
//[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 ()
{
Current = Abs(_CurrentL1),
Voltage = Abs(_VoltageL1N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL1)
},
L2 = new ()
{
Current = Abs(_CurrentL2),
Voltage = Abs(_VoltageL2N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL2)
},
L3 = new ()
{
Current = Abs(_CurrentL3),
Voltage = Abs(_VoltageL3N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL3)
},
Frequency = _Frequency
};
}