asy81 - 2018-10-03

Hello, I created a post before but clearly I made a mistake about CoDeSys version which is currently running v3.5(not v2.3). So, please accept my apologies about posting same issue twice.

I am not so familiar with PLC programs and I decided to start learning CoDeSys with an excellent youtube tutorial. But the very first problem is he is using Beckhoff, so I can not use some libraries and function blocks as he did.
https://www.youtube.com/watch?v=BMrVOQJJhkg&index=11&list=PLE1CU6EebvTCJCMIUOSWgMseMaW-2k5zH

While I am trying to get real time values, I used the function block RTCLK.GetDateAndTime. But my problem is I could not figured out a way to get a real time value at second time. I even tried to use add a second function block for solving that but it did not work either. So, what am I missing and what should I do?
I am adding the project and code below so you can check it.

FUNCTION_BLOCK FB_PIZZA
VAR_INPUT
   
   bLoadPizza : BOOL;
   bRemovePizza : BOOL;
   
   
END_VAR
VAR_OUTPUT
   
   bBuzzer : BOOL;
   sStateDesc : STRING;
   iTotalPizzasCooked : UDINT;
   fbPizzaTimer : TON;
END_VAR
VAR
   
   iState : DINT;
   iLastState : DINT;
   
   arrStateDescHistory : ARRAY [1..100] OF STRING;
   
   stPizzaOnDeck: ST_PIZZA;
   stPizzaInOven: ST_PIZZA;
   stPizzaAtOut: ST_PIZZA;
   fbLoad_RTRIG: R_TRIG;
   fbRemove_RTRIG: R_TRIG;
   
   arrPizzaHistory: ARRAY[0..100] OF ST_PIZZA;
   fbNT_GetTime: RTCLK.GetDateAndTime;
   dtCurrentTime : DT;
      
END_VAR
VAR CONSTANT
   standard : RTCLK.SetDateAndTime;
   stNULL_PIZZA : ST_PIZZA;
END_VAR
//Structure of ST_PIZZA
TYPE ST_PIZZA :
STRUCT
   
   bExist : BOOL;
   dtTimeEnteredOven : DT;
   dtTimeExitedOven : DT;
   tTimeInOven : TIME;
   eType : E_PIZZA_TYPES;
END_STRUCT
END_TYPE
//We can press the button 'Load Pizza' anytime we want and the 
//first function block(fbNT_GetTime) counts and measure the value how much time after we did hit the button..
//It gives the true clock value even there exist a time-difference!
fbNT_GetTime();
dtCurrentTime := fbNT_GetTime.dtDateAndTime ;
IF stPizzaOnDeck.bExist AND NOT stPizzaInOven.bExist THEN
   stPizzaInOven := stPizzaOnDeck;
   stPizzaOnDeck := stNULL_PIZZA;
END_IF
fbLoad_RTRIG(CLK:= bLoadPizza);
IF fbLoad_RTRIG.Q THEN
   //bLoadPizza := FALSE;
   stPizzaOnDeck.bExist := TRUE;
   stPizzaOnDeck.eType := 0;
END_IF
fbRemove_RTRIG(CLK:= bRemovePizza);
IF fbRemove_RTRIG.Q THEN
   //bRemovePizza := FALSE;
   F_FIFO_WRITE(cbData := SIZEOF(stPizzaAtOut), pData := ADR(stPizzaAtOut), cbBuffer := SIZEOF(arrPizzaHistory), 
      pBuffer := ADR(arrPizzaHistory));
   stPizzaAtOut := stNULL_PIZZA;
END_IF
CASE iState OF
   0:
      sStateDesc := 'Waiting for pizza!';
      IF stPizzaInOven.bExist THEN
         iState := 10;
      END_IF
   10:
      sStateDesc := 'Baking pizza right now!';
      fbPizzaTimer(IN := TRUE, PT:=T#5S);
      fbNT_GetTime.xExecute := TRUE;
      stPizzaInOven.dtTimeEnteredOven := dtCurrentTime;
      
      IF fbPizzaTimer.Q THEN
         fbPizzaTimer(IN := FALSE);
         
         fbNT_GetTime.xExecute := FALSE;
         
         iState := 20;
      END_IF
   20:
      sStateDesc := 'PIZZA BURNING!!';
      IF NOT stPizzaAtOut.bExist THEN
         fbNT_GetTime.xExecute := TRUE;
         stPizzaAtOut.dtTimeExitedOven := dtCurrentTime;
         
         stPizzaAtOut := stPizzaInOven;
         stPizzaInOven := stNULL_PIZZA;
         
         bBuzzer := FALSE;
         iState := 30;
      ELSE
         bBuzzer := TRUE;
      END_IF
   30:
      iTotalPizzasCooked := iTotalPizzasCooked + 1;
      fbNT_GetTime.xExecute := FALSE;
      iState := 0;
ELSE
   sStateDesc := 'Invalid State!';   
END_CASE
//Start state history
IF iLastState <> iState AND(iState<>30) THEN
   F_FIFO_WRITE(cbData := SIZEOF(sStateDesc), pData := ADR(sStateDesc), cbBuffer :=SIZEOF(arrStateDescHistory), pBuffer := ADR(arrStateDescHistory));
   //Reset for next time.
   iLastState := iState;   
END_IF

PizzaOven RTC (2).project [190.93 KiB]