Run Scripts Cyclically in WinCC Comfort: TIA Portal Guide

David Krause13 min read
SiemensTutorial / How-toWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview: Cyclic Script Execution on Siemens Comfort Panels

Siemens Comfort Panels (the TP/KTP generation that pairs with the S7-1200/1500 controller family) run WinCC Comfort/Advanced Runtime directly on the panel. Unlike WinCC V7.5 SP1 on a PC, where the WinCC Explorer scheduler can drive cyclic actions in the millisecond range, the panel runtime exposes a much narrower set of cyclic primitives: scheduled tasks, tag value-change events, and system events. When a project is migrated from a Mitsubishi HMI to a Siemens Comfort Panel (such as the 6AV2 124-1MC01-0AX0 TP1200 Comfort) over Modbus TCP/IP, and the application logic depends on free-running polling, the engineer must pick a Comfort-compatible trigger pattern. This article documents three field-proven approaches, the official constraints that bound them, and the anti-patterns (such as unbounded While loops) that must be avoided.

Prerequisites

  • TIA Portal V16, V17, or V18 (V18 recommended for current panel firmware support).
  • WinCC Comfort/Advanced V16+ engineering component installed in TIA Portal.
  • Siemens Comfort Panel firmware V16 or higher. For the TP1200 Comfort 6AV2 124-1MC01-0AX0, firmware V17.x is current as of this writing.
  • Modbus TCP/IP connection configured in the HMI device with a verified point-to-point route to the Modbus slave.
  • HMI tags of internal scope (HMI-local) created in the project tree, with the appropriate data type for the trigger pattern.
  • Project rights to edit the HMI's "Schedules" node, the tag properties, and the VBScript function library.
  • Access to the panel's runtime diagnostic views (Schedules, Tag Simulator, Diagnostic Buffer) for verification.

Trigger Mechanisms Comparison

Trigger Min Interval Max Interval CPU Load PLC Tag Required Recommended Use
Scheduled Task (Schedules node) 1 minute 1 hour and longer Low No Slow polling, housekeeping, log flushing
Tag Value Change (HMI internal tag) ~250 ms (limited by tag acquisition cycle) Limited by tag update path Low Internal tag only Sub-minute cyclic execution
System Events (RuntimeStart, ScreenChange, ConnectionStatusChange) Event-driven, not cyclic Event-driven Negligible No Initialization, recovery
Continuous loop in script (While ... Wend) Theoretical sub-ms None High, blocks UI No Avoid on panels

Method 1: Configure a Scheduled Task in TIA Portal

On Comfort Panels, the "Schedules" node under the HMI device in the project tree is the most reliable cyclic trigger for intervals of 1 minute or more. The configuration procedure in TIA Portal V17/V18 is:

  1. Open the HMI device in the project tree.
  2. Expand Schedules under the HMI device; the default list contains Schedule_1.
  3. Add a new schedule or edit the default. Set the Trigger to Cyclic.
  4. Set the cyclic interval to 1 minute (the smallest supported value on Comfort Panels) or 1 hour.
  5. In the Event column, link the schedule to a VBScript function (for example PollModbusData). The link uses the function name as configured under "Scripts > VB Scripts" in the HMI device.
  6. Compile the HMI project (Build > Rebuild All) and download the full project (not just the delta) to the panel.
  7. In Runtime, navigate to the Schedules diagnostic view to confirm the schedule is enabled and shows the next fire time.

According to the official WinCC scripting documentation (Siemens Support entry ID 109773213): "With cyclic actions, the action is always executed, e.g. every 20 seconds. The tag trigger only executes the action if a change in the value of the tag has been detected." On Comfort Panels, the same distinction applies, but the cyclic interval is fixed at 1 minute minimum — a critical constraint for any application requiring higher rates.

Parameter Reference: Schedule Properties

Property Comfort Panel Value Notes
Trigger type Cyclic, Once, Daily, Weekly, Monthly, Yearly Cyclic is the only continuously-running mode
Min cyclic interval 1 minute Hard limit on Comfort Panels; not configurable below
Max cyclic interval 24 hours or longer Use 1 hour for typical housekeeping
Event linkage VBScript function name Function must exist in the HMI's script library
Runtime status visibility Yes (Schedules diagnostic view) Use this for verification

Method 2: Internal Tag Value-Change Trigger

To achieve faster than 1 minute, use an internal HMI tag whose value is repeatedly changed by a schedule, and bind a second VBScript to the tag's Value Change event. This is the most common pattern in migrated Mitsubishi HMI applications where the source HMI had a free-running polling cycle and the engineer wants to keep the cycle rate at 500 ms or 1 s.

Step-by-Step Procedure

  1. In the HMI tags table, create an internal tag PollTrigger of type Word or Int. Internal tags are HMI-local and consume no PLC connection resources.
  2. Create two VBScript functions in the HMI's script library:
    • ToggleTrigger — flips the value of PollTrigger between 0 and 1.
    • PollModbusData — the application's polling logic.
  3. Create a scheduled task that runs every 1 minute and calls ToggleTrigger.
  4. On the PollTrigger tag properties, configure the Value Change event to call PollModbusData.
  5. To achieve sub-minute cycles (such as 500 ms), do not use a 1-minute schedule. Instead, bind ToggleTrigger to the Value Change event of PollTrigger itself — the tag triggers its own toggle. The minimum reliable cycle is governed by the panel's processing of the value-change queue and the tag's acquisition cycle.
  6. Set the tag's Acquisition mode to Cyclic continuous with a 250 ms or 500 ms cycle time.
  7. Compile and download the full project to the panel.

VBScript Toggle Implementation

' VBScript: ToggleTrigger
' Cyclic self-toggle pattern for sub-minute triggering on Comfort Panels
Dim currentValue
currentValue = SmartTags("PollTrigger")
If currentValue = 0 Then
    SmartTags("PollTrigger") = 1
Else
    SmartTags("PollTrigger") = 0
End If

VBScript Polling Skeleton

' VBScript: PollModbusData
' Bound to the value-change event of PollTrigger
Dim tagValue
tagValue = SmartTags("PollTrigger")
HMIRuntime.Trace("PollModbusData fired, trigger=" & tagValue & ", t=" & Now)

' Example: read a Modbus holding register via the configured HMI tag
Dim rawData
rawData = SmartTags("MB_HoldingReg_40001")

' Application logic here. Keep total execution time under 200 ms
' to avoid blocking other HMI tasks.

Common Failure: 500 ms Toggle Does Not Fire Script

Symptom: A user toggles an internal HMI tag every 500 ms but the bound VBScript is never invoked.
Root causes (in order of frequency):
  1. The value-change event is configured on a tag that is being read by the same script. Value-change events are not re-entrantly fired by writes from a bound script; the script reads the new value but the event is consumed by the same script invocation.
  2. The HMI tag's Acquisition cycle is set to a longer interval than the toggle period. Value changes faster than the acquisition cycle are coalesced or dropped by the tag manager.
  3. The Cyclic continuous acquisition mode is not enabled. The tag must run on a continuous cycle for sub-second value-change events to be delivered.
  4. The script function name in the event link does not exactly match the VBScript function name (case sensitive on some firmware versions).
Fix: Set the tag's Acquisition mode to Cyclic continuous with a 250 ms or 500 ms cycle time, and verify the script binding is on the Value Change event, not on a limit-exceeded event. Confirm the function name spelling in the HMI's script library matches the link exactly.

Tag Configuration Reference

Property Required Value Notes
Tag name PollTrigger (or application-specific) Internal tag, no PLC address
Data type Word or Int Word is sufficient for 0/1 toggling
Acquisition mode Cyclic continuous Do not use "On demand" or "Cyclic once"
Acquisition cycle 250 ms or 500 ms Match your desired poll rate
Value Change event ToggleTrigger (or PollModbusData) Function name must exist in script library
PLC connection None (internal) Internal tags do not use a connection

Method 3: System Events

For one-shot initialization (opening a Modbus TCP connection, clearing buffers at runtime start, loading default values), bind scripts to system events. These are not truly cyclic, but combined with the methods above they cover the full lifecycle:

  • RuntimeStart — fires once when the runtime loads the project. Use to establish Modbus connection state, preload constants.
  • RuntimeStop — fires on graceful shutdown. Use to flush logs and close connections.
  • ScreenChange — fires on every screen change. Can refresh data on screen entry, but is not a true cyclic trigger.
  • ConnectionStatusChange — useful for Modbus reconnection logic; bind a script to detect transition from "Disconnected" to "Connected".
  • UserChange — fires on user login/logout. Use to refresh user-specific views.

Method 4 (Avoid): Infinite While Loops

Warning: A common anti-pattern is to use an infinite While ... Wend or Do ... Loop inside a button-bound script to achieve "cyclic" behavior. This pattern blocks the HMI event loop, prevents tag updates, freezes screen refresh, suppresses touch input, and in extreme cases can crash the Comfort Panel runtime requiring a power-cycle. Never use unbounded loops in Comfort Panel VBScripts. If a polling loop is required, use one of the cyclic triggers above (scheduled task, value-change event, or system event). If higher rate is required, reduce the tag acquisition cycle to the smallest supported value (250 ms) and use a value-change trigger.

Best Practices

  • Keep script execution time under 200 ms. Comfort Panels are resource-constrained; long scripts delay other HMI tasks such as screen refresh, alarm logging, and tag acquisition.
  • Prefer scheduled tasks for housekeeping. Use tag triggers only when you need sub-minute resolution.
  • Configure internal tags with Cyclic continuous acquisition at the smallest cycle that meets your SLA. Typical values: 250 ms for high-rate polling, 500 ms for medium-rate, 1 s for low-rate.
  • Do not rely on value-change events for tags updated faster than the tag's acquisition cycle. The runtime will drop changes that occur between acquisition points.
  • Cache SmartTags(...) reads at the start of a script to avoid repeated tag-manager calls. Each SmartTags access has measurable overhead on Comfort Panels.
  • For Modbus TCP/IP polling, configure the connection's Cycle parameter to match the desired update interval. Avoid issuing Modbus reads from the script if the connection can be configured to poll the relevant tags automatically — the panel's built-in Modbus driver is more efficient than script-driven reads.
  • Use HMIRuntime.Trace (visible in the diagnostic buffer) instead of Debug.Print for runtime logging on Comfort Panels.
  • Test scripts in the WinCC Runtime Simulator (PLCSim or the HMI simulator) before downloading to the physical panel. The simulator runs on a PC and is faster to iterate against.
  • Version your VBScript code in the project tree. Comfort Panel RT does not provide source control; maintain a copy in the TIA Portal project archive.

Modbus TCP/IP Integration Notes

When the application uses Modbus TCP/IP as the data source, configure the connection on the Comfort Panel as follows:

  • Driver: "Modicon Modbus TCP/IP" (or "Modbus TCP/IP" depending on TIA Portal version).
  • Connection parameters: IP address, port (default 502), slave/unit ID, connection cycle (250 ms to several seconds).
  • Tag area addressing follows Modicon convention: 0xxxx (coils), 1xxxx (discrete inputs), 3xxxx (input registers), 4xxxx (holding registers). TIA Portal maps these to the HMI tag address space.
  • For polled data, set the tag's Acquisition cycle to match the connection's Cycle parameter; mismatches cause stale data or unnecessary Modbus traffic.
  • Use the connection's diagnostic view in Runtime to confirm the connection state, error count, and last poll time.

Troubleshooting Matrix

Symptom Likely Cause Resolution
Scheduled task not firing Schedule disabled in Runtime; project not fully downloaded; function name mismatch Open Schedules diagnostic view; recompile and download the full project; verify the linked function name
Value-change event does not fire Tag acquisition cycle too long; bound script disabled; function name typo Reduce acquisition cycle to 250 ms; ensure the script function is enabled; verify exact function name match
Script runs but Modbus read returns 0 or invalid Connection not established; wrong Modbus address/function code; byte-order mismatch Verify connection status via the connection's diagnostic view; use a standalone Modbus poll tool to validate the slave response; check byte order (big-endian vs little-endian)
HMI freezes after script start Infinite loop in script Power-cycle the panel; rewrite the script with a cyclic trigger (schedule or value-change event)
Toggle value flickers but script never runs Value-change event bound to the wrong tag or wrong event type Re-link the event to the tag being written by the toggle script; confirm the event is "Value Change" not "Limit exceeded"
Script fires once and then stops Value-change event consumed by the same script; self-toggle fails Use a second tag for the trigger; bind ToggleTrigger to one tag, PollModbusData to another tag that ToggleTrigger writes
Modbus connection drops after a few minutes Keep-alive not configured; panel sleeps; firewall idle timeout Enable the connection's keep-alive option; set the connection cycle to a value less than the firewall idle timeout; check panel power management
Tag value is stale (does not reflect current Modbus value) Tag acquisition mode is "On demand" or cycle is too long Switch to "Cyclic continuous" with a cycle matching the connection cycle

Verification Procedure

  1. Open the panel's Runtime and navigate to the Schedules diagnostic view. Confirm the schedule is enabled, shows the expected interval, and lists the next fire time.
  2. Use the HMI tag simulation table to monitor PollTrigger. The value should oscillate at the configured rate (250 ms, 500 ms, or 1 s).
  3. Add a HMIRuntime.Trace line at the start of PollModbusData with a timestamp. Watch the diagnostic buffer to confirm the script is being called at the expected rate.
  4. Verify Modbus polling by adding a temporary output screen (or a numeric I/O field on an existing screen) that displays the polled registers. Confirm the values match a reference Modbus poll tool.
  5. Monitor the HMI's CPU load in the System diagnostic view. The CPU should remain below 70% under normal load; sustained higher values indicate that scripts are running too long or too frequently.
  6. Power-cycle the panel and confirm that cyclic execution resumes without manual intervention. This validates that schedules and value-change triggers are persistent across restart.

Diagnostic Buffer and Trace Reference

The Comfort Panel's diagnostic buffer (System > Diagnostic Buffer) records the following relevant events:

  • Runtime start and stop
  • Schedule execution (when trace is enabled for the schedule)
  • Connection state changes (Modbus connect, disconnect, error)
  • Script errors (VBScript runtime errors, including line number)
  • System errors (memory exhaustion, tag overflow)

To enable VBScript error logging, add the following line to the start of each script:

On Error Resume Next
' ... script body ...
If Err.Number <> 0 Then
    HMIRuntime.Trace("Script error " & Err.Number & ": " & Err.Description)
    Err.Clear
End If

Firmware and Version Notes

TIA Portal Version Panel Firmware Cyclic Min Interval VBScript Engine
V16 V16.x 1 minute VBScript 5.x compatible
V17 V17.x 1 minute VBScript 5.x compatible
V18 V18.x 1 minute VBScript 5.x compatible

All current Comfort Panel firmware versions enforce the 1-minute minimum cyclic schedule interval. Sub-minute execution requires the tag value-change pattern documented in Method 2.

FAQ

What is the fastest cyclic script interval on a Siemens Comfort Panel?

Scheduled tasks support a minimum of 1 minute on Comfort Panels. For faster execution, bind a VBScript to a continuously-cycling internal HMI tag's value-change event with a 250 ms acquisition cycle; the practical floor is approximately 250 ms.

Why does my 500 ms tag toggle not trigger the bound script?

The HMI tag's acquisition cycle is likely longer than the toggle period, or the value-change event is misconfigured. Set the tag acquisition mode to Cyclic continuous at 250 ms or 500 ms, and verify the event is bound to the tag's Value Change event, not a limit event. Also confirm the script function name in the event link exactly matches the function in the script library.

Can I use a While loop in a Comfort Panel VBScript?

No. Infinite While or Do loops block the HMI event loop and freeze the panel runtime, requiring a power-cycle to recover. Replace with scheduled tasks (1 minute minimum) or tag value-change triggers for cyclic logic.

Do I need a PLC tag to run a script cyclically on the HMI?

No. Internal HMI tags (HMI-local variables with no PLC address) can drive scheduled tasks and value-change events without any PLC interaction. The Modbus TCP/IP connection is only required for the data the script reads or writes, not for the trigger mechanism.

How does WinCC Comfort differ from WinCC V7.5 SP1 for cyclic scripts?

WinCC V7.5 SP1 on a PC supports cyclic actions with sub-second resolution via the WinCC Explorer scheduler, while WinCC Comfort on a panel limits scheduled tasks to a 1 minute minimum interval. For sub-minute cycles on a panel, the tag value-change pattern documented above is required.

Back to blog