Entry type: FAQ, Entry ID: 23751257, Entry date: 08/17/2006

How do you synchronize the data and time between a SIMATIC HMI panel and a SIMOTION controller?

  • Entry
  • Associated product(s)

Date and time synchronization between WinCC flexible and a SIMOTION controller takes place via external tags. The SIMOTION system time is read out cyclically in a SIMOTION program and transferred into WinCC flexible via the configured tags. Synchronization takes place via script functions in both directions.

No. Procedure

Create a SIMOTION project:
The requirement for date and time synchronization is an opened project with a SIMOTION device set up.

Fig. 01


A new device or further devices can be added in the project menu via "Create new device".


Creating/importing a structured program in SIMOTION Scout:
In the project menu, add a new ST program in the "Programs" folder for the device created or added.

Fig. 02


Alternatively, you can also download the Uhr.zip file and import the unpacked file "Uhr.st" via the pop-up menu (right-click on "Programs"). Select "Import external source" and "ST source file" in the pop-up menu.

Fig. 03

3 Create global tags and program:
Global tags are required for data communication between WinCC flexible and the SIMOTION Scout. The system time can be read or set with the aid of the ReadClock and SetClock functions which are created.

Fig. 04


The ReadClock and SetClock functions are RTC-type. When these functions are called, explicit parameters must be transferred to enable the corresponding functions to be executed. The current system time can be read by calling the CDT method.

Identifier Parameter Data type Description
SET Input Boolean Setting the time, default is FALSE
READ Input Boolean Reading the time, default is FALSE
PDT Input DT Value to which the real-time clock should be set, default is DT#0001-01-01-00:00:00. If the value is lower than the default for the real-time clock on the SIMOTION device, the real-time clock is set to its default (e.g. in the case of C320-2: DT#1994-01-01-00:00:00).
CDT Output DT Current system time

With the following function call the system time is read and the current time is transferred via the CDT method:
ReadClock( FALSE, TRUE, DT#2005-01-01-0:0:0 );
ReturnValue = ReadClock.CDT;

The structured program can be tested for syntax errors via the menu selection "ST source file > Accept and compile" or by clicking the following icon on the toolbar.

Accept and compile

4 Define the program call in the runtime system:
The program which is created in or imported into SIMOTION Scout also has to be defined as a background task in the execution system.
  • This is done by clicking on the "Execution System" menu in the project navigation and selecting "Execution levels > Operation levels > BackgroundTask".
  • Select the "Uhr.clock( )" program and add it by clicking the "Add" button.

Fig. 05


You can then compile your SIMOTION configuration and transfer it to the SIMOTION device.

5 Create a SIMOTION connection in WinCC flexible:
The connection with the SIMOTION device must be created in WinCC flexible.

In the project tree, under "Communication > Connections" you create a new connection and select the communication driver "SIMOTION".

Fig. 06


WinCC flexible does not support using the area pointer "Date/Time PLC" for time synchronization with a SIMOTION device because the WinCC flexible "DATE_AND_TIME" data type is different to the SIMOTION data type.

6 Add tags for time synchronization:
In the project tree, under "Communication > Tags" you create all the tags required:
  • Uhr.set
  • Uhr.time_panel
  • Uhr.time_plc 

Fig. 07

7 Create a script:
  • Add a new script named "SetPanelClk".
  • Create six script tags (second, minute, hour, day, month, year) in the Script Editor and, using the appropriate VBS functions (e.g. day, month, etc.), assign the relevant time base via the external tag "Uhr.time_plc".

The system time of the panel can be changed via the (CMD) console with the "Date" and "Time" operating system functions in Windows. The Windows console is called via the script functions "Call" and "StartProgram".

Script - SetPanelClk

Fig. 08

Depending on which location has been selected, dots or dashes must be selected as separator characters in the date details.

Description of the "StartProgram" function
The statements of functions are displayed in red in the Script Editor. The structure of the "StartProgram" function is defined as follows: 

StartProgram( <ProgName>, <Param>, <Layout>, <Wait> )

Parameter Meaning Description
ProgName Name of the program Name and path of the program that is to be started.
Param Program parameters The parameters that you transfer when the program starts, for example a file that opens after program start.
Layout Display Defines how the program window is displayed on the operator panel:
0 (hmiShowNormal) =Normal
1 (hmiShowMinimized) =Minimized
2 (hmiShowMaximized) =Maximized
3 (ShowMinimizedAndInactive) =Minimized and inactive
Wait Wait for the end Defines whether there is to be return to the project after the called program has ended:
0 (hmiNo) = No:
No return to project
1 (hmiYes) = Yes:
Return to project

You can check the script for syntax errors by selecting the toolbar icon (see below) or selecting the "Script" menu (only available when the Script Editor is open).
Check syntax


Create a further script:

  • Create a second script and rename it "Clk_sys_in_var".
  • Use the keyword "Now" to assign the "Uhr.time_panel" tag which has already been created.

The "Now" function delivers the current system date and time for the panel or PC.

Script - Clk_sys_in_var

Fig. 09

9 Create pictures and objects:
Create two buttons, two date-time fields, as well as (optionally) an alarm view with system messages as an alarm event in a new picture.

Fig. 10

The alarm view is merely used as a configuration aid. Among other things, the system message, which must be explicitly configured, appears in this display to indicate whether the SIMOTION device is connected to the panel.
10 Link tags:
Then connect the upper date/time field to the "Uhr.time_plc" tag which you created previously. Select the "Display system time" in the lower date/time field.

Fig. 11

11 Link the script to the buttons:
  • Link the "Clk_sys_in_var" script in the Properties of the "Time Panel > CPU" button under "Events > Click".
  • Also create the "SetBit" function and link the "Uhr.set" tag.
  • Link the second script "SetPanelClk" to the "Time CPU > Panel" button applying the same principle as with the first button.

Fig. 12


You can now transfer the configuration to the panel or start the PC runtime.

Download the structured SIMOTION program:
This file contains the "Uhr.st" file which can be imported into SIMOTION Scout V4.0.

Uhr.zip ( 508 bytes )

Download the sample project:
The packed file contains the SIMOTION-WinCC flexible project which is described in the instructions. The WinCC flexible project requires WinCC flexible 2005 SP1.  

Simotion_WinCC_flexible.zip ( 2837 KB )

Runnability and test environment:
The following table lists the components that have been used to create this entry and verify the functions described.

Components Product and version
PC operating system Microsoft Windows XP SP2
Standard Tools  
Engineering Tools SIMOTION Scout V 4.0
HMI Software WinCC flexible 2005 SP1
HMI system -
SIMOTION device C230

Date synchronization, Time synchronization