Some fixes before the FAT
- Refactored inverter Heartbeat check - Added SafetyComError on EtherCAT checking - Adjusted lower pressure value for safety plc from 200 mBar to 300mBar
This commit is contained in:
@@ -38,6 +38,9 @@ VAR
|
||||
// FB for writing Modbus holding registers for inverter heartbeat
|
||||
_fbWriteHeartbeatRegister : FB_MBWriteRegs;
|
||||
|
||||
// FB for reading Modbus holding registers for inverter heartbeat
|
||||
_fbReadHeartbeatRegister : FB_MBReadRegs;
|
||||
|
||||
// Timer for checking if the inverter started in a reasonable amount of time
|
||||
//_tonInverterStartup : TON;
|
||||
|
||||
@@ -226,30 +229,7 @@ IF (rPower < -rMaxBattPower) THEN
|
||||
rPower := -rMaxBattPower;
|
||||
END_IF
|
||||
|
||||
// Increment heartbeat counter
|
||||
_tonHearbeatIncTimer(IN := TRUE);
|
||||
IF _tonHearbeatIncTimer.Q THEN
|
||||
_tonHearbeatIncTimer(IN := FALSE);
|
||||
_uiPLCToInverterCounter := _uiPLCToInverterCounter + 1;
|
||||
_fbWriteHeartbeatRegister.bExecute := TRUE;
|
||||
END_IF
|
||||
_fbWriteHeartbeatRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= CONTROLLER_HB,
|
||||
cbLength:= SIZEOF(_uiPLCToInverterCounter),
|
||||
pSrcAddr:= ADR(_uiPLCToInverterCounter),
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> );
|
||||
// If writing modbus register is done
|
||||
IF NOT _fbWriteHeartbeatRegister.bBusy THEN
|
||||
// And there is no error, then continue
|
||||
_fbWriteHeartbeatRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
HandleHeartbeat();
|
||||
|
||||
// State machine
|
||||
CASE _iState OF
|
||||
@@ -362,7 +342,7 @@ CASE _iState OF
|
||||
// If there was no error and the converter has no error continue
|
||||
IF NOT _fbReadRegister.bError THEN
|
||||
// Go back to polling state
|
||||
_iState := 6;
|
||||
_iState := 0;
|
||||
stCurrentValues.rActACCurrent := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[0]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[4])));
|
||||
stCurrentValues.rActtACPhaseACurrent := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[1]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[4])));
|
||||
stCurrentValues.rActtACPhaseBCurrent := LREAL_TO_REAL(WORD_TO_INT(_awCurrentACValues[2]) * EXPT(10,WORD_TO_INT(_awCurrentACValues[4])));
|
||||
@@ -379,46 +359,6 @@ CASE _iState OF
|
||||
END_IF
|
||||
_fbReadRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
|
||||
6: // Check heartbeat signal
|
||||
_fbReadRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= PCS_HB,
|
||||
cbLength:= SIZEOF(_uiInverterToPLCCounter),
|
||||
pDestAddr:= ADR(_uiInverterToPLCCounter),
|
||||
bExecute:= TRUE,
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> ,
|
||||
cbRead=> );
|
||||
|
||||
IF NOT _fbReadRegister.bBusy THEN
|
||||
IF (NOT _fbReadRegister.bError) THEN
|
||||
// Check if counter has been incremented by the inverter
|
||||
IF (_uiInverterToPLCCounter - _uiInverterToPLCCounterOld) > 0 THEN
|
||||
_xInverterHBCounterIncremented := TRUE;
|
||||
|
||||
// Safe old value
|
||||
_uiInverterToPLCCounterOld := _uiInverterToPLCCounter;
|
||||
ELSE
|
||||
_xInverterHBCounterIncremented := FALSE;
|
||||
END_IF
|
||||
|
||||
_iState := 0;
|
||||
ELSE
|
||||
xError := TRUE;
|
||||
_iErrorInState := _iState;
|
||||
// Goto error state
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
_fbReadRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
|
||||
10: // Wait for inverter to be online and in state STANDBY(8)
|
||||
@@ -979,7 +919,7 @@ CASE _iState OF
|
||||
// Check if reading mudbus register is done
|
||||
IF NOT _fbReadRegister.bBusy THEN
|
||||
IF NOT _fbReadRegister.bError THEN
|
||||
_iState := 91;
|
||||
_iState := 93;
|
||||
stCurrentValues.uiStatus := _uiInverterState;
|
||||
ELSE
|
||||
_iErrorInState := _iState;
|
||||
@@ -989,78 +929,6 @@ CASE _iState OF
|
||||
_fbReadRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
|
||||
91: // Send heartbeat signal
|
||||
_uiPLCToInverterCounter := _uiPLCToInverterCounter + 1;
|
||||
_fbWriteRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= CONTROLLER_HB,
|
||||
cbLength:= SIZEOF(_uiPLCToInverterCounter),
|
||||
pSrcAddr:= ADR(_uiPLCToInverterCounter),
|
||||
bExecute:= TRUE,
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> );
|
||||
|
||||
// If writing modbus register is done
|
||||
IF NOT _fbWriteRegister.bBusy THEN
|
||||
// And there is no error, then continue
|
||||
IF NOT _fbWriteRegister.bError THEN
|
||||
_iState := 92;
|
||||
ELSE
|
||||
_iErrorInState := _iState;
|
||||
xError := TRUE;
|
||||
// Goto error state
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
_fbWriteRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
|
||||
92: // Check heartbeat signal
|
||||
_fbReadRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= PCS_HB,
|
||||
cbLength:= SIZEOF(_uiInverterToPLCCounter),
|
||||
pDestAddr:= ADR(_uiInverterToPLCCounter),
|
||||
bExecute:= TRUE,
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> ,
|
||||
cbRead=> );
|
||||
|
||||
IF NOT _fbReadRegister.bBusy THEN
|
||||
IF (NOT _fbReadRegister.bError) THEN
|
||||
// Check if counter has been incremented by the inverter
|
||||
IF (_uiInverterToPLCCounter - _uiInverterToPLCCounterOld) > 0 THEN
|
||||
_xInverterHBCounterIncremented := TRUE;
|
||||
|
||||
// Safe old value
|
||||
_uiInverterToPLCCounterOld := _uiInverterToPLCCounter;
|
||||
ELSE
|
||||
_xInverterHBCounterIncremented := FALSE;
|
||||
END_IF
|
||||
|
||||
// _iState := 65;
|
||||
_iState := 93;
|
||||
ELSE
|
||||
xError := TRUE;
|
||||
_iErrorInState := _iState;
|
||||
// Goto error state
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
_fbReadRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
93: // Send current power demand
|
||||
_fbWriteRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
@@ -1223,11 +1091,14 @@ CASE _iState OF
|
||||
|
||||
1000: // Write error state to log
|
||||
ADSLOGDINT(msgCtrlMask:= ADSLOG_MSGTYPE_ERROR, msgFmtStr:= 'Fehler im state: %s', dintArg:= INT_TO_DINT(_iErrorInState));
|
||||
_fbWriteRegister(bExecute := FALSE);
|
||||
_fbReadRegister(bExecute := FALSE);
|
||||
xActive := FALSE;
|
||||
xError := TRUE;
|
||||
_iState := 1001;
|
||||
|
||||
1001: // Error state, wait for reset
|
||||
IF xReset AND (NOT xEnable) THEN
|
||||
IF xReset AND xHeartbeatOk AND (NOT xEnable) THEN
|
||||
_iState := 1010;
|
||||
END_IF
|
||||
|
||||
@@ -1270,11 +1141,13 @@ IF _fbHeartbeatTimeout.Q THEN
|
||||
xHeartbeatOk := FALSE;
|
||||
END_IF
|
||||
|
||||
IF (NOT xHeartbeatOk) AND (_iState < 1000) THEN
|
||||
_iState := 1000;
|
||||
END_IF
|
||||
|
||||
// ===============================
|
||||
// Inverter alarm handling
|
||||
// ===============================
|
||||
|
||||
IF xError AND (NOT _fbErrorInverterAlarm.bRaised) THEN
|
||||
_fbErrorInverterAlarm.Raise(0);
|
||||
END_IF
|
||||
@@ -1304,6 +1177,74 @@ _fbErrorInverterAlarm.CreateEx(stEventEntry := TC_EVENTS.Inverter.InverterError,
|
||||
_fbErrorInverterAlarm.ipArguments.Clear().AddString(_sName);]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Action Name="HandleHeartbeat" Id="{323d78bf-2521-40eb-b5f1-47fb6b9e0ed1}">
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Increment heartbeat counter and check current heartbeat
|
||||
_tonHearbeatIncTimer(IN := TRUE);
|
||||
IF _tonHearbeatIncTimer.Q THEN
|
||||
_tonHearbeatIncTimer(IN := FALSE);
|
||||
_uiPLCToInverterCounter := _uiPLCToInverterCounter + 1;
|
||||
IF (NOT _fbWriteHeartbeatRegister.bBusy) THEN
|
||||
_fbWriteHeartbeatRegister.bExecute := TRUE;
|
||||
END_IF
|
||||
IF (NOT _fbReadHeartbeatRegister.bBusy) THEN
|
||||
_fbReadHeartbeatRegister.bExecute := TRUE;
|
||||
END_IF
|
||||
END_IF
|
||||
|
||||
// Write new heartbeat counter
|
||||
_fbWriteHeartbeatRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= CONTROLLER_HB,
|
||||
cbLength:= SIZEOF(_uiPLCToInverterCounter),
|
||||
pSrcAddr:= ADR(_uiPLCToInverterCounter),
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> );
|
||||
|
||||
// If writing modbus register is done
|
||||
IF (NOT _fbWriteHeartbeatRegister.bBusy) THEN
|
||||
_fbWriteHeartbeatRegister(bExecute := FALSE);
|
||||
END_IF
|
||||
|
||||
// Read current heartbeat counter
|
||||
_fbReadHeartbeatRegister(
|
||||
sIPAddr:= sInverterIPAddr,
|
||||
nTCPPort:= 502,
|
||||
nUnitID:= 16#FF, // 16#FF for Modbus TCP
|
||||
nQuantity:= 1,
|
||||
nMBAddr:= PCS_HB,
|
||||
cbLength:= SIZEOF(_uiInverterToPLCCounter),
|
||||
pDestAddr:= ADR(_uiInverterToPLCCounter),
|
||||
tTimeout:= T#5S,
|
||||
bBusy=> ,
|
||||
bError=> ,
|
||||
nErrId=> ,
|
||||
cbRead=> );
|
||||
|
||||
IF (NOT _fbReadHeartbeatRegister.bBusy) THEN
|
||||
_fbReadHeartbeatRegister(bExecute := FALSE);
|
||||
IF (NOT _fbReadHeartbeatRegister.bError) THEN
|
||||
// Check if counter has been incremented by the inverter
|
||||
IF (_uiInverterToPLCCounter - _uiInverterToPLCCounterOld) > 0 THEN
|
||||
_xInverterHBCounterIncremented := TRUE;
|
||||
|
||||
// Safe old value
|
||||
_uiInverterToPLCCounterOld := _uiInverterToPLCCounter;
|
||||
ELSE
|
||||
_xInverterHBCounterIncremented := FALSE;
|
||||
END_IF
|
||||
ELSE
|
||||
// only flag heartbeat as incremented of modbusregister could be read
|
||||
_xInverterHBCounterIncremented := FALSE;
|
||||
END_IF
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</Action>
|
||||
<Property Name="Name" Id="{ef8c6e8f-7c1b-4781-b201-87f759acb289}">
|
||||
<Declaration><![CDATA[PROPERTY Name : string]]></Declaration>
|
||||
<Get Name="Get" Id="{bc17161e-727d-4abd-a845-a7eacc08f995}">
|
||||
|
||||
Reference in New Issue
Block a user