EMS communication and Voltage optimizations

- Added data for EMS communication
- Added highest segment voltage for charging check
- Added lowest segment voltage for discharging check
This commit is contained in:
Matthias Heisig
2024-05-07 17:10:29 +02:00
parent 327f324be8
commit 0ffff9be2a
11 changed files with 660 additions and 383 deletions

View File

@@ -95,6 +95,12 @@ VAR
_fbBatteryFullMessage : FB_TcMessage;
_fbBatteryEmptyMessage : FB_TcMessage;
// Smallest segment voltage
_rSmallestSegmentVoltage : REAL;
// Highest segment voltage
_rHighestSegmentVoltage : REAL;
// Safety
_fbSafety : FB_Safety;
@@ -104,6 +110,12 @@ VAR
_xDebug : BOOL;
_uiDebugCurrentString : UINT := 1;
_ModbusDebugTest : ST_MODBUS_REG_11;
_fbModbusRead : FB_MBReadRegs;
_iLength : WORD := 49;
bDebugTest : BOOL;
END_VAR
]]></Declaration>
<Implementation>
@@ -273,6 +285,40 @@ _fbADSReader(
ERR=> ,
ERRID=> );
_fbModbusRead(
sIPAddr:= '127.0.0.1',
nTCPPort:= 502,
nUnitID:= 16#FF,
nQuantity:= 48,
nMBAddr:= 11000,
cbLength:= SIZEOF(_ModbusDebugTest),
pDestAddr:= ADR(_ModbusDebugTest),
bExecute:= bDebugTest,
tTimeout:= T#5S,
bBusy=> ,
bError=> ,
nErrId=> ,
cbRead=> );
// ===============================
// Copy data to modbus registers
// ===============================
// Modbus current inverter values
GVL_MODBUS.stModbusEMSComm.stModbusReg11.diCurrentActivePower := REAL_TO_DINT(_afbStrings[_uiDebugCurrentString].stInverterData.rActACPower);
GVL_MODBUS.stModbusEMSComm.stModbusReg11.diCurrentReactivePower := REAL_TO_DINT(_afbStrings[_uiDebugCurrentString].stInverterData.rActReactivePower);
// Set Modbus mirror values
GVL_MODBUS.stModbusEMSComm.stModbusReg11.diSetpointActivePowerMirror := GVL_MODBUS.stModbusEMSComm.stModbusReg12.diSetpointActivePower;
GVL_MODBUS.stModbusEMSComm.stModbusReg11.rSetpointCosPhiMirror := GVL_MODBUS.stModbusEMSComm.stModbusReg12.rSetpointCosPhi;
// ===============================
// Calculate highest and lowest
// segment voltage
// ===============================
_rSmallestSegmentVoltage := _afbStrings[_uiDebugCurrentString].rSmallestSegmentVoltage;
_rHighestSegmentVoltage := _afbStrings[_uiDebugCurrentString].rHighestSegmentVoltage;
// ===============================
// State machine
@@ -435,7 +481,7 @@ END_IF]]></ST>
END_IF
// Shutdown triggered by battery fully charged
IF GVL_MODBUS.stModbusEMSComm.stModbusReg11.eChargeStatus = E_CHARGE_STATUS.CHARGING AND (_afbStrings[_uiDebugCurrentString].stInverterData.rActDCVoltage >= GVL_CONFIG.rStringFullyChargedVoltage) THEN
IF GVL_MODBUS.stModbusEMSComm.stModbusReg11.eChargeStatus = E_CHARGE_STATUS.CHARGING AND ((_afbStrings[_uiDebugCurrentString].stInverterData.rActDCVoltage >= GVL_CONFIG.rStringFullyChargedVoltage) OR _rHighestSegmentVoltage >= GVL_CONFIG.rMaximumUnitVoltage) THEN
_tonBeginShutdown(In := FALSE);
// Send message
@@ -457,7 +503,7 @@ END_IF]]></ST>
END_IF
// Shutdown triggered by battery empty
IF GVL_MODBUS.stModbusEMSComm.stModbusReg11.eChargeStatus = E_CHARGE_STATUS.DISCHARGING AND (_afbStrings[_uiDebugCurrentString].stInverterData.rActDCVoltage <= GVL_CONFIG.rStringEmptyVoltage) THEN
IF GVL_MODBUS.stModbusEMSComm.stModbusReg11.eChargeStatus = E_CHARGE_STATUS.DISCHARGING AND ((_afbStrings[_uiDebugCurrentString].stInverterData.rActDCVoltage <= GVL_CONFIG.rStringEmptyVoltage) OR _rSmallestSegmentVoltage <= GVL_CONFIG.rMinimumUnitVoltage) THEN
_tonBeginShutdown(In := FALSE);
// Send Message
@@ -741,7 +787,26 @@ END_CASE]]></ST>
<LineId Id="2490" Count="10" />
<LineId Id="2484" Count="0" />
<LineId Id="2113" Count="19" />
<LineId Id="2144" Count="23" />
<LineId Id="2144" Count="15" />
<LineId Id="3088" Count="0" />
<LineId Id="3094" Count="12" />
<LineId Id="3089" Count="0" />
<LineId Id="3124" Count="0" />
<LineId Id="3123" Count="0" />
<LineId Id="3125" Count="2" />
<LineId Id="2160" Count="0" />
<LineId Id="3081" Count="1" />
<LineId Id="3085" Count="0" />
<LineId Id="3084" Count="0" />
<LineId Id="3083" Count="0" />
<LineId Id="3086" Count="0" />
<LineId Id="3115" Count="2" />
<LineId Id="3119" Count="0" />
<LineId Id="3121" Count="0" />
<LineId Id="3120" Count="0" />
<LineId Id="3118" Count="0" />
<LineId Id="3122" Count="0" />
<LineId Id="2161" Count="6" />
<LineId Id="2601" Count="0" />
<LineId Id="2168" Count="0" />
<LineId Id="2944" Count="1" />