Finished first implementation of modbus error registers

This commit is contained in:
Matthias Heisig
2025-04-14 19:38:17 +02:00
parent 4a00a4c414
commit f79cf27c0c
19 changed files with 998 additions and 531 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.12">
<POU Name="MAIN" Id="{bbd7302c-91ce-4697-9f4b-743f57ca5819}" SpecialFunc="None">
<Declaration><![CDATA[PROGRAM MAIN
VAR
@@ -122,8 +122,6 @@ VAR
_xAllComponentsToManualMode : BOOL;
// DEBUG
_xRestart : BOOL;
_ModbusDebugTest : ST_MODBUS_REG_11;
_fbStringReadyTimeout : TON;
@@ -158,21 +156,7 @@ VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[// ===============================
// DEBUG
IF _xRestart AND (_iState = 1010) THEN
GVL_MODBUS.stModbusEMSComm.stModbusReg12.diSetpointActivePower := 0;
_xConfirmAlarms := TRUE;
END_IF
IF _xRestart AND (_iState = 0) THEN
_xRestart := FALSE;
GVL_MODBUS.stModbusEMSComm.stModbusReg12.diSetpointActivePower := 1000;
END_IF
// DEBUG
// ===============================
IF _xFirstCycle THEN
<ST><![CDATA[IF _xFirstCycle THEN
_xFirstCycle := FALSE;
_xGetPowerMeterData := TRUE;
@@ -206,6 +190,12 @@ IF GVL_SCADA.stAckAlarmsButton.xRequest THEN
GVL_SCADA.stAckAlarmsButton.xRequest := FALSE;
END_IF
// Ack alarms through modbus
IF GVL_MODBUS.stBMSErrorReg.wConfirmAlarms > 0 THEN
GVL_MODBUS.stBMSErrorReg.wConfirmAlarms := 0;
_xConfirmAlarms := TRUE;
END_IF
// ===============================
// EtherCAT communication error
// ===============================
@@ -218,6 +208,7 @@ _wDebug2 := (_wEtherCATState AND 16#2000);
// String 1 on X1 = Port D = 0x8000
IF (NOT _xEtherCatString1Ok) AND (NOT _fbEtherCATErrorString1.bRaised) THEN
_fbEtherCATErrorString1.Raise(0);
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bEthercat := 1;
END_IF
IF _fbEtherCATErrorString1.bRaised AND (_xEtherCatString1Ok) THEN
@@ -231,6 +222,7 @@ END_IF
// String 2 on X2 = Port B = 0x2000
IF (NOT _xEtherCatString2Ok) AND (NOT _fbEtherCATErrorString2.bRaised) THEN
_fbEtherCATErrorString2.Raise(0);
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bEthercat := 1;
END_IF
IF _fbEtherCATErrorString2.bRaised AND _xEtherCatString2Ok THEN
@@ -260,6 +252,8 @@ IF _fbEStopNotOk.eConfirmationState = TcEventConfirmationState.WaitForConfirmati
_fbEStopNotOk.Confirm(0);
END_IF
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bEStop := (NOT _xEmergencyStopOk) OR _fbEStopNotOk.bRaised OR (_fbEStopNotOk.eConfirmationState <> TcEventConfirmationState.Confirmed);
// ===============================
// Hardware reset button part 1
// ===============================
@@ -303,6 +297,7 @@ _tonStartupDelay(IN := TRUE);
// Call string 1
_afbStrings[0](
xEnable := _xEnableString,
uiStringNumber := 0,
xErrorShutdown := _xErrorShutdown,
xStartBalancing := _xStartBalancing,
sInverterIP := GVL_CONFIG.sInverterIpString1,
@@ -321,9 +316,17 @@ IF _afbStrings[0].xError THEN
_xErrorActive := TRUE;
END_IF
// Handle string 1 modbus error and warning
GVL_MODBUS.stBMSErrorReg.wStringErrorActive.0 := _afbStrings[0].xError;
GVL_MODBUS.stBMSErrorReg.wStringWarningActive.0 := _afbStrings[0].xWarning;
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bDCSwitchS1 := _afbStrings[0].xRepairSwitchOk;
GVL_MODBUS.stBMSErrorReg.wBMSWarningActive.stBitmap.bSafetyIntlkString1 := (NOT _afbStrings[0].xSafetyIntlksOk);
// Call string 2
_afbStrings[1](
xEnable := _xEnableString,
uiStringNumber := 1,
xErrorShutdown := _xErrorShutdown,
xStartBalancing := _xStartBalancing,
sInverterIP := GVL_CONFIG.sInverterIpString2,
@@ -342,6 +345,16 @@ IF _afbStrings[1].xError THEN
_xErrorActive := TRUE;
END_IF
// Handle string 1 modbus error and warning
GVL_MODBUS.stBMSErrorReg.wStringErrorActive.1 := _afbStrings[1].xError;
GVL_MODBUS.stBMSErrorReg.wStringWarningActive.1 := _afbStrings[1].xWarning;
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bDCSwitchS2 := _afbStrings[1].xRepairSwitchOk;
GVL_MODBUS.stBMSErrorReg.wBMSWarningActive.stBitmap.bSafetyIntlkString2 := (NOT _afbStrings[1].xSafetyIntlksOk);
// Copy general error to modbus error register
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.stBitmap.bError := _xErrorActive;
// ===============================
// Get global string status information
// ===============================
@@ -616,6 +629,9 @@ IF _xStringsInAutoMode AND _fbNoAutomaticModeAlarm.bRaised THEN
_fbNoAutomaticModeAlarm.Clear(0, TRUE);
END_IF
// Copy auto mode warning message to modbus register
GVL_MODBUS.stBMSErrorReg.wBMSWarningActive.stBitmap.bNotAllInAuto := (NOT _xStringsInAutoMode);
// Reset automatic buttons
IF GVL_SCADA.stAutomaticModeHMI.stStartAutoButton.xRequest THEN
GVL_SCADA.stAutomaticModeHMI.stStartAutoButton.xRequest := FALSE;
@@ -626,6 +642,8 @@ END_IF
// Reset alarm confirmation
IF _xConfirmAlarms OR _rtHardwareResetButton.Q THEN
GVL_MODBUS.stBMSErrorReg.wBMSErrorActive.wRegister := 0;
GVL_MODBUS.stBMSErrorReg.wBMSWarningActive.wRegister := 0;
_xConfirmAlarms := FALSE;
END_IF