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
Hi
I got the same issue, I only get the time once.
And here's my code, the counter is increased every 500ms,
so every 3s I want to read out the actual time and display
it at the visualization. The code runs in cyclic task with 500ms cycle time.
For some reasons, I only get in the first cycle a date and time.
The output dtu_getdt.xDone will not reset even
if dtu_getdt.Execute is set back from TRUE to FALSE.
According to the library description the outputs should be reseted upon a
falling edge. I'm not sure whether this is the reason for executing it only once or not.
Using Codesys 3.5 SP11 Patch4+
RaspberryPi Runtime
VAR
dtu_getdt : DTU.GetDateAndTime;
dtDate : DATE_AND_TIME;
END_VAR
Codepart:
IF i_count1 > 5 THEN
dtu_getdt.xExecute := TRUE;
dtu_getdt();
IF dtu_getdt.xError THEN
; // Fehlerbehandlung
END_IF
IF dtu_getdt.xDone THEN
// ohne Fehler abgeschlossen
dtDate := dtu_getdt.dtDateAndTime;
dtu_getdt.xExecute := FALSE;
END_IF
i_count1 :=0;
END_IF
i_count1 := i_count1+1;
Thanks for any comments. I'm not a very experienced user.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
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.project [190.93 KiB]
Hi
I got the same issue, I only get the time once.
And here's my code, the counter is increased every 500ms,
so every 3s I want to read out the actual time and display
it at the visualization. The code runs in cyclic task with 500ms cycle time.
For some reasons, I only get in the first cycle a date and time.
The output dtu_getdt.xDone will not reset even
if dtu_getdt.Execute is set back from TRUE to FALSE.
According to the library description the outputs should be reseted upon a
falling edge. I'm not sure whether this is the reason for executing it only once or not.
Using Codesys 3.5 SP11 Patch4+
RaspberryPi Runtime
VAR
dtu_getdt : DTU.GetDateAndTime;
dtDate : DATE_AND_TIME;
END_VAR
Codepart:
IF i_count1 > 5 THEN
dtu_getdt.xExecute := TRUE;
dtu_getdt();
IF dtu_getdt.xError THEN
; // Fehlerbehandlung
END_IF
IF dtu_getdt.xDone THEN
// ohne Fehler abgeschlossen
dtDate := dtu_getdt.dtDateAndTime;
dtu_getdt.xExecute := FALSE;
END_IF
i_count1 :=0;
END_IF
i_count1 := i_count1+1;
Thanks for any comments. I'm not a very experienced user.
You have to take out dtu_getdt() outside "icount if".
For the fb icount, execute is never false, because when you set it to false you dont call anymore dtu_getdt since execute be true.
Be carefull with fb inside ifs, fb are normally though to call it all cycles!
Sent from my Moto G (5S) Plus using Tapatalk