Supported platforms: CODESYS 3.5
To set the time, add a system library called SysProcess into the project. The library includes a function SysProcessExecuteCommand that is used to give system commands.
An example code for setting the time:
Code:
// set time to Linux SysProcessExecuteCommand(pszComand:='date -s "2015-05-26 15:30"', pResult:= 0);
// set time from Linux to RTC SysProcessExecuteCommand(pszComand:='hwclock -w', pResult:= 0);
|
|
The following example requires 6107int library 3.1.3.0 or newer and CAA DTUtil library. GetSystemDateAndTime program and example's variables are generated to code template when the following is used:
|
Code template executes 6107int library's GetSystemDateAndTime program automatically which updates time once per second.
Application can access the time variables from G_UI variable list located under CodeTemplate\Globals folder.
Current operating system time can be accessed with variable:
Code: |
|
G_UI.SystemTime
|
Application can set time offset in minutes for UI (default zero, no offset).
Note that application needs to handle saving/restoring value from MRAM if required.
Code: |
|
G_UI.UITimeOffset := 120;
|
Current time with offset applied can be accessed with following variable.
Note: Value is same than G_UI.SystemTime if offset is set to zero.
Code: |
|
G_UI.UITime
|
Both time variables are DT type (DATE_AND_TIME).
See CAA DTUtil library for utility functions (e.g. DTU.DTSplit) to split DT variable into components.
Time updating is enabled by default in the code template.
Error checking can be implemented in application. Note that normally errors should not activate.
Code: |
|
IF G_UI.SystemTimeError <> DTU.ERROR THEN G_UI.SystemTimeEnable := FALSE; (*Handle error*) ; ELSE G_UI.SystemTimeEnable := TRUE; END_IF |
|
|
Code template initializes G_UI.TimeSyncMethod variable depending on the selected 6000/X series unit and functionality.
The variable can be used by application UI to determine if the time offset should be applied.
When GlobE remote management is activated with MultiTool Creator.
Note: GlobE sets current system time to UTC timezone so application should use G_UI.UITime with offset if necessary.
Code: |
|
G_UI.TimeSyncMethod := EPEC_6000INT.TimeSyncTypes.NTP;
|
If GlobE is NOT initialized but the 6000/X series unit has a GPS available.
Note: It is up to the application to synchronize 6000/X series RTC with the GPS.
Code: |
|
G_UI.TimeSyncMethod := EPEC_6000INT.TimeSyncTypes.GPS;
|
If none of the above conditions are met:
Code: |
|
G_UI.TimeSyncMethod := EPEC_6000INT.TimeSyncTypes.Manual;
|
See also
Source file topic000930.htm
Last updated 24-Apr-2025