lift EmuMeter to new StatusApi
This commit is contained in:
parent
be5999e0f0
commit
55048b3f99
|
@ -1,3 +1,4 @@
|
||||||
|
using DecimalMath;
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
||||||
using InnovEnergy.Lib.StatusApi.Connections;
|
using InnovEnergy.Lib.StatusApi.Connections;
|
||||||
|
@ -29,7 +30,9 @@ public class EmuMeterDevice
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static Decimal GetPhi(Decimal cosPhi) => cosPhi.Clamp(-1m, 1m).Apply(ACos);
|
|
||||||
|
|
||||||
|
//private static Decimal GetPhi(Decimal cosPhi) => cosPhi.Clamp(-1m, 1m).Apply(ACos);
|
||||||
|
|
||||||
private EmuMeterStatus TryReadStatus()
|
private EmuMeterStatus TryReadStatus()
|
||||||
{
|
{
|
||||||
|
@ -75,45 +78,70 @@ public class EmuMeterDevice
|
||||||
var energyImportL3 = energyPhases[80 / 4] / 1000.0m;
|
var energyImportL3 = energyPhases[80 / 4] / 1000.0m;
|
||||||
var energyExportL3 = energyPhases[100 / 4] / 1000.0m;
|
var energyExportL3 = energyPhases[100 / 4] / 1000.0m;
|
||||||
|
|
||||||
|
// Ac: new Ac3Bus
|
||||||
|
// (
|
||||||
|
// new AcPhase(
|
||||||
|
// voltageL1N,
|
||||||
|
// currentL1,
|
||||||
|
// GetPhi(powerFactorL1)
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// new AcPhase(
|
||||||
|
// voltageL2N,
|
||||||
|
// currentL2,
|
||||||
|
// GetPhi(powerFactorL2)
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// new AcPhase(
|
||||||
|
// voltageL3N,
|
||||||
|
// currentL3,
|
||||||
|
// GetPhi(powerFactorL3)
|
||||||
|
// ),
|
||||||
|
// frequency
|
||||||
|
// ),
|
||||||
|
// activePowerL123,
|
||||||
|
// reactivePowerL123,
|
||||||
|
// apparentPowerL123,
|
||||||
|
// currentL123,
|
||||||
|
// voltageL1L2,
|
||||||
|
// voltageL2L3,
|
||||||
|
// voltageL3L1,
|
||||||
|
// energyImportL123,
|
||||||
|
// energyImportL1,
|
||||||
|
// energyImportL2,
|
||||||
|
// energyImportL3,
|
||||||
|
// energyExportL123,
|
||||||
|
// energyExportL1,
|
||||||
|
// energyExportL2,
|
||||||
|
// energyExportL3
|
||||||
|
// );
|
||||||
|
|
||||||
return new EmuMeterStatus
|
return new EmuMeterStatus
|
||||||
(
|
{
|
||||||
Ac: new Ac3Bus
|
Ac = new Ac3Bus
|
||||||
(
|
{
|
||||||
new AcPhase(
|
Frequency = frequency,
|
||||||
voltageL1N,
|
L1 = new AcPhase
|
||||||
currentL1,
|
{
|
||||||
GetPhi(powerFactorL1)
|
Current = currentL1,
|
||||||
),
|
Voltage = voltageL1N,
|
||||||
|
Phi = ATan2(reactivePowerL1, activePowerL1) // TODO: check that this works
|
||||||
new AcPhase(
|
},
|
||||||
voltageL2N,
|
L2 = new AcPhase
|
||||||
currentL2,
|
{
|
||||||
GetPhi(powerFactorL2)
|
Current = currentL2,
|
||||||
),
|
Voltage = voltageL2N,
|
||||||
|
Phi = ATan2(reactivePowerL2, activePowerL2)
|
||||||
new AcPhase(
|
},
|
||||||
voltageL3N,
|
L3 = new AcPhase
|
||||||
currentL3,
|
{
|
||||||
GetPhi(powerFactorL3)
|
Current = currentL3,
|
||||||
),
|
Voltage = voltageL3N,
|
||||||
frequency
|
Phi = ATan2(reactivePowerL3, activePowerL3)
|
||||||
),
|
}
|
||||||
activePowerL123,
|
}
|
||||||
reactivePowerL123,
|
};
|
||||||
apparentPowerL123,
|
|
||||||
currentL123,
|
|
||||||
voltageL1L2,
|
|
||||||
voltageL2L3,
|
|
||||||
voltageL3L1,
|
|
||||||
energyImportL123,
|
|
||||||
energyImportL1,
|
|
||||||
energyImportL2,
|
|
||||||
energyImportL3,
|
|
||||||
energyExportL123,
|
|
||||||
energyExportL1,
|
|
||||||
energyExportL2,
|
|
||||||
energyExportL3
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,27 +1,10 @@
|
||||||
using InnovEnergy.Lib.StatusApi;
|
using InnovEnergy.Lib.StatusApi;
|
||||||
using InnovEnergy.Lib.StatusApi.Connections;
|
|
||||||
using InnovEnergy.Lib.Units.Composite;
|
|
||||||
|
|
||||||
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
||||||
|
|
||||||
public record EmuMeterStatus
|
public record EmuMeterStatus : PowerMeterStatus
|
||||||
(
|
{
|
||||||
Ac3Bus Ac,
|
// TODO add serial nb, (and other?)
|
||||||
Decimal ActivePowerL123,
|
}
|
||||||
Decimal ReactivePowerL123,
|
|
||||||
Decimal ApparentPowerL123,
|
|
||||||
Decimal CurrentL123,
|
|
||||||
Decimal VoltageL1L2,
|
|
||||||
Decimal VoltageL2L3,
|
|
||||||
Decimal VoltageL3L1,
|
|
||||||
Decimal EnergyImportL123,
|
|
||||||
Decimal EnergyImportL1,
|
|
||||||
Decimal EnergyImportL2,
|
|
||||||
Decimal EnergyImportL3,
|
|
||||||
Decimal EnergyExportL123,
|
|
||||||
Decimal EnergyExportL1,
|
|
||||||
Decimal EnergyExportL2,
|
|
||||||
Decimal EnergyExportL3
|
|
||||||
):PowerMeterStatus(Ac)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue