Files
BasicComponents/PLC/POUs/Unittests/ValveTests/FB_ValveTestHMI.TcPOU
2025-11-13 09:19:39 +01:00

282 lines
8.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<POU Name="FB_ValveTestHMI" Id="{78a34e73-74e3-480e-93ae-396774638baf}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FB_ValveTestHMI EXTENDS TcUnit.FB_TestSuite
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
// valve instance for Open/Close-Test
_fbValveOC : FB_Valve('');
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TestManualButtonRelease();
TestManualButtonModeChange();
TestManualModeButtonOpenClose();
TestManualModeOpenRelease();]]></ST>
</Implementation>
<Method Name="TestManualButtonModeChange" Id="{4fa4418c-a1e9-4136-b912-1dfb82f3064a}">
<Declaration><![CDATA[{warning disable C0394}
METHOD TestManualButtonModeChange
VAR
// valve instance
_fbValve : FB_Valve('');
// valve hmi data
_stHMIValve : ST_HMI_VALVE_DATA;
// valve config
_stValveConfig : ST_ValveConfig;
// valve interlocks
_wInterlocks : T_INTERLOCK;
_wInterlocksUsed : T_INTERLOCK;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TestManualButtonModeChange');
// set manual request button on HMI and call valve block
_stHMIValve.stManualButton.xRequest := TRUE;
_fbValve(
xReleaseManualMode:= TRUE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= _stValveConfig,
xOpenValve=> ,
xCloseValve=> );
// Valve should now be in manual mode and xRequest should have been reset
AssertTrue(Condition := _fbValve.IsInManualMode, Message := 'Valve did not change to manual mode');
AssertFalse(Condition := _stHMIValve.stManualButton.xRequest, Message := 'Valve did not reset the manual mode button request');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="TestManualButtonRelease" Id="{6966094d-e9b6-4f8b-a399-9dea4a3eee19}">
<Declaration><![CDATA[{warning disable C0394}
METHOD TestManualButtonRelease
VAR
// valve instance
_fbValve : FB_Valve('');
// valve hmi data
_stHMIValve : ST_HMI_VALVE_DATA;
// valve config
_stValveConfig : ST_ValveConfig;
// valve interlocks
_wInterlocks : T_INTERLOCK;
_wInterlocksUsed : T_INTERLOCK;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TestManualButtonRelease');
// Test no release for HMI mode change
_fbValve(
xReleaseManualMode:= FALSE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= _stValveConfig,
xOpenValve=> ,
xCloseValve=> );
AssertFalse(Condition := _stHMIValve.stManualButton.xRelease, Message := 'Manual mode button was released but should not have been');
// Test release for HMI mode change
_fbValve(
xReleaseManualMode:= TRUE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= ,
xOpenValve=> ,
xCloseValve=> );
AssertTrue(Condition := _stHMIValve.stManualButton.xRelease, Message := 'Manual mode button was not released but should have been');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="TestManualModeButtonOpenClose" Id="{5447550c-d5f0-42c9-bcfd-b2ef662685c8}">
<Declaration><![CDATA[{warning disable C0394}
METHOD TestManualModeButtonOpenClose
VAR
// valve hmi data
_stHMIValve : ST_HMI_VALVE_DATA;
// valve config
_stValveConfig : ST_ValveConfig;
// valve interlocks
_wInterlocks : T_INTERLOCK;
_wInterlocksUsed : T_INTERLOCK;
// hmi button feedback
_eExpectedOpenButtonFeedback : E_HMI_BUTTON_FEEDBACK;
_eExpectedCloseButtonFeedback : E_HMI_BUTTON_FEEDBACK;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TestManualModeButtonOpenClose');
// set manual request button on HMI and call valve block
_stHMIValve.stManualButton.xRequest := TRUE;
_fbValveOC(
xReleaseManualMode:= TRUE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= _stValveConfig,
xOpenValve=> ,
xCloseValve=> );
// Valve should now be in manual mode
AssertTrue(Condition := _fbValveOC.IsInManualMode, Message := 'Valve did not change to manual mode pre test');
// Request open from HMI and call valve block
_stHMIValve.stOpenButton.xRequest := TRUE;
_fbValveOC(
xReleaseManualMode:= TRUE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= ,
xOpenValve=> ,
xCloseValve=> );
// test for valve state and HMI feedback
AssertTrue(Condition := _fbValveOC.xOpenValve, Message := 'Valve did not open as requested by hmi button');
AssertFalse(Condition := _stHMIValve.stOpenButton.xRequest, Message := 'Valve did not reset open request');
_eExpectedOpenButtonFeedback := E_HMI_BUTTON_FEEDBACK.ACTIVE;
_eExpectedCloseButtonFeedback := E_HMI_BUTTON_FEEDBACK.NONE;
AssertEquals(Expected := _eExpectedOpenButtonFeedback, Actual := _stHMIValve.stOpenButton.eFeedback, Message := 'Valve did not send correct open button feedback signal while open');
AssertEquals(Expected := _eExpectedCloseButtonFeedback, Actual := _stHMIValve.stCloseButton.eFeedback, Message := 'Valve did not send correct close button feedback signal while open');
// Request close from HMI and call valve block
_stHMIValve.stCloseButton.xRequest := TRUE;
_fbValveOC(
xReleaseManualMode:= TRUE,
wProcessINTLK:= _wInterlocks,
wProcessINTLKUsed:= _wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= ,
xOpenValve=> ,
xCloseValve=> );
// test for valve state and HMI feedback
AssertTrue(Condition := _fbValveOC.xCloseValve, Message := 'Valve did not close as requested by hmi button');
AssertFalse(Condition := _stHMIValve.stCloseButton.xRequest, Message := 'Valve did not reset close request');
_eExpectedOpenButtonFeedback := E_HMI_BUTTON_FEEDBACK.NONE;
_eExpectedCloseButtonFeedback := E_HMI_BUTTON_FEEDBACK.ACTIVE;
AssertEquals(Expected := _eExpectedCloseButtonFeedback, Actual := _stHMIValve.stCloseButton.eFeedback, Message := 'Valve did not send correct close button feedback signal while closed');
AssertEquals(Expected := _eExpectedOpenButtonFeedback, Actual := _stHMIValve.stOpenButton.eFeedback, Message := 'Valve did not send correct open button feedback signal while closed');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="TestManualModeOpenRelease" Id="{7b7870a1-a0b3-45c8-af76-55d8712c17bf}">
<Declaration><![CDATA[{warning disable C0394}
METHOD TestManualModeOpenRelease
VAR
// valve instance
_fbValve : FB_Valve('');
// valve hmi data
_stHMIValve : ST_HMI_VALVE_DATA;
// valve config
_stValveConfig : ST_ValveConfig;
END_VAR
VAR CONSTANT
// valve interlocks
wInterlocks : T_INTERLOCK := 0;
wInterlocksUsed : T_INTERLOCK := 1;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TestManualModeOpenRelease');
// set manual request button on HMI and call valve block
_stHMIValve.stManualButton.xRequest := TRUE;
_fbValve(
xReleaseManualMode:= TRUE,
wProcessINTLK:= wInterlocks,
wProcessINTLKUsed:= wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= _stValveConfig,
xOpenValve=> ,
xCloseValve=> );
// Valve should now be in manual mode
AssertTrue(Condition := _fbValve.IsInManualMode, Message := 'Valve did not change to manual mode pre test');
// Valve should not realease open button with active interlock
AssertFalse(Condition := _stHMIValve.stOpenButton.xRelease, Message := 'Valve did release open button but should not');
// Test if request is denied by valve with active interlocks
_stHMIValve.stOpenButton.xRequest := TRUE;
_fbValve(
xReleaseManualMode:= TRUE,
wProcessINTLK:= wInterlocks,
wProcessINTLKUsed:= wInterlocksUsed,
stHMIInterface:= _stHMIValve,
xError=> ,
xOpenFeedback:= ,
xCloseFeedback:= ,
xReleaseErrors:= ,
xConfirmAlarms:= ,
stValveConfig:= ,
xOpenValve=> ,
xCloseValve=> );
AssertFalse(Condition := _fbValve.xOpenValve, Message := 'Valve did not block manual open command with active interlock');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
</POU>
</TcPlcObject>