Overview
The Siemens PCS7 CountOH block (Operating Hours Counter) from the Advanced Process Library (APL) and the related Industry Library aggregates equipment runtime as a DWORD (32-bit unsigned integer) in seconds at the TotalTime output. WinCC does not interpret this raw numeric value as a time of day; the operator screen, the trend control, and the tag logging archive must each perform an explicit conversion from total seconds to hh:mm:ss (or to hhhh:mm:ss for runtimes that exceed 24 hours).
This reference documents three end-to-end implementation paths. The first uses a C script inside a WinCC V7.x I/O field. The second packages the same conversion into a WinCC Global Script action so that the formatted string can be reused across many pictures. The third uses the WinCC Unified V21 native output format property on a screen object, which removes the script entirely when the tag type matches the pattern consumer. Tag logging configuration, trend display, migration notes, and a verification procedure are documented at the level a commissioning engineer needs in the field.
CountOH Block Technical Reference
The CountOH block is delivered as part of the PCS7 Advanced Process Library (APL) Master Data Library and is also surfaced as aggr08 in the Industry Library. Both blocks implement the same functional behaviour: they count the on-time of a binary signal and expose cumulative totals to the HMI.
| I/O | Meaning | Data Type |
|---|---|---|
| MSG_ACK | Acknowledgement of messages | BOOL |
| RESET | Operator reset of totals | BOOL |
| TotalTime | Cumulative on-time | DWORD (seconds) |
| OperatingHours | Operating hours (TotalTime/3600) | DWORD |
| StartCount | Number of starts | DWORD |
| LastOperatingHours | Hours since last reset | DWORD |
| StatusWord | Block status flags | WORD |
The TotalTime output is the canonical value to display because it preserves full resolution; OperatingHours is integer-truncated and loses sub-hour information.
TotalTime Output Format and Range
The TotalTime output is a 32-bit unsigned integer holding the cumulative on-time of the monitored equipment in seconds since the last operator reset.
| Property | Value |
|---|---|
| Output name | TotalTime |
| Data type | DWORD (32-bit unsigned integer) |
| Unit | Seconds |
| Range | 0 to 4,294,967,295 seconds |
| Range expressed | 0 to approximately 136.19 years continuous run |
| Resolution | 1 second |
| Reset | Operator reset via faceplate button or AS program logic |
| Retentivity | Instance DB must be marked retentive to survive AS restart |
Example conversion (from the source thread): the value 16#11B8 hex equals 10#4536 decimal seconds, which decomposes as follows:
- Hours:
floor(4536 / 3600)= 1 - Minutes:
floor((4536 % 3600) / 60)=floor(936 / 60)= 15 - Seconds:
4536 % 60= 36 - Display string:
01:15:36
This is the canonical pattern that all three WinCC implementation paths below reproduce.
Conversion Mathematics: Seconds to hh:mm:ss
The general conversion from total seconds to hours, minutes, and seconds uses integer division and modulo operations. The two equivalent forms are shown below.
// Form A - using nested modulo hours = floor(totalSeconds / 3600) minutes = floor((totalSeconds % 3600) / 60) seconds = totalSeconds % 60 // Form B - using subtraction (avoids second modulo) hours = floor(totalSeconds / 3600) minutes = floor((totalSeconds - hours * 3600) / 60) seconds = totalSeconds - hours * 3600 - minutes * 60
Worked examples covering the common edge cases that surface during commissioning:
| TotalTime (s) | Hex | hours | minutes | seconds | Formatted |
|---|---|---|---|---|---|
| 0 | 16#00000000 | 0 | 0 | 0 | 00:00:00 |
| 59 | 16#0000003B | 0 | 0 | 59 | 00:00:59 |
| 60 | 16#0000003C | 0 | 1 | 0 | 00:01:00 |
| 3599 | 16#00000E0F | 0 | 59 | 59 | 00:59:59 |
| 3600 | 16#00000E10 | 1 | 0 | 0 | 01:00:00 |
| 4536 | 16#000011B8 | 1 | 15 | 36 | 01:15:36 |
| 86399 | 16#0001517F | 23 | 59 | 59 | 23:59:59 |
| 86400 | 16#00015180 | 24 | 0 | 0 | 24:00:00 |
| 604800 | 16#00093A80 | 168 | 0 | 0 | 168:00:00 |
For values that exceed 24 hours the standard hh:mm:ss display counts past 24 without wrapping. Confirm with operations whether a day boundary wrap is preferred (display jumps to 00:00:00 at the 24-hour transition) or whether continuous counting is preferred (display reads 25:00:00, 100:00:00, and so on). Process plants almost universally prefer continuous counting for runtime to avoid misleading operators.
WinCC V7.x: I/O Field with C Script
Bind an I/O field to the TotalTime tag and attach a C script to the Output event. The script executes when the picture is loaded and whenever the tag value changes.
Step-by-Step
- Open the WinCC Graphics Designer and add an
I/O Fieldto the process picture. - In the I/O field properties, set the field type to Output only.
- Assign the tag
CountOH_TotalTimein theOutput Valueproperty. - Right-click the I/O field and select Properties > Events > Output Value > C Action.
- Paste the C script below, save, and compile via right-click > Compile.
- Set the I/O field
Output Formatproperty toStringand clear theData Formatfield. - Resize the field width to at least 8 characters so the formatted string renders without truncation.
// C script - I/O field Output event (WinCC V7.x)
DWORD totalTime = GetTagDWord("CountOH_TotalTime");
DWORD hours = totalTime / 3600;
DWORD minutes = (totalTime % 3600) / 60;
DWORD seconds = totalTime % 60;
char buffer[16];
sprintf(buffer, "%02lu:%02lu:%02lu", hours, minutes, seconds);
SetText(lpszPictureName, lpszObjectName, buffer);
return 0;
Set the I/O field Output Format property to String and clear the Data Format field. The field then displays the runtime as 01:15:36 for the example value of 4536 seconds.
GetTagDWord, SetText, and sprintf functions are part of the default APL C runtime and require no additional include path changes.
WinCC V7.x: Global Script Action for Re-use
When the formatted runtime must appear in many pictures, replicate the conversion in a WinCC Global Script C action that triggers on the underlying tag change. A single action drives a formatted string tag, and every screen binds its I/O field to that string tag. This centralises the logic and prevents drift across picture revisions.
Configuration Steps
- In WinCC Tag Management, create a new internal text tag
CountOH_TotalTime_Strwith length 16 characters. - Open Global Script and create a new C action.
- Configure the trigger: select Trigger > Tag Trigger and add
CountOH_TotalTime. Do not use the standard 1-second cycle trigger because it consumes unnecessary runtime and can introduce jitter if the tag is updated at a different cadence. - Insert the conversion code:
// Global Script C action (WinCC V7.x)
DWORD totalTime = GetTagDWord("CountOH_TotalTime");
DWORD hours = totalTime / 3600;
DWORD minutes = (totalTime % 3600) / 60;
DWORD seconds = totalTime % 60;
char buffer[16];
sprintf(buffer, "%02lu:%02lu:%02lu", hours, minutes, seconds);
SetTagChar("CountOH_TotalTime_Str", buffer);
return 0;
- Compile and activate the action.
- Bind each I/O field on the operator screens to
CountOH_TotalTime_Strwith output formatString.
For multi-equipment deployments, suffix the string tag and the action with the equipment number (for example CountOH_TotalTime_Str_P01) and generate the action per equipment via the Dynamic Wizard or by copy-and-modify.
WinCC V7.x: Visual Basic Script Equivalent
Some existing PCS7 projects use VB scripts rather than C actions because legacy templates predate the C script adoption. The functional equivalent is shown below.
' VB script - I/O field Output event (WinCC V7.x)
Dim totalTime, hours, minutes, seconds, txt
totalTime = HMIRuntime.Tags("CountOH_TotalTime").Read
hours = Int(totalTime / 3600)
minutes = Int((totalTime Mod 3600) / 60)
seconds = totalTime Mod 60
txt = Right("00" & CStr(hours), 2) & ":" & _
Right("00" & CStr(minutes), 2) & ":" & _
Right("00" & CStr(seconds), 2)
HMIRuntime.Screens(lpszPictureName).ScreenItems(lpszObjectName).Output = txt
The Right("00" & CStr(x), 2) pattern pads to two characters without using a manual length check. Place the VB script on the same I/O field Output Value event as the C version; WinCC accepts either per object but not both at once.
WinCC Unified V21: Native Output Format Property
WinCC Unified, introduced with TIA Portal V17 and continuously expanded through V21, exposes an Output Format property on every screen object that displays a numeric or time value. When the underlying tag type matches a pattern consumer supported by the runtime, no script is required.
Pattern Reference
The official TIA Portal V21 documentation lists the supported format tokens, the available placeholder syntax, and the data-type constraints for each pattern. Refer to the manufacturer manual for the definitive list:
Defining the output format (WinCC Unified RT, TIA Portal V21)
Configuration Steps
- Open the Unified screen in the TIA Portal editor.
- Select the screen object (I/O field, text field, or output).
- Open Properties > Display > Output Format.
- Enter the format pattern that maps to the desired
hh:mm:ssrendering. The exact token syntax is documented in the reference above; verify against your installed build before deployment because pattern support can vary between service packs. - Bind the tag. If the runtime pattern consumes a TimeSpan tag, expose a derived tag of type
Timefrom the AS instead of passing the raw DWORD seconds value.
Time from an SCL function block in the AS and assign that derived tag to the screen object.
Reference Script from the APL aggr08 Block
The Industry Library block aggr08 is a related runtime counter that ships with an example C script in its faceplate parameter view. The example script decomposes a seconds value into hours, minutes, and seconds and uses the printf-family formatter to insert the colon separators. It is the closest factory-supplied pattern to the conversion required here and is a useful reference for code review when commissioning new equipment. Inspect the faceplate parameter view of aggr08 for the exact listing; copy the conversion skeleton into your Global Script and adjust the tag name to match your CountOH instance.
Tag Logging Configuration
Tag logging in WinCC V7.x is configured in the Tag Logging editor. Two implementation paths apply depending on whether the operator needs to read the archive as text or whether the archive must remain numeric for trend export and external analysis.
Approach A — Log the formatted string
- Use the Global Script action above to populate
CountOH_TotalTime_Str. - In Tag Logging, add a new archive tag and select
CountOH_TotalTime_Stras the source. - Set the data type to
Text variable, 8-bit character setand the acquisition cycle to 1 second to match the CountOH resolution. - Configure the swap-out behaviour. For daily rotation set the archive segment to
1 day; for weekly rotation,7 days. - For long retention requirements, route the archive to a secondary storage path and configure backup timing per site policy.
Approach B — Log the raw DWORD and format on export
- Add a new archive tag bound directly to
CountOH_TotalTimewith data typeUnsigned 32-bit. - Set acquisition cycle to 1 second. For long-term archives consider 10-second or 60-second cycles to bound the archive size; the seconds resolution is preserved and the conversion is lossless.
- Create a UserArchive column or export-side calculated field that converts seconds to
hh:mm:ssfor the CSV/PDF reports. - This approach is preferable for trend display because the Y-axis scales linearly with seconds and avoids aliasing of the formatted string.
Archive Sizing Example
For a single tag acquired at 1-second cycle with 32-bit values, the archive grows by approximately 4 bytes per entry plus per-entry metadata of ~16 bytes. At 86,400 entries per day the archive segment is roughly 1.4 MB per day per tag. Plan disk capacity for 7 to 10 years of retention per site policy and rotate to backup storage before disk fills.
Trend Display Configuration
WinCC Online Trend Controls in V7.x and the equivalent Trend Control in WinCC Unified require a numeric Y-axis; they cannot render a string tag as a continuous trace. Two practical options exist.
Option 1 — Display raw seconds with axis label
- Add a WinCC Online Trend Control to the picture.
- Assign
CountOH_TotalTime(DWORD archive tag) as the trend tag. - Configure the Y-axis label as
Runtime [s]orRuntime [hh:mm:ss]per operator preference. - Set Y-axis scaling to auto, or fix the range to the expected operating window (for example 0 to 3,600,000 seconds for a 1000-hour display ceiling).
- Configure the time axis to cover the desired trace window — 8 hours, 24 hours, or 7 days are typical defaults.
Option 2 — Overlay a formatted string on a numeric trace
If a literal hh:mm:ss label must appear on the trend canvas, render the numeric trend as described in Option 1 and overlay a static text element that updates from CountOH_TotalTime_Str. The overlay is positioned over the trend area and bound to the formatted string tag; the curve itself remains numeric.
Multi-Equipment Deployment Pattern
For plants with many monitored assets (typical PCS7 installations exceed 100 CountOH instances), replicate the conversion through a script-generator template rather than hand-writing each instance.
Recommended Pattern
- Define a naming convention:
CountOH_TotalTime_<EQ>for the source tag andCountOH_TotalTime_Str_<EQ>for the formatted string tag. - Export the WinCC tag list to CSV and generate the Global Script action template via a small utility script (Python or VBScript on the engineering workstation) that substitutes the equipment suffix.
- Import the generated actions into Global Script and compile in batch.
- Bind each I/O field on the equipment overview picture to the corresponding
_Str_<EQ>tag. - For very large fleets, evaluate moving the conversion into the AS (S7-1500 SCL function block) and expose
Hours,Minutes,Secondsas separate outputs. This reduces WinCC script load and improves HMI response time on lower-spec runtime servers.
Performance Ceiling
A single Global Script C action consumes negligible runtime per execution (~50 microseconds typical). At 1,000 actions triggered on tag change per second the cumulative load is ~50 ms per second, which is comfortable on any supported WinCC Runtime license. Beyond 5,000 actions per second consider the AS-side conversion pattern to offload the runtime.
Migration from WinCC V7.x to Unified
Existing V7.x projects being migrated to TIA Portal / WinCC Unified require a script audit because the Unified runtime rejects a subset of legacy C functions and uses a different tag-access API.
Audit Checklist
- Identify every C action that reads
CountOH_TotalTimeor any otherTotalTimevariant. - Confirm each tag is migrated and re-bound in the Unified tag management.
- Replace
GetTagDWord/SetTagCharwith the asynchronousHMIRuntime.TagsAPI. Read into a local variable before formatting. - Test the Output Format property first; only fall back to a script if the pattern does not match the tag type.
- Re-verify each trend binding against the migrated archive tags.
Unified C Script Equivalent
// WinCC Unified V21 - C script on Output Value event
{
DWORD totalTime;
DWORD hours, minutes, seconds;
char buffer[16];
HMIRuntime.Tags.SysFct."CountOH_TotalTime".Read(&totalTime, 1);
hours = totalTime / 3600;
minutes = (totalTime % 3600) / 60;
seconds = totalTime % 60;
sprintf(buffer, "%02lu:%02lu:%02lu", hours, minutes, seconds);
HMIRuntime.Screens(lpszPictureName).ScreenItems(lpszObjectName).Output = buffer;
return 0;
}
The exact Unified API surface depends on the installed service pack; consult the TIA Portal V21 help for the supported tag-access patterns and confirm against the runtime build before deployment.
Verification Procedure
Execute the following steps on the engineering workstation and on the operator panel after every code change.
- Force the
TotalTimetag to a known value via the AS simulation interface. Use 0, 59, 3600, 4536, and 86399 to cover the boundary cases. - Open the operator screen in WinCC Runtime and confirm the I/O field displays the expected
hh:mm:ssfor each forced value. - Trigger a tag change from a non-boundary value and verify the Global Script action re-formats the string within one scan cycle.
- Open Tag Logging and confirm the archive entry contains the expected string value (Approach A) or the expected numeric value (Approach B).
- Open the trend view and confirm the curve ramps linearly when the underlying seconds value increments. Watch for jump discontinuities that would indicate a missed conversion.
- Reset
TotalTimevia the faceplate reset button and confirm both the screen and the archive reflect the reset to00:00:00. - Power-cycle the AS (if a maintenance window is available) and confirm the formatted runtime survives the restart. A failure here indicates the CountOH instance DB is not marked retentive.
- Document the verified tag values and screenshot the operator screen in the commissioning report.
Troubleshooting Matrix
| Symptom | Likely Cause | Corrective Action |
|---|---|---|
I/O field shows raw seconds value (e.g. 4536) |
C script not compiled, or output format not set to String | Re-compile the C action via right-click > Compile; set Output Format to String and clear Data Format |
I/O field shows ####
|
Field width too narrow for the formatted string | Increase the I/O field width to at least 8 characters (length of hh:mm:ss) |
| Display lags by several seconds | Update cycle of the underlying tag too slow, or Global Script trigger set to standard cycle | Set tag acquisition cycle to 1 second matching CountOH resolution; change Global Script trigger to the tag-change event |
| Trend shows blank or disconnected curve | Trend tag bound to string archive tag instead of numeric tag | Bind the trend to the raw DWORD archive tag; overlay formatted text via a separate text object if needed |
| CountOH rolls over at 4,294,967,295 seconds | DWORD overflow after ~136 years continuous operation | Plan periodic resets at maintenance intervals; document reset policy in operating procedures |
| Negative or zero runtime displayed after AS restart | CountOH instance DB not retentive | Mark the CountOH instance DB as retentive in the AS hardware configuration and download a new version |
| Format string contains garbage characters in WinCC Unified | Mismatch between pattern tokens and PLC data type | Verify pattern syntax in the TIA Portal V21 manual and confirm the tag data type matches the pattern consumer |
Script compile error referencing apdef.h
|
Project header set corrupted or not loaded | Regenerate the project header via right-click > C-Editor > Header, then recompile |
| Archive grows unexpectedly fast | Acquisition cycle shorter than required or duplicate archive tags | Audit archive configuration; verify one archive tag per source; consider 10-second or 60-second cycle for long-term archives |
| Multiple I/O fields show different values simultaneously | Global Script not triggered on tag change but on standard cycle, and cycle overlaps with picture refresh | Switch trigger to the tag-change event and confirm activation order in WinCC Explorer |
| Reset button increments runtime instead of clearing | Wiring reversed between RESET input and acknowledge signal | Cross-check the CountOH signal list against the I/O assignment; correct in the CFC chart and recompile |
| Trend curve resets unexpectedly at midnight | Operator accidentally pressed reset, or instance DB reload | Verify with operations; if accidental, restrict reset privilege in the WinCC User Administrator |
Best Practices and Field-Proven Notes
- Centralise the conversion in a Global Script action to avoid drift across multiple picture revisions.
- Always set the I/O field width before the first compile. WinCC does not re-compute the display width when the format string changes.
- Use the tag-change trigger on Global Script actions, not the standard cycle trigger, to avoid jitter and unnecessary CPU load.
- For plants with more than 100 monitored equipment, prefer AS-side conversion in an SCL function block and expose separate Hours, Minutes, and Seconds outputs. This reduces WinCC script load and improves HMI response time.
- Document the reset interval in the operating manual. The DWORD range is large but finite, and a roll-over in service is difficult to diagnose after the fact.
- When migrating from WinCC V7.x to Unified, audit every C action that formats
TotalTime. The Unified runtime rejects a subset of legacy V7.x C functions and uses a different tag-access API. - Keep the formatted string tag length at 16 characters to accommodate up to
136:00:00without truncation. For plants with even longer runtimes, widen to 24 characters and switch the display tohhhh:mm:ss. - Validate the conversion at the AS as well. A PCS7 acceptance test should verify both the formatted HMI display and the AS-side
TotalTimeinteger against a known reference (for example 4536 seconds).
FAQ
What data type is the CountOH TotalTime output?
CountOH TotalTime is a 32-bit unsigned integer (DWORD) holding cumulative equipment on-time in seconds since the last reset. Maximum value is 4,294,967,295 seconds (approximately 136 years of continuous run).
How do I convert the hex value 16#11B8 to hh:mm:ss?
16#11B8 hex equals 4536 decimal seconds. Apply the formulas: hours = 4536 / 3600 = 1, minutes = (4536 % 3600) / 60 = 15, seconds = 4536 % 60 = 36. The formatted display string is 01:15:36.
Can I display hh:mm:ss directly in a WinCC trend?
Online Trend Controls in WinCC V7.x and Trend Controls in WinCC Unified require a numeric Y-axis and cannot render a string tag as a continuous trace. Log the raw DWORD seconds value to the archive, bind the trend to that tag, and overlay a text element with the formatted string updated by a Global Script action if a literal hh:mm:ss annotation is required.
Do I need a script in WinCC Unified V21?
Not necessarily. WinCC Unified V21 exposes an Output Format property on screen objects. Configure the pattern string per the Defining the output format (RT Unified) reference. If the underlying tag is seconds-as-DWORD, confirm the format pattern tokens apply to the tag data type before deployment; otherwise expose a derived Time tag from the AS.
Why does the I/O field show ### after applying the C script?
The I/O field is too narrow for the formatted string. The hh:mm:ss display requires 8 characters; resize the field width accordingly. Also confirm the Output Format property is set to String and the Data Format field is empty, then recompile the C action.
Where can I find an example script in the PCS7 library?
The Industry Library block aggr08 ships with an example script in its faceplate parameter view that decomposes a seconds value into hours, minutes, and seconds using the printf-family formatter. Inspect that faceplate for the canonical conversion skeleton.