Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

"GetDateAndTime" => is there something "faster" exististing?

Wicked
2012-12-11
2021-12-26
  • Wicked - 2012-12-11

    Hello community

    Do you know whether there is in CDS3 function to get current date and time like it is in CDS2 "SysRtcGetTime" ?
    I was able to find out just library DTU which has "GetDateAndTime" function block.
    Unfortunately that FB needs some time to process and makes things little complicated … .
    Is there something faster existing?

    Any help is appreciated.

    Thank you in advance.

    Regards,

    W.

     
  • Anonymous - 2013-04-03

    Originally created by: Eckhard

    Hello Wicked

    In my system (WAGO 750-) is also a second functionblock to read the time: CurTimeEx in the lib: SysLibTime.lib
    This function is (in my case) about six times faster.
    To get the same data type you have to create a DT# variable.

    Here the program which is translating the structure of CurTimeEx to DT#
    The declaration part:

    PROGRAM ReadClock_CurTimeEx
    VAR
    Realtime_extended:( The realtime as a complex variable )
    Realtime_64:SysTime64;
    TimeDate:( Structure with year, month, etc. )
    Helptime: ( Helper with is collecting the time)
    dtActualTime: DT;
    END_VAR

    The code part (in structured text):

    Realtime_extended (SystemTime:= Realtime_64 , TimeDate:= TimeDate );
    Helptime := CONCAT ( 'DT#',UINT_TO_STRING (TimeDate.Year));( DT#2009 )
    Helptime := CONCAT ( Helptime ,'-');( DT#2009- )
    Helptime := CONCAT ( Helptime ,UINT_TO_STRING (TimeDate.Month));( DT#2009-10 )
    Helptime := CONCAT ( Helptime ,'-');( DT#2009-10- )
    Helptime := CONCAT ( Helptime ,UINT_TO_STRING (TimeDate.Day));( DT#2009-10-30 )
    Helptime := CONCAT ( Helptime ,'-');( DT#2009-10-30- )
    Helptime := CONCAT ( Helptime ,UINT_TO_STRING (TimeDate.Hour)); ( DT#2009-10-30-23 )
    Helptime := CONCAT ( Helptime ,':'); ( DT#2009-10-30-23: )
    Helptime := CONCAT ( Helptime ,UINT_TO_STRING (TimeDate.Minute)); ( DT#2009-10-30-23:56 )
    Helptime := CONCAT ( Helptime ,':'); ( DT#2009-10-30-23:56: )
    Helptime := CONCAT ( Helptime ,UINT_TO_STRING (TimeDate.Second)); ( DT#2009-10-30-23:56:30 )
    dtActualTime := STRING_TO_DT (Helptime);

    Hope this helps, Eckhard

     
  • Wicked - 2013-04-09

    Thank you!

     
  • george13 - 2021-12-26

    Hi all, quite an old topic to resurrect, but I have a very related question.

    I would like to ask for an advice how to measure the speed or CPU load of the SysRtcGetTime() function. At my WAGO 750-880 PLC I am running a cyclic task to execute SysRtcGetTime() to read the clock at a given interval. The intention is to reduce CPU load - my assumption is that I do not need to read the clock at every cycle, as well as if the function was executed in the main program at every cycle it would impose higher CPU load? Is the second statement valid? I thought if I could measure the CPU load I could validate it.

    I would apperciate any best practices on using SysRtcGetTime() function to read time.

     

Log in to post a comment.