Example: Software clocks (RTC, RTC_EX, RTC_EX2)
Here you can unpack the complete sources: RTCSample.zip
In the following example the three software clocks are synchronized with the local Windows system time every 5 seconds (the local Windows system time is shown in the taskbar).
PROGRAM MAIN
VAR
    fbGetLocalTime  : NT_GetTime;
    bBusy           : BOOL;
    bError          : BOOL;
    nErrID          : UDINT;
    presetTime      : TIMESTRUCT;
    syncTimer       : TON;
    syncTrigger     : F_TRIG;
    bSynchronize    : BOOL;    
    
    fbRTC           : RTC;
    bValid_RTC      : BOOL;
    time_RTC        : DT;
    fbRTC_EX        : RTC_EX;
    bValid_RTCEX    : BOOL;
    time_RTCEX      : DT;
    nMilliseconds   : DWORD;
    fbRTC_EX2       : RTC_EX2;
    bValid_RTCEX2   : BOOL;
    time_RTCEX2     : TIMESTRUCT;
    nMicroseconds   : DWORD;
END_VAR
 
Requirements
Development environment  | Target platform  | PLC libraries to be integrated (category group)  | 
|---|---|---|
TwinCAT v3.1.0  | PC or CX (x86, x64, Arm®)  | Tc2_Utilities (System)  |