How can I show an "S5TIME" type variable from a SIMATIC
controller, separated into hours, minutes, seconds and
milliseconds, with ProTool/Pro?
More information on the subjects of S5 timer and using scripts
can be found in the following articles:
- "Entering a S5TIME variable with Protool/Pro", Entry-ID
- "Entering ProTool/Pro S5 timer values directly", Entry-ID
The controller timestamp is present as a variable of the
"S5TIME" type (e.g. S5T#1H_34M_30S_0MS) in the logic control.
The value of the variable is read from the controller and processed
in Protool/Pro. The time value then displays in hours, minutes,
seconds and milliseconds.
The attached project includes four scripts that read in as input
parameters a variable of the "WORD" type declaring an "S5TIME". The
feedback value of the functions is a variable showing the time
either in hours, minutes, seconds or milliseconds.
These scripts should be used as follows:
- You define 4 variables (e.g. "HH", "MM", "SS" and "MS").
- You link these variables with 4 output fields for displaying
the time in hours, minutes, seconds or milliseconds.
- You define a variable of the "WORD" type (e.g. "S5T"), which
takes the "S5TIME" value from the controller
- Now you define a function in the Properties of the "S5T"
variable, which executes when the value changes. This means you
start the four functions for calculating the time values in hours,
minutes, seconds and milliseconds respectively
How the scripts work:
The system first checks which base time is entered for the
"S5Time" variable (see Entry ID 56243) and sets a multiplier
accordingly. The script then defines the time value in binary coded
decimal format (BCD). This value is multiplied by the previously
defined multiplier. The result is the time value in milliseconds.
This value is the uniform basis taken for the remaining
The hours, minutes, seconds and milliseconds are then determined
according to this millisecond value.
Source text of the script for milliseconds:
Dim base time, total time, buffer, hour, minute, second
If S5TimeIn < 4096 Then
ElseIf S5TimeIn < 8192 Then
Base time =100
ElseIf S5TimeIn < 12288 Then
Base time =1000
Buffer = S5TimeIn And 4095
Total time = Fix(buffer/256)*100
Buffer = Buffer And 255
Total time = Total time+Fix(buffer/16)*10
Buffer = Buffer And 15
Total time = Total time+buffer
Total time = Total time*Base time
Hour = Fix(total time/3600000)
Total time = Total time - Hour*3600000
Minute = Fix(Total time/60000)
Total time = Total time - Minute*60000
Second = Fix(Total time/1000)
Total time = Total time - Second*1000
S5Time_ms = Total time
Downloading the four scripts:
The download contains the four scripts described above. Copy
the " pro___0l.exe" file to a separate directory and then start the
file with a double click.
pro___0l.exe ( 39 KB )
The sample programs are selected solutions to queries about
complex tasks developed by Customer Support. We must also point out
that it is not possible in the current state of the technology to
exclude all errors in software programs under all conditions of
use. The sample programs were prepared according to the best of our
knowledge. However, we cannot accept any liability beyond the
standard guarantee for Class C software in accordance with our
General Terms of Sale for Software Products for Automation and
Object-oriented programming, Time conversion, Time value