Getting crazy with SysRtcGetTime

GUERILLON
2010-01-14
2010-02-11
  • GUERILLON - 2010-01-14

    Hi all,

    I'm a new user of CoDeSys and I try it on my PC before to use it on "real" on a PMA system (KS128).'m in simulation mode.

    I'm trying to get the current date and time and it's not realy succesful

    dummy:=FALSE;
    test := SysRtcGetTime(dummy) ;
    

    and I get for test the value DT#1970-01-01-00:00 in spy mode

    Please help

    Thanks

     
  • Nitrozin - 2010-01-15

    Hi,

    the value is correct. what you see is the default value.

    the SysRtcGetTime function won't work in simulaton mode,

    because you have no access to the controllers realtime-clock.

    greets Volker

     
  • GUERILLON - 2010-01-15

    Thanks NITROZIN,

    The new question is How can I have the current date and time in simulation mode ? I need it to make the test of my FB.

    Thanks

     
  • Nitrozin - 2010-01-15

    hi,

    it's really easy.

    first create a variable with DT format.

    VAR
    MY_DT : DT; (* testvariable *)
    END_VAR
    

    use this variable instead of the GetSysRtc-output for testing the input of your FB.

    run your program and make a doubleclick on the variable you want to change (My_DT).

    you get a window for changing the value.

    greets Volker

     
  • GUERILLON - 2010-01-15

    Thanks again for your answer but the idea is to have the current time and to see it change. Is there a simple solution in simulation mode or is there a solution to test without having the material (use my computer as a platform)

    Thanks

     
  • Nitrozin - 2010-01-15

    hi again,

    you can use the external librarys only with the target system.

    for testing the date & time functions use the RTC FB from the standard.lib

    VAR
    My_DTΒ  Β : DT;Β  Β (* testvar *)
    MyRtcSimΒ  Β : RTC; (* instance *)
    END_VAR
    MyRtcSim(EN := TRUE, PDT := DT#2010-01-15-07:10);
    My_DT := MyRtcSim.CDT;
    

    this should work

    greets Volker

     
  • GUERILLON - 2010-01-15

    Thanks a lot for your help

     
  • Anonymous - 2010-02-11

    Originally created by: crthomas1234

    The RTC libraries can access the RTC on your PC.

    I like to use the internal function: SysTimeGetDate found in the SysTime.lib.

    This function returns a structure of type SYSTIMEDATE. Inside this structure, all of the sub-elements such as year, day, hour, minute, second, etc are already broken out for you to access so you do not have to parse the time string that is returned by some of the other blocks.

    The SysRtcGetTime() returns a time that is referenced from an initial input time setting. The default value for this initial time is the 1970-01-01-00:00.

     

Log in to post a comment.