Update truConvert devices to new status API

This commit is contained in:
atef 2023-04-04 13:43:23 +02:00
parent 2b14106e6b
commit b088665f39
5 changed files with 189 additions and 127 deletions

View File

@ -13,12 +13,8 @@ public enum PreChargeDcLinkConfig : UInt16
{
External = 0, // device waits for external precharge of DC link
Internal = 1, // device precharges external DC link to necessary start-up voltage
InternalWithDc =
2, // behaviour similar to 1 with additional support of DC submodules (necessary for island operation)
InternalWithWait =
3 // device precharges external DC link to necessary start-up voltage and waits until PrechargeDcLinkConfig gets set back to 1 or 2
InternalWithDc = 2, // behaviour similar to 1 with additional support of DC submodules (necessary for island operation)
InternalWithWait = 3 // device precharges external DC link to necessary start-up voltage and waits until PrechargeDcLinkConfig gets set back to 1 or 2
}
public enum AcErrorPolicy : UInt16

View File

@ -212,56 +212,118 @@ public class TruConvertAcDevice
var gridVoltageL3 = acActualMeasurement2.GetUInt16(5163) * 0.1m;
var gridFrequency = acActualMeasurement7.GetInt16(5201) * 0.01m;
return new TruConvertAcStatus
(
Ac: new Ac3Bus
(
new AcPhase(gridVoltageL1,phaseCurrentL1, ACos(powerAcL1/apparentPowerAcL1)),
new AcPhase(gridVoltageL2,phaseCurrentL2, ACos(powerAcL2/apparentPowerAcL2)),
new AcPhase(gridVoltageL3,phaseCurrentL3, ACos(powerAcL3/apparentPowerAcL3)),
gridFrequency // Gird Frequency
),
Dc: new DcConnection(dcVoltage, dcCurrent),
{
Ac = new Ac3Bus
{
Frequency = gridFrequency,
SerialNumber : acSerialNumber.GetInt32(2009).ToString(),
L1 = new AcPhase
{
Voltage = gridVoltageL1,
Current = phaseCurrentL1,
Phi = ACos(powerAcL1 / apparentPowerAcL1), // TODO: 2pi
},
L2 = new AcPhase
{
Voltage = gridVoltageL2,
Current = phaseCurrentL2,
Phi = ACos(powerAcL2 / apparentPowerAcL2), // TODO: 2pi
},
L3 = new AcPhase
{
Voltage = gridVoltageL3,
Current = phaseCurrentL3,
Phi = ACos(powerAcL3 / apparentPowerAcL3), // TODO: 2pi
}
},
Dc = new DcBus
{
Current = dcCurrent,
Voltage = dcVoltage,
},
// acActualMainValues
MainState : acActualMain.GetInt16(5001).ConvertTo<MainState>(),
NumberOfConnectedSlaves : acActualMain.GetUInt16(5002),
NumberOfConnectedSubSlaves : acActualMain.GetUInt16(5003),
MainState = acActualMain.GetInt16(5001).ConvertTo<MainState>(),
Alarms = alarms,
Warnings = warnings,
GridType = acActualAcDc.GetUInt16(5024).ConvertTo<AcDcGridType>(),
SerialNumber = acSerialNumber.GetInt32(2009).ToString(), // TODO: why tostring ?
NumberOfConnectedSlaves = acActualMain.GetUInt16(5002),
NumberOfConnectedSubSlaves = acActualMain.GetUInt16(5003),
AcDcNominalGridFrequency = acActualAcDc.GetUInt16(5021) * 0.1m,
AcDcNominalGridVoltage = acActualAcDc.GetUInt16(5022),
AcDcActNominalPower = acActualAcDc.GetUInt16(5023),
AcDcPowerLimitingStatusAct = acActualAcDc.GetUInt16(5025),
AcDcDcVoltageReference = acActualAcDc.GetUInt16(5026), // DC link reference
AcDcDcLinkVoltageMinAct = acActualAcDc.GetUInt16(5027), // DC link min voltage
AcDcDcLinkVoltageMaxAct = acActualAcDc.GetUInt16(5028), // DC link max voltage
AcDcDcLinkChargedMinVoltage = acActualAcDc.GetUInt16(5029) * 0.01m,
AcDcStmActCustomer = acActualAcDc2.GetUInt16(5031), //need to check
AcDcOverloadIntegratorStatusL1 = acActualAcDc3.GetUInt16(5134) * 0.1m,
AcDcOverloadIntegratorStatusL2 = acActualAcDc3.GetUInt16(5135) * 0.1m,
AcDcOverloadIntegratorStatusL3 = acActualAcDc3.GetUInt16(5136) * 0.1m,
AcSignedPowerValue = acSetValues.GetInt16(4196) * -1.0m, // this is also used for control
ActualDcLinkVoltageUpperHalf = acActualMeasurement8.GetUInt16(5211),
ActualDcLinkVoltageLowerHalf = acActualMeasurement8.GetUInt16(5212),
ActualDcLinkVoltageUpperHalfExt = acActualMeasurement8.GetUInt16(5213),
ActualDcLinkVoltageLowerHalfExt = acActualMeasurement8.GetUInt16(5214),
VoltageIntNtoPe = acActualMeasurement9.GetInt16(5221) * 0.1m,
VoltageExtNtoPe = acActualMeasurement9.GetInt16(5222) * 0.1m,
InletAirTemperature = acActualTemp.GetInt16(5501) * 0.1m,
//acActualAcDc
AcDcNominalGridFrequency : acActualAcDc.GetUInt16(5021) * 0.1m,
AcDcNominalGridVoltage : acActualAcDc.GetUInt16(5022),
AcDcActNominalPower : acActualAcDc.GetUInt16(5023),
AcDcActiveGridType : acActualAcDc.GetUInt16(5024).ConvertTo<AcDcGridType>(),
AcDcPowerLimitingStatusAct : acActualAcDc.GetUInt16(5025),
AcDcDcVoltageReference : acActualAcDc.GetUInt16(5026), // DC link reference
AcDcDcLinkVoltageMinAct : acActualAcDc.GetUInt16(5027), // DC link min voltage
AcDcDcLinkVoltageMaxAct : acActualAcDc.GetUInt16(5028), // DC link max voltage
AcDcDcLinkChargedMinVoltage : acActualAcDc.GetUInt16(5029) * 0.01m,
//ac Actual AcDc 2
AcDcStmActCustomer : acActualAcDc2.GetUInt16(5031), //need to check
AcDcOverloadIntegratorStatusL1 : acActualAcDc3.GetUInt16(5134) * 0.1m,
AcDcOverloadIntegratorStatusL2 : acActualAcDc3.GetUInt16(5135) * 0.1m,
AcDcOverloadIntegratorStatusL3 : acActualAcDc3.GetUInt16(5136) * 0.1m,
AcSignedPowerValue : acSetValues.GetInt16(4196) * -1.0m, // this is also used for control
//acActualMeasurement10
ActualDcLinkVoltageUpperHalf : acActualMeasurement8.GetUInt16(5211),
ActualDcLinkVoltageLowerHalf : acActualMeasurement8.GetUInt16(5212),
ActualDcLinkVoltageUpperHalfExt : acActualMeasurement8.GetUInt16(5213),
ActualDcLinkVoltageLowerHalfExt : acActualMeasurement8.GetUInt16(5214),
};
VoltageIntNtoPe : acActualMeasurement9.GetInt16(5221) * 0.1m,
VoltageExtNtoPe : acActualMeasurement9.GetInt16(5222) * 0.1m,
//acActualTemp
InletAirTemperature : acActualTemp.GetInt16(5501) * 0.1m,
Warnings : warnings,
Alarms : alarms
);
// (
// Ac: new Ac3Bus
// (
// new AcPhase(gridVoltageL1,phaseCurrentL1, ACos(powerAcL1/apparentPowerAcL1)),
// new AcPhase(gridVoltageL2,phaseCurrentL2, ACos(powerAcL2/apparentPowerAcL2)),
// new AcPhase(gridVoltageL3,phaseCurrentL3, ACos(powerAcL3/apparentPowerAcL3)),
// gridFrequency // Gird Frequency
// ),
// Dc: new DcConnection(dcVoltage, dcCurrent),
//
// SerialNumber : acSerialNumber.GetInt32(2009).ToString(),
//
// // acActualMainValues
// MainState : acActualMain.GetInt16(5001).ConvertTo<MainState>(),
// NumberOfConnectedSlaves : acActualMain.GetUInt16(5002),
// NumberOfConnectedSubSlaves : acActualMain.GetUInt16(5003),
//
// //acActualAcDc
// AcDcNominalGridFrequency : acActualAcDc.GetUInt16(5021) * 0.1m,
// AcDcNominalGridVoltage : acActualAcDc.GetUInt16(5022),
// AcDcActNominalPower : acActualAcDc.GetUInt16(5023),
// AcDcActiveGridType : acActualAcDc.GetUInt16(5024).ConvertTo<AcDcGridType>(),
// AcDcPowerLimitingStatusAct : acActualAcDc.GetUInt16(5025),
// AcDcDcVoltageReference : acActualAcDc.GetUInt16(5026), // DC link reference
// AcDcDcLinkVoltageMinAct : acActualAcDc.GetUInt16(5027), // DC link min voltage
// AcDcDcLinkVoltageMaxAct : acActualAcDc.GetUInt16(5028), // DC link max voltage
// AcDcDcLinkChargedMinVoltage : acActualAcDc.GetUInt16(5029) * 0.01m,
//
// //ac Actual AcDc 2
// AcDcStmActCustomer : acActualAcDc2.GetUInt16(5031), //need to check
// AcDcOverloadIntegratorStatusL1 : acActualAcDc3.GetUInt16(5134) * 0.1m,
// AcDcOverloadIntegratorStatusL2 : acActualAcDc3.GetUInt16(5135) * 0.1m,
// AcDcOverloadIntegratorStatusL3 : acActualAcDc3.GetUInt16(5136) * 0.1m,
// AcSignedPowerValue : acSetValues.GetInt16(4196) * -1.0m, // this is also used for control
//
// //acActualMeasurement10
// ActualDcLinkVoltageUpperHalf : acActualMeasurement8.GetUInt16(5211),
// ActualDcLinkVoltageLowerHalf : acActualMeasurement8.GetUInt16(5212),
// ActualDcLinkVoltageUpperHalfExt : acActualMeasurement8.GetUInt16(5213),
// ActualDcLinkVoltageLowerHalfExt : acActualMeasurement8.GetUInt16(5214),
//
// VoltageIntNtoPe : acActualMeasurement9.GetInt16(5221) * 0.1m,
// VoltageExtNtoPe : acActualMeasurement9.GetInt16(5222) * 0.1m,
// //acActualTemp
// InletAirTemperature : acActualTemp.GetInt16(5501) * 0.1m,
//
// Warnings : warnings,
// Alarms : alarms
// );
}
}

View File

@ -1,43 +1,44 @@
using InnovEnergy.Lib.Devices.Trumpf.TruConvert;
using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.StatusApi;
using InnovEnergy.Lib.Units;
namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
using AlarmMessages = IReadOnlyList<AlarmMessage>;
using WarningMessages = IReadOnlyList<WarningMessage>;
public record TruConvertAcStatus
(
Ac3Bus Ac,
DcConnection Dc,
String SerialNumber,
MainState MainState,
UInt16 NumberOfConnectedSlaves,
UInt16 NumberOfConnectedSubSlaves,
Decimal AcDcNominalGridFrequency,
Decimal AcDcNominalGridVoltage,
Decimal AcDcActNominalPower,
AcDcGridType AcDcActiveGridType,
Decimal AcDcPowerLimitingStatusAct,
Decimal AcDcDcVoltageReference,
Decimal AcDcDcLinkVoltageMinAct,
Decimal AcDcDcLinkVoltageMaxAct,
Decimal AcDcDcLinkChargedMinVoltage,
Decimal AcDcStmActCustomer,
Decimal AcDcOverloadIntegratorStatusL1,
Decimal AcDcOverloadIntegratorStatusL2,
Decimal AcDcOverloadIntegratorStatusL3,
Decimal AcSignedPowerValue,
Decimal ActualDcLinkVoltageUpperHalf,
Decimal ActualDcLinkVoltageLowerHalf,
Decimal ActualDcLinkVoltageUpperHalfExt,
Decimal ActualDcLinkVoltageLowerHalfExt,
Decimal VoltageIntNtoPe,
Decimal VoltageExtNtoPe,
Decimal InletAirTemperature,
WarningMessages Warnings,
AlarmMessages Alarms
) : ThreePhaseInverter(Ac, Dc)
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS8618
public record TruConvertAcStatus : ThreePhaseInverterStatus
{
}
public MainState MainState { get; init; }
public String SerialNumber { get; init; }
public AcDcGridType GridType { get; init; }
public WarningMessages Warnings { get; init; }
public AlarmMessages Alarms { get; init; }
public Decimal NumberOfConnectedSlaves { get; init; }
public Decimal NumberOfConnectedSubSlaves { get; init; }
public Frequency AcDcNominalGridFrequency { get; init; }
public Voltage AcDcNominalGridVoltage { get; init; }
public Power AcDcActNominalPower { get; init; }
public Decimal AcDcPowerLimitingStatusAct { get; init; } // TODO: enum
public Voltage AcDcDcVoltageReference { get; init; }
public Voltage AcDcDcLinkVoltageMinAct { get; init; }
public Voltage AcDcDcLinkVoltageMaxAct { get; init; }
public Voltage AcDcDcLinkChargedMinVoltage { get; init; }
public Decimal AcDcStmActCustomer { get; init; }
public Decimal AcDcOverloadIntegratorStatusL1 { get; init; }
public Decimal AcDcOverloadIntegratorStatusL2 { get; init; }
public Decimal AcDcOverloadIntegratorStatusL3 { get; init; }
public Power AcSignedPowerValue { get; init; }
public Voltage ActualDcLinkVoltageUpperHalf { get; init; }
public Voltage ActualDcLinkVoltageLowerHalf { get; init; }
public Voltage ActualDcLinkVoltageUpperHalfExt { get; init; }
public Voltage ActualDcLinkVoltageLowerHalfExt { get; init; }
public Voltage VoltageIntNtoPe { get; init; }
public Voltage VoltageExtNtoPe { get; init; }
public Temperature InletAirTemperature { get; init; }
}

View File

@ -3,6 +3,8 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvert;
using InnovEnergy.Lib.Protocols.Modbus.Clients;
using InnovEnergy.Lib.Protocols.Modbus.Connections;
using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Composite;
using InnovEnergy.Lib.Utils;
using static InnovEnergy.Lib.Devices.Trumpf.TruConvertDc.DcControlRegisters;
@ -138,27 +140,31 @@ public class TruConvertDcDevice
var dcCurrent = dcLinkVoltage != 0m ? dcPower / dcLinkVoltage : 0m;
return new TruConvertDcStatus
(
{
Left = new DcBus()
{
Current = dcCurrent,
Voltage = dcLinkVoltage
},
Right = new DcBus()
{
Current = dcBatteryValue2.GetInt16(5111),
Voltage =dcBatteryValue.GetUInt16(5101) * 0.1m,
},
Dc: new DcConnection
(
dcLinkVoltage,
dcCurrent
),
MainState : (MainState)dcPrValMain.GetInt16(5001),
NumberOfConnectedSlaves : dcPrValMain.GetUInt16(5002),
NumberOfConnectedSubSlaves : dcPrValMain.GetUInt16(5003),
BatteryVoltage : dcBatteryValue.GetUInt16(5101) * 0.1m,
BatteryCurrent : dcBatteryValue2.GetInt16(5111),
TotalDcPower : dcBatteryValue3.GetInt32(5114) * 1m, // Resolution is 0.001 (kW) in Tru convert DC doc, but we want it in W
StatusOfCurrentLimiting : dcCurrentLimitState,
OverloadCapacity : dcPrValDcDc2.GetUInt16(5127) * 0.1m,
DcDcInletTemperature : dcTempValue.GetInt16(5511),
Warnings : warnings,
Alarms : alarms,
PowerOperation : dcSetValues.GetBoolean(4001)
);
MainState = (MainState)dcPrValMain.GetInt16(5001),
NumberOfConnectedSlaves = dcPrValMain.GetUInt16(5002),
NumberOfConnectedSubSlaves = dcPrValMain.GetUInt16(5003),
TotalDcPower = dcBatteryValue3.GetInt32(5114) * 1m, // Resolution is 0.001 (kW) in Tru convert DC doc, but we want it in W
StatusOfCurrentLimiting = dcCurrentLimitState,
OverloadCapacity = dcPrValDcDc2.GetUInt16(5127) * 0.1m,
DcDcInletTemperature = dcTempValue.GetInt16(5511),
Warnings = warnings,
Alarms = alarms,
PowerOperation = dcSetValues.GetBoolean(4001),
};
}
}

View File

@ -1,3 +1,4 @@
using InnovEnergy.Lib.Devices.Trumpf.TruConvert;
using InnovEnergy.Lib.StatusApi;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Composite;
@ -9,24 +10,20 @@ using AlarmMessages = IReadOnlyList<AlarmMessage>;
using WarningMessages = IReadOnlyList<WarningMessage>;
using DcCurrentLimitStates = IReadOnlyList<DcCurrentLimitState>;
public record TruConvertDcStatus
(
DcBus DcLeft,
DcBus DcRight,
State MainState,
Power TotalDcPower, // TODO: necessary?
State StatusOfCurrentLimiting,
Decimal OverloadCapacity,
Temperature DcDcInletTemperature,
State Alarms,
State Warnings,
State PowerOperation
// UInt16 NumberOfConnectedSlaves, // TODO: necessary?
// UInt16 NumberOfConnectedSubSlaves, // TODO: necessary?
) :
DcDcConverterStatus(DcLeft, DcRight)
public record TruConvertDcStatus : DcDcConverterStatus
{
public static TruConvertDcStatus operator |(TruConvertDcStatus left, TruConvertDcStatus right) => OpParallel(left, right);
private static readonly Func<TruConvertDcStatus, TruConvertDcStatus, TruConvertDcStatus> OpParallel = Operators.Op<TruConvertDcStatus>("|");
}
public MainState MainState { get; init; }
public Power TotalDcPower { get; init; } // TODO: necessary?
public DcCurrentLimitStates StatusOfCurrentLimiting { get; init; }
public Decimal OverloadCapacity { get; init; }
public Temperature DcDcInletTemperature { get; init; }
public AlarmMessages Alarms { get; init; } = Array.Empty<AlarmMessage>();
public WarningMessages Warnings { get; init; } = Array.Empty<WarningMessage>();
public Boolean PowerOperation { get; init; }
public Decimal NumberOfConnectedSlaves { get; init; } // TODO: necessary?
public Decimal NumberOfConnectedSubSlaves { get; init; } // TODO: necessary?
}
// {
// public static TruConvertDcStatus operator |(TruConvertDcStatus left, TruConvertDcStatus right) => OpParallel(left, right);
// private static readonly Func<TruConvertDcStatus, TruConvertDcStatus, TruConvertDcStatus> OpParallel = Operators.Op<TruConvertDcStatus>("|");
// }