I'm having a problem with structured text in Codesys V3.5 SP9 Patch 5. What I want to do is to be able to use a timer within a function created by me, which is called in a POU. I've done the same without using function by putting timer directly into POU and it is working.
My function declaration:
FUNCTION AssignDOORStatus : USINT
VAR_INPUT
DDUC_ComSta_Dcux_x: BOOL; //No communication
DDUC_DCUxEmHdler_x: BOOL; //Emergency handler
END_VAR
VAR
Timer: TP; //Timer to do intermittence between current doors status and emergency handler
CurrentDoorStatus: USINT;
TONProcessTime: TIME := T#1S; //TONProcesTime
END_VAR
My function code:
IF DDUC_ComSta_Dcux_x THEN
CurrentDoorStatus := 0;
ELSE
CurrentDoorStatus := 1;
END_IF
IF DDUC_DCUxEmHdler_x THEN
Timer(IN := NOT Timer.Q, PT := TONProcessTime); //Timer starts
Timer();
IF Timer.Q THEN //When TONProcessTime has gone by
IF AssignDOORStatus <> CurrentDoorStatus THEN
AssignDOORStatus := CurrentDoorStatus;
ELSE AssignDOORStatus := 10;
END_IF
END_IF
ELSE
AssignDOORStatus := CurrentDoorStatus;
END_IF
My code in POU main:
testdoor := AssignDOORStatus(DDUC_ComSta_Dcu1_S1_T,DDUC_DCU1EmHdler_S1_T);
This code is used to assign to "AssignDOORStatus" 0 or 1 depending on variable "DDUC_ComSta_Dcux_x " and then, when "DDUC_DCUxEmHdler_x " is true, it flips "AssignDOORStatus" value from "0 or 1" to 10, using timer.
I have to call in POU many times this function.
Thanks in advance!