Configuring Continuous Scripts in WinCC RT Advanced

David Krause11 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

Configuring Continuous Scripts in WinCC RT Advanced

WinCC Runtime Advanced (the panel-side runtime for Siemens SIMATIC HMI Panels and PC-based RT Advanced stations) exposes a single, shared scheduler for all VBScript actions. Engineers frequently ask how to keep a script "running all the time" without an external trigger. The runtime does not support a literal "free-running" script, but it provides three deterministic substitutes: scheduled tasks, cyclic triggers, and tag-triggered actions. Choosing the right mechanism is the difference between a stable HMI and a runtime that stalls under load.

A "continuously running" VBScript in WinCC RT Advanced is a script that the runtime re-invokes at a fixed interval. The script itself never loops inside the HMI process; instead the scheduler calls it repeatedly. Long internal Do...Loop blocks block the entire single-threaded script queue and will crash or freeze the runtime.

1. Runtime Execution Model

WinCC RT Advanced uses a single execution queue for every VBScript action and every C-action in the project. This architectural constraint — present since WinCC flexible 2008 and carried forward through TIA Portal V16 through V19 — drives every design decision below.

Runtime Variant Script Execution Queues Thread Model Recommended Cyclic Method
WinCC RT Advanced (Comfort Panel / PC) 1 shared queue Single-threaded for VBS Scheduled task or 1 s+ tag trigger
WinCC RT Professional Multiple C/VB actions, separate scheduler Background task support Background task (VB / C)
WinCC flexible 2008 SP5 1 shared queue Single-threaded Scheduled task or tag trigger

Because there is only one queue, a slow script blocks every other scheduled action, every value-change trigger, and every screen update tied to a script. The runtime does not preempt a running script — it waits for completion before dispatching the next scheduled call.

2. Prerequisites

  • TIA Portal V16, V17, V18, or V19 with WinCC Comfort/Advanced option installed.
  • A configured HMI device (Comfort Panel TP700..TP2200, or PC-based RT Advanced) compiled and transferred.
  • Project rights to edit "Schedules" under HMI Tags & Connections → Schedules.
  • For VBScript authoring: enabled VBScript runtime on the target (default on all Siemens panels).
  • Familiarity with WinCC Advanced scripting manual (entry ID 109755202).

3. Method A — Scheduled Task (Recommended)

A scheduled task invokes a VBScript function on a fixed time interval independent of any tag value change. It is the cleanest substitute for a "continuous" loop because the runtime owns the timer, the script returns control to the scheduler after each call, and the task is dispatched on the same single queue (so timing is predictable but you must keep the script short).

3.1 Creating the schedule

  1. In the TIA project tree, expand the HMI device and open Schedules.
  2. Right-click → Add new schedule. Name it (e.g., Poll_Loop_1s).
  3. In the schedule's properties set the trigger type to Cyclic and enter the interval. Minimum selectable interval is 100 ms; practical minimum is 1 s.
  4. Assign a VBScript function as the event handler of the schedule.

3.2 VBScript template

Function Poll_Loop_1s_Trigger(ByVal Item)
    Dim t0
    t0 = Now

    ' --- user logic (must complete well inside cycle time) ---
    SmartTags("AuxValue") = SmartTags("AuxValue") + 1

    ' --- diagnostic timer (optional) ---
    ShowSystemAlarm "Poll_Loop_1s execution ms: " & _
        DateDiff("s", t0, Now) * 1000
End Function

The schedule object exposes a single VBScript event [ScheduleName]_Trigger. The argument Item is the runtime schedule object and is rarely needed for poll loops.

Scheduled tasks in WinCC RT Advanced run on the same script queue as screen-change and value-change triggers. If your function takes 800 ms and you schedule it at 1 s, you risk queue saturation the moment a tag trigger fires simultaneously. Stay well below 50 % of the cycle period.

4. Method B — Tag-Triggered Cyclic Execution

Tag triggers are often the better choice because they let the runtime batch value updates and only invoke the script when something changed. To produce a periodic trigger you can either:

  • Use an internal tag whose value is updated by the PLC on a fixed cycle (typical scan time = 100 ms).
  • Use the HMI's own "Update" cycle of an internal pointer tag set to "Cyclic in operation" with a 1 s update.

4.1 Configure the trigger tag

  1. Add an internal HMI tag Heartbeat (type: Int, length 1).
  2. Set Acquisition mode = Cyclic continuous, Cycle = 1s.
  3. In the tag's Events tab add a VBScript action tied to Value change.

4.2 Trigger handler

Sub Heartbeat_OnChange(ByVal Item)
    ' Item.DSMObject gives access to runtime tag info if needed
    If SmartTags("EnablePolling") = 0 Then Exit Sub

    ' --- short, deterministic body ---
    SmartTags("Counter") = SmartTags("Counter") + 1
End Sub

The advantage over a fixed schedule is that the action only fires when the runtime actually observed a value change. With a 1 s update cycle on an internal tag this is functionally identical to a 1 s scheduled task but consumes one fewer scheduler object.

5. Method C — Cyclic Trigger on a Screen or Function Key

WinCC RT Advanced also allows a "Cyclic" event on a screen object or a function key. This is rarely the right answer because the trigger only fires while that screen or that key object is loaded and in focus. It is mentioned here only to caution against using it as a substitute for a continuous poll.

Method Interval Min. Scope Affects Other Scripts Diagnostic Output
Scheduled task 100 ms (1 s practical) Runtime-wide Yes (same queue) ShowSystemAlarm per call
Tag-triggered action 100 ms via internal tag Runtime-wide Yes (same queue) ShowSystemAlarm per call
Screen cyclic event 250 ms Single screen, while open Yes Limited

6. Monitoring Execution Time with ShowSystemAlarm

The runtime function ShowSystemAlarm writes a string into the system's alarm buffer with timestamp. Sandwiching the script body between two timestamp captures is the standard way to verify that your "continuous" script finishes inside its cycle budget.

Sub PollLoop(ByVal Item)
    Dim t0, ms
    t0 = Timer            ' seconds with sub-second resolution

    ' --- work ---
    CalcDerivedTags

    ms = (Timer - t0) * 1000
    If ms > 800 Then
        ShowSystemAlarm "PollLoop over budget: " & ms & " ms"
    End If
End Sub

Use Timer (VBScript built-in) rather than Now; Now only resolves to whole seconds and cannot capture sub-cycle execution time.

7. Why You Should Not Use an Internal Do...Loop

A common first attempt is:

' DO NOT DO THIS
Sub StartLoop(ByVal Item)
    Do
        SmartTags("Counter") = SmartTags("Counter") + 1
        ' ...
    Loop
End Sub

This blocks the only script queue for the entire duration of the loop. While the loop runs:

  • No other scheduled task fires.
  • Tag-triggered events queue up but never run until the loop exits (or the runtime watchdog trips).
  • Screen change scripts and alarm-triggered scripts are deferred.
  • The runtime watchdog (typically a few seconds) eventually raises 70022-class alarms and the panel may restart.

The correct pattern is to design the function as a stateless "tick" and rely on the scheduler for periodicity.

8. Performance Budget for a Comfort Panel TP900

Empirical guidance for an 800 MHz ARM-based Comfort Panel running TIA V18 RT Advanced:

Cycle Max Concurrent Active Scripts Recommended Max Body Time Risk if Exceeded
100 ms 1 ≤ 40 ms Queue starvation
250 ms 2–3 ≤ 100 ms Watchdog alarms
1 s 5–8 ≤ 400 ms Visible UI stalls
5 s 15+ ≤ 2 s Acceptable
These numbers are conservative field targets, not Siemens-published limits. PC-based RT Advanced can sustain heavier loads, but the single-queue constraint still applies.

9. Step-by-Step: Build a 1 s Continuous Poll

9.1 Add the schedule

  1. Project tree → HMI device → Schedules → right-click → Add new schedule.
  2. Name: Poll_1s.
  3. Trigger: Cyclic, Interval: 1 s.
  4. Confirm with OK.

9.2 Add the VBScript

  1. Project tree → HMI device → VBScripts → right-click → Add new VBScript.
  2. Name the script file mod_Poll.vbs.
  3. Paste the body from section 3.2.
  4. Right-click the schedule Poll_1s → Properties → Events → Trigger event → assign the function Poll_Loop_1s_Trigger.

9.3 Compile and transfer

  1. Right-click the HMI device → Compile & download (full).
  2. On the panel, navigate to the alarm buffer and look for the Poll_Loop_1s execution ms messages.

10. Verification Procedure

  1. After transfer, open the system alarms screen and verify Poll_Loop_1s fires approximately once per second.
  2. Force the function to a 2 s body by adding WScript.Sleep 2000 (debug only — never ship) and confirm the runtime surfaces a queue-overrun alarm.
  3. Open multiple screens concurrently and confirm that scheduled task continues to fire — this proves you are using a runtime-wide schedule, not a screen-bound cyclic event.
  4. Toggle the internal tag EnablePolling from the PLC and verify the function honours the guard clause.
  5. Capture the runtime log for one hour; verify no 70022 "Script execution time exceeded" alarms.

11. Troubleshooting Matrix

Symptom Likely Cause Fix
Script fires once then never again Unhandled runtime exception inside body Check alarm buffer for VBScript error; wrap body in On Error Resume Next for diagnosis only.
Script fires but UI becomes unresponsive Body exceeds cycle, queue saturates Reduce body time; move heavy work to PC-based RT or split into multiple tick functions.
Alarm 70022 "Script runtime exceeded" Internal Do...Loop or long sync call Refactor to stateless tick; remove blocking calls.
Schedule appears in tree but no event fires Function name misspelled in event assignment Verify function signature matches schedule event binding.
Schedule fires at irregular intervals Other scripts consuming queue time Audit all cyclic and tag-triggered actions; consolidate.
ShowSystemAlarm shows > 800 ms per call Tag access over slow connection (OPC UA to remote PLC) Cache tag values locally; access remote tags on slower cycle (5–10 s).

12. Common Anti-Patterns

  • Internal infinite loop: blocks the single queue and triggers watchdog.
  • Reading many external tags per tick: each SmartTags() call is a marshalling op; cache and reuse.
  • Polling on screen-c open instead of a schedule: poll stops when the screen closes.
  • Multiple overlapping schedules: 2 s and 1 s on similar logic double the queue load with no benefit.
  • Using Now for timing: only second-resolution, masks over-budget scripts.

13. Migrating From WinCC flexible 2008

The schedule concept is preserved in TIA Portal, but the property pages and event binding locations changed. In WinCC flexible 2008 the schedule event was bound in the schedule editor; in TIA Portal V16+ it is bound in the schedule's properties → Events → Trigger. If you are importing a WinCC flexible project with a continuous poll into TIA, verify the event binding survived the migration and re-test on a 1 s body to confirm queue capacity.

14. When to Move Up to WinCC RT Professional

If your application needs multiple long-running background scripts, genuine multithreading, OPC UA server publishing, or redundant HMI pairs, escalate to WinCC Runtime Professional. RT Professional provides background tasks with their own threads, which removes the single-queue constraint that drives every rule in this article.

15. Summary of the Recommended Pattern

  1. Design the function as a stateless "tick".
  2. Bind it to a schedule at the largest interval that still meets functional requirements.
  3. Wrap the body with Timer-based timing and ShowSystemAlarm for diagnostics.
  4. Keep the body under 40 % of the cycle period.
  5. Use a tag trigger instead of a schedule when the script should only run when external state changes.
  6. Never use an internal Do...Loop to simulate continuity.

Can I run a VBScript literally without any trigger in WinCC RT Advanced?

No. WinCC RT Advanced requires an event source for every VBScript invocation. The closest substitute is a schedule at the smallest practical interval (1 s on a Comfort Panel), which the runtime calls repeatedly and acts as a continuous trigger.

What is the minimum cycle time for a scheduled task in WinCC RT Advanced?

The dialog accepts 100 ms but the practical minimum on a Comfort Panel is 1 s because every script shares one queue. On PC-based RT Advanced with light CPU load you can run reliably at 250 ms; below that you risk queue starvation under tag load.

How do I measure how long my script takes?

Capture Timer at the start and end of the body, multiply the delta by 1000, and emit it via ShowSystemAlarm. The alarm buffer entry will show ms execution time per call so you can verify you stay inside your cycle budget.

Why does my script stop firing after the first run?

An unhandled VBScript runtime error invalidates the scheduled binding on some firmware versions. Open the alarm buffer, fix the reported error, recompile, and retransfer. Wrapping the body in On Error Resume Next only for diagnostic builds helps confirm the cause.

Is a tag-triggered action better than a scheduled task?

Usually yes. A tag trigger only invokes the script when the runtime observes a value change, so the queue is not consumed during steady state. Use a schedule only when you need a true periodic heartbeat independent of PLC data.

What happens if I use a Do...Loop inside the script?

The single shared script queue blocks for the entire loop duration, so no other action, alarm, or screen-change script runs and the watchdog will eventually raise a 70022-series alarm or restart the runtime. Refactor to a stateless tick and let the scheduler provide periodicity.

Does WinCC RT Professional behave differently?

Yes. RT Professional supports background tasks that run on their own threads and a separate scheduler, so you can have several long-running scripts without blocking the UI. If your application genuinely needs a multi-threaded script model, upgrade to RT Professional.

Back to blog