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

Getting Date and Time with DTU.GetDateAndTime only once

Andreas-K
2018-09-12
2018-09-12
  • Andreas-K - 2018-09-12

    Hi

    I am trying to read out the current time and date and display it in
    the visualization.
    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.

     
  • johnlee - 2018-09-12

    dtu_getdt();
    IF i_count1 > 5 THEN
    dtu_getdt.xExecute := TRUE;
    IF dtu_getdt.xDone THEN
    // ohne Fehler abgeschlossen
    dtDate := dtu_getdt.dtDateAndTime;
    dtu_getdt.xExecute := FALSE;
    i_count1 :=0;
    END_IF

        IF dtu_getdt.xError THEN
        ; // Fehlerbehandlung
        i_count1 :=0;
        dtu_getdt.xExecute := FALSE;
    END_IF
    

    END_IF
    i_count1 := i_count1+1;

     
  • Andreas-K - 2018-09-12

    Thanks a lot !!

     

Log in to post a comment.