ali nawaz
ali nawaz

Reputation: 93

How can I get current time from PLC (Beckhoff)

I am trying to get the current time from the PLC (Beckhoff-cx5130). I have tried "GETSYSTEMTIME", but I am not getting any output. I also tried "NT_GetTime" "TIMESTRUCT" and "T_FILETIME" but showing some compiling error (Could be a library issue). Any suggestion (Example code) regarding this issue will be highly appreciated. Thanks!

Upvotes: 3

Views: 9369

Answers (1)

ali nawaz
ali nawaz

Reputation: 93

I forgot to add the TcUtilities.Lib. After adding it, everything worked. For more info see Beckhoff's InfoSys

Example code

PROGRAM MAIN
VAR
    fbSystemTime : GETSYSTEMTIME;
    timeAsFileTime : T_FILETIME;
    timeAsDT : DT;
END_VAR

fbSystemTime(
    timeLoDW=>timeAsFileTime.dwLowDateTime,
    timeHiDW=>timeAsFileTime.dwHighDateTime 
);

timeAsDT := FILETIME_TO_DT(timeAsFileTime); 

Upvotes: 5

Related Questions