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.Connections;
|
||||
using InnovEnergy.Lib.StatusApi.Connections;
|
||||
|
@ -29,7 +30,9 @@ public class EmuMeterDevice
|
|||
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()
|
||||
{
|
||||
|
@ -75,45 +78,70 @@ public class EmuMeterDevice
|
|||
var energyImportL3 = energyPhases[80 / 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
|
||||
(
|
||||
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
|
||||
);
|
||||
{
|
||||
Ac = new Ac3Bus
|
||||
{
|
||||
Frequency = frequency,
|
||||
L1 = new AcPhase
|
||||
{
|
||||
Current = currentL1,
|
||||
Voltage = voltageL1N,
|
||||
Phi = ATan2(reactivePowerL1, activePowerL1) // TODO: check that this works
|
||||
},
|
||||
L2 = new AcPhase
|
||||
{
|
||||
Current = currentL2,
|
||||
Voltage = voltageL2N,
|
||||
Phi = ATan2(reactivePowerL2, activePowerL2)
|
||||
},
|
||||
L3 = new AcPhase
|
||||
{
|
||||
Current = currentL3,
|
||||
Voltage = voltageL3N,
|
||||
Phi = ATan2(reactivePowerL3, activePowerL3)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,10 @@
|
|||
using InnovEnergy.Lib.StatusApi;
|
||||
using InnovEnergy.Lib.StatusApi.Connections;
|
||||
using InnovEnergy.Lib.Units.Composite;
|
||||
|
||||
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
||||
|
||||
public record EmuMeterStatus
|
||||
(
|
||||
Ac3Bus Ac,
|
||||
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)
|
||||
{}
|
||||
public record EmuMeterStatus : PowerMeterStatus
|
||||
{
|
||||
// TODO add serial nb, (and other?)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue