Codesys V3.5 Sp17 P3 Raspberry Local Time

rhaeu

Level-2
Beiträge
40
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo zusammen, vielleich hat jemand ja schon mal dieses Problem gehabt.
Wie kann man die Local Time einlesen. Ich habe schon viele verschiedene
Beispiel gefunden, bin aber bei keinem an das Ziel gekommen.
Ich freue mich sehr für Inspirationen.

Grüße
Rainer
 
Zuviel Werbung?
-> Hier kostenlos registrieren
vielen dank,
versuche gerade GetAnd Convert UTCTimeInMs da bekomme ich bei den VAR Result : RTS_IEC_RESULT wobei der Bezeichner nicht definiert ist.
da hänge ich jetzt etwas.
 
Wieder ein Schritt weiter :) Konnte die RTS_IEC_RESULT in deiner LIB finden, Progamm lässt sich jetzt auch vollkommen laden.
Bekomme jedoch online diese Ansicht
 

Anhänge

  • GetTimeInMs.jpg
    GetTimeInMs.jpg
    45,7 KB · Aufrufe: 17
Mit dem Aufruf deines Bausteins passt was nicht!
SysTimeGetMs hat nichts mit der Lokalzeit zu tun und diese lässt sich daraus auch nicht ableiten.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
die funktion soll nur die systemzeit mal als ms ausgeben... nur um zu sehen um irgendwas mal geht :)
aber das gleiche phänomen habe ich auch wenn ich andere zeifunktionen teste.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Probier das mal aus, bei mir geht das ...

Code:
// needs the lib  TimeAndDate
PROGRAM SystemTime
VAR
    iState                    : INT;
    CurrentDateAndTime        : DATE_AND_TIME;
    GetCurrentDateAndTime    : DTU.GetDateAndTime;
    SetCurrentTimeZoneInformation: DTU.SetTimeZoneInformation;
    uiYear                    : UINT;
    uiMonth                    : UINT;
    uiDay                    : UINT;
    uiHour                    : UINT;
    uiMinute                : UINT;
    uiSecond                : UINT;
    uimillSecond            : UINT;
    SetCurrentDateAndTime    : DTU.SetDateAndTime;
    secpulsFB : R_TRIG;
     secpuls   : BOOL;
     olds      : UINT;
     news      : UINT;
     change    : BOOL;
     scount    : DINT;
    Year      : STRING;
    Month     : STRING;
    Day       : STRING;
    Hour      : STRING;
    Minute    : STRING;
    Second    : STRING;
    Date_     : STRING;
    Time_     : STRING;
END_VAR



// This example visualises an analog clock. Timezone informatione are used to get the correct local time.
//


CASE iState OF
    0:  iState:= 1;
          // Set the current timezone. The times to set the clock
         
        SetCurrentTimeZoneInformation(
            xExecute:= TRUE,
            tziInfo:= DTU.GlobalConstants.gc_tziTimeZoneCET);
        IF SetCurrentTimeZoneInformation.xDone THEN
            SetCurrentTimeZoneInformation(xExecute:= FALSE);
            iState:= 1;
        END_IF
        IF SetCurrentTimeZoneInformation.xError THEN
            SetCurrentTimeZoneInformation(xExecute:= FALSE);
            iState:= 32767;
        END_IF
       
    1:  // Fetch the current date and time.
        GetCurrentDateAndTime(
            xExecute:= TRUE);
        IF GetCurrentDateAndTime.xDone THEN
            CurrentDateAndTime:= GetCurrentDateAndTime.dtDateAndTime;
            GetCurrentDateAndTime(xExecute:= FALSE);
            iState:= 2;
        END_IF
        IF GetCurrentDateAndTime.xError THEN
            GetCurrentDateAndTime(xExecute:= FALSE);
            iState:= 32767;
        END_IF
       
    2: // Split the date and time in its parts.  
        IF DTU.DTSplit(
            CurrentDateAndTime,
            ADR(uiYear),
            ADR(uiMonth),
            ADR(uiDay),
            ADR(uiHour),
            ADR(uiMinute),
            ADR(uiSecond)) = DTU.ERROR.NO_ERROR
        THEN
            iState:= 1;
        ELSE
            iState:= 32767;
        END_IF
       
    32767:  (*error*)    ;
            iState:= 1;
END_CASE

Year   := UINT_TO_STRING ( uiYear    );
Month := '';
CASE UINT_TO_INT (uiMonth) OF
 0..9 : Month := CONCAT ( Month , '0' );
        Month := CONCAT ( Month , UINT_TO_STRING ( uiMonth )) ;
ELSE
        Month :=  UINT_TO_STRING ( uiMonth );
END_CASE;
Day := '';
CASE UINT_TO_INT (uiDay) OF
 0..9 : Day := CONCAT ( Day , '0' );
        Day := CONCAT ( Day ,  UINT_TO_STRING ( uiDay ));
ELSE
        Day := UINT_TO_STRING ( uiDay ) ;
END_CASE;
Hour := '';
CASE UINT_TO_INT (uiHour) OF
 0..9 : Hour := CONCAT ( Hour , '0' );
        Hour := CONCAT ( Hour ,  UINT_TO_STRING ( uiHour ) );
ELSE
        Hour :=   UINT_TO_STRING ( uiHour ) ;
END_CASE;
Minute :='';
CASE UINT_TO_INT (uiMinute) OF
 0..9 : Minute := CONCAT ( Minute , '0' );
        Minute := CONCAT ( Minute ,  UINT_TO_STRING ( uiMinute ) );
ELSE
        Minute := UINT_TO_STRING ( uiMinute  );
END_CASE;
Second := '';
CASE UINT_TO_INT (uiSecond) OF
 0..9 : Second := CONCAT ( Second , '0' );
        Second := CONCAT ( Second ,  UINT_TO_STRING ( uiSecond ) );
ELSE
        Second := UINT_TO_STRING ( uiSecond ) ;
END_CASE;



(* für das File Object                                                            *)
(* ----------------------------------- Datestring  ------------------------------ *)
Date_ := '';
Date_ := CONCAT  (Date_, Year);
Date_ := CONCAT  (Date_, '_');
Date_ := CONCAT  (Date_, Month);
Date_ := CONCAT  (Date_, '_');
Date_ := CONCAT  (Date_, Day);
(* ----------------------------------- Timestring  ------------------------------ *)
Time_ := '';
Time_ := CONCAT  (Time_, ' ');
Time_ := CONCAT  (Time_, Hour);
Time_ := CONCAT  (Time_, ':');
Time_ := CONCAT  (Time_, Minute);
Time_ := CONCAT  (Time_, ':');
Time_ := CONCAT  (Time_, Second);







news := uiSecond;
IF ( olds <> news )
THEN
  olds   := news;
  change := TRUE;
ELSE
  change := FALSE;
END_IF

secpulsFB(CLK:= change , Q=> secpuls );

IF secpuls
THEN
 scount := scount + 1;
ELSE
 ;
END_IF
 
Hey, das ist ja super das Funktioniert, das müsste ich ja jetzt in einen Funktion bringen können.
Vielen Dank !!!!
Ich hoffe dies wird noch vielen nutzen !!
 
Zurück
Oben