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.
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_BLOCKFB_PIZZAVAR_INPUT
 Â
  bLoadPizza : BOOL;
  bRemovePizza : BOOL;
 Â
 Â
END_VARVAR_OUTPUT
 Â
  bBuzzer : BOOL;
  sStateDesc : STRING;
  iTotalPizzasCooked : UDINT;
  fbPizzaTimer : TON;END_VARVAR
 Â
  iState : DINT;
  iLastState : DINT;
 Â
  arrStateDescHistory : ARRAY [1..100] OFSTRING;
 Â
  stPizzaOnDeck: ST_PIZZA;
  stPizzaInOven: ST_PIZZA;
  stPizzaAtOut: ST_PIZZA;
  fbLoad_RTRIG: R_TRIG;
  fbRemove_RTRIG: R_TRIG;
 Â
  arrPizzaHistory: ARRAY[0..100] OFST_PIZZA;
  fbNT_GetTime: RTCLK.GetDateAndTime;
  dtCurrentTime : DT;
  Â
END_VARVARCONSTANT
  standard : RTCLK.SetDateAndTime;
  stNULL_PIZZA : ST_PIZZA;END_VAR//StructureofST_PIZZATYPEST_PIZZA :
STRUCT
 Â
  bExist : BOOL;
  dtTimeEnteredOven : DT;
  dtTimeExitedOven : DT;
  tTimeInOven : TIME;
  eType : E_PIZZA_TYPES;END_STRUCTEND_TYPE//Wecanpressthebutton'Load Pizza'anytimewewantandthe//firstfunctionblock(fbNT_GetTime)countsandmeasurethevaluehowmuchtimeafterwedidhitthebutton..
//Itgivesthetrueclockvalueeventhereexistatime-difference!fbNT_GetTime();dtCurrentTime :=fbNT_GetTime.dtDateAndTime;IFstPizzaOnDeck.bExistANDNOTstPizzaInOven.bExistTHEN
  stPizzaInOven :=stPizzaOnDeck;
  stPizzaOnDeck :=stNULL_PIZZA;END_IFfbLoad_RTRIG(CLK:=bLoadPizza);IFfbLoad_RTRIG.QTHEN
  //bLoadPizza :=FALSE;
  stPizzaOnDeck.bExist :=TRUE;
  stPizzaOnDeck.eType :=0;END_IFfbRemove_RTRIG(CLK:=bRemovePizza);IFfbRemove_RTRIG.QTHEN
  //bRemovePizza :=FALSE;
  F_FIFO_WRITE(cbData :=SIZEOF(stPizzaAtOut), pData :=ADR(stPizzaAtOut), cbBuffer :=SIZEOF(arrPizzaHistory),
   pBuffer :=ADR(arrPizzaHistory));
  stPizzaAtOut :=stNULL_PIZZA;END_IFCASEiStateOF
  0:
   sStateDesc :='Waiting for pizza!';
   IFstPizzaInOven.bExistTHEN
     iState :=10;
   END_IF
  10:
   sStateDesc :='Baking pizza right now!';
   fbPizzaTimer(IN :=TRUE, PT:=T#5S);
   fbNT_GetTime.xExecute :=TRUE;
   stPizzaInOven.dtTimeEnteredOven :=dtCurrentTime;
  Â
   IFfbPizzaTimer.QTHEN
     fbPizzaTimer(IN :=FALSE);
    Â
     fbNT_GetTime.xExecute :=FALSE;
    Â
     iState :=20;
   END_IF
  20:
   sStateDesc :='PIZZA BURNING!!';
   IFNOTstPizzaAtOut.bExistTHEN
     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//StartstatehistoryIFiLastState<>iStateAND(iState<>30)THEN
  F_FIFO_WRITE(cbData :=SIZEOF(sStateDesc), pData :=ADR(sStateDesc), cbBuffer :=SIZEOF(arrStateDescHistory), pBuffer :=ADR(arrStateDescHistory));
  //Resetfornexttime.
  iLastState :=iState;  END_IF
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.
PizzaOven RTC (2).project [190.93 KiB]