WinCC Push Button: Controlling Multiple Tags in One Action

David Krause16 min read
HMI / SCADASiemensTutorial / How-to
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

WinCC Push Button: Controlling Multiple Tags in One Action

SIMATIC WinCC push buttons bind a single tag and a single bit by default in the Dynamic Dialogue and Direct Tag dialogs. Engineers commissioning HMI screens that drive several outputs from one operator action must escalate beyond the per-event binding. This reference covers five field-proven methods to set or reset multiple tags, or multiple bits inside a single word tag, from a single WinCC button event: ANSI-C scripts in WinCC V7, the Setting/Resetting bits dynamic wizard, VBScript bitwise operations in WinCC Professional (TIA Portal), PLC-side logic, and the multi-tag selection tool introduced in WinCC Unified V17 and current through V21.

Problem Definition

The default WinCC button configuration dialog exposes one Tag field and one Bit field per event (mouse click, press, release). When the control strategy is "one operator action triggers several outputs", the screen designer faces three distinct cases:

  1. Multiple distinct tags — each output is a separate HMI tag pointing to a different PLC bit or word. Example: StartPump, OpenValve, ResetConveyor are three independent BOOL tags.
  2. Multiple bits in one tag — all outputs share a single PLC word (often a control or command word), and each output is a different bit of that word. Example: ControlWord at DB100.DBW0 contains bits 0–7 driving eight outputs.
  3. Mixed — some outputs are individual tags, others are bits inside a shared word, all triggered by the same button.

The dialog is a per-event binding, not a per-screen binding. The fix is to attach a script or a PLC routine that performs the multi-tag work in one transaction. The five methods below cover each case with working code, runtime caveats, and verification steps.

WinCC Versions and Architecture

The technique depends on the runtime in use. The methods below reference three product lines found in production plants in 2024–2025:

Runtime Scripting Language Bit Operation Primitive Multi-Tag Selection First Multi-Bit Wizard
WinCC V7.x (classic, standalone) ANSI-C SetTagBit(), GetTagBit(), SetTagWord() No multi-tag table Dynamic Wizard Setting/Resetting bits (V7.0)
WinCC Comfort / Advanced (TIA Portal V13–V16) VBScript SmartTags() with bitwise operators No built-in Manual VBScript
WinCC Professional (TIA Portal V15–V20) VBScript SmartTags() with bitwise operators No built-in Manual VBScript
WinCC Unified (TIA Portal V17+) JavaScript Tags().Read() / Tags().Write() Drag-select multi-tag editor V17 multi-tag editor

Confirm the engineering environment in TIA Portal > Project tree > Devices > [HMI] > Device configuration > General before choosing a method. WinCC Unified V17 introduced the multi-tag editor documented in the official TIA Portal help under Configuring tags (RT Unified) > Configuring multiple tags; it is the cleanest path when the project targets a Unified Comfort Panel, a Unified RT Advanced, or a Unified PC runtime.

Prerequisites

  • TIA Portal V16 or later (V18 or later recommended for the WinCC Unified multi-tag editor; the TIA Portal help tracks through V21)
  • WinCC Comfort, WinCC Professional, or WinCC Unified license for the target panel
  • HMI tags defined in the HMI tags table with valid PLC connections
  • Tag of type Word (16 bit) or DWord (32 bit) when bit-masking is planned; the tag width defines the available mask range
  • Read/write access to the underlying PLC data block or output area
  • For the PLC-side method: STEP 7 program with a free marker bit in a data block or merker area
Confirm the HMI connection in Connections shows a green status indicator. A red connection bar will cause the script to return quality bad silently and the tags will not update on the PLC. The error does not surface as a script error—it surfaces as a quality code on the tag.

Method 1 — C-Script with Direct Tag Calls (WinCC V7)

The classic WinCC V7 environment supports ANSI-C functions on button events. The Setting/Resetting a bit and Setting/Resetting bits dynamic wizards generate a C-script template that calls SetTagBit() for each target. Edit the generated code to call as many SetTagBit() statements as required. The runtime dispatches all calls in the same OnClick event, so the PLC sees the change in one acquisition cycle.

// Generated by dynamic wizard "Setting/Resetting bits"; extended manually
#include "apdefap.h"

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
    // Set output 1, reset output 2, toggle output 3 in one operator click
    SetTagBit("HMI_Output_1", 1);
    SetTagBit("HMI_Output_2", 0);
    SetTagBit("HMI_Output_3", 1);
    SetTagBit("HMI_Valve_Open", 1);
}

To use a single word tag and address individual bits, declare a local WORD variable, call GetTagWord(), mask, and write back with SetTagWord():

void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName, UINT nFlags, int x, int y)
{
    WORD wValue = 0;

    if (GetTagWord("HMI_ControlWord", &wValue) == 0)
    {
        // Read succeeded
        wValue |= 0x0015;  // Set bits 0, 2, 4
        wValue &= ~0x000A; // Reset bits 1, 3

        SetTagWord("HMI_ControlWord", wValue);
    }
    else
    {
        // Optional: trigger a system alarm
        // Internal error: tag read failed
    }
}

Compile the script with Right-click > Compile and check the output window for warnings. C-scripts run in the graphics runtime process; long-running loops block the HMI refresh. Keep the body of OnClick to a few tag operations. If you need to drive more than ten tags, move the logic to the PLC (see Method 4) or split the work across events (for example, mouse press and mouse release).

Method 2 — Dynamic Wizard "Setting/Resetting Bits"

The fastest path in WinCC V7 when the tags are individual bits. The wizard writes a C-script under the selected event, eliminating the need to author the C code by hand.

  1. Select the button on the screen.
  2. Right-click > Dynamic Wizard > System > Set/Reset.
  3. Choose Setting/Resetting bits (plural) to expose a list of tags—not the singular Setting/Resetting a bit, which is for a single tag.
  4. Click Add tag for every HMI tag the button must drive.
  5. Set each row to Set (write 1), Reset (write 0), or Toggle (invert the current value).
  6. Choose the trigger event: Mouse click, Press, or Release. Mouse click is the standard operator action; Press/Release gives a latched behavior used for jog and inching controls.
  7. Finish. The wizard writes a C-script under the selected event.

Inspect the generated script and rename the placeholder tag names (for example, bit_0) to match your tag table. The wizard does not validate the tag names against the HMI tag table; a typo surfaces only at runtime as a quality-bad tag. Run Compiler > Check consistency before downloading the project to the panel.

Method 3 — VBScript Bitwise Operations (WinCC Professional TIA)

WinCC Professional in TIA Portal uses VBScript for button events. The runtime evaluates SmartTags() synchronously; the value is written to the PLC on the next acquisition cycle. Combine bitwise OR, AND, and NOT to set or reset multiple bits in a single write transaction. The whole read-mask-write runs in one HMI acquisition cycle, so the PLC never sees a partial state where some bits are set and others are still in their previous value.

' WinCC Professional VBScript on button "Click" event
Sub OnClick(ByVal item)
    Dim ctrl
    Set ctrl = SmartTags("HMI_ControlWord")

    ' Build mask: set bits 0, 1, 4
    Dim setMask
    setMask = &H13  ' binary 0001 0011

    ' Build mask: reset bits 2, 3
    Dim resetMask
    resetMask = &H0C ' binary 0000 1100

    ctrl = (ctrl Or setMask) And Not resetMask
    SmartTags("HMI_ControlWord") = ctrl
End Sub

To combine distinct tags into one action, call SmartTags for each. The runtime coalesces the assignments into one acquisition cycle, so the PLC sees a consistent set of changes:

Sub OnClick(ByVal item)
    SmartTags("HMI_Output_1") = 1
    SmartTags("HMI_Output_2") = 0
    SmartTags("HMI_Output_3") = 1
    SmartTags("HMI_Valve_Open") = 1
    SmartTags("HMI_Pump_Run") = 1
End Sub
In WinCC Professional, SmartTags is a runtime object; assign to a local variable only when the tag is a complex type. For a Word tag, the assignment ctrl = (ctrl Or setMask) And Not resetMask reads, masks, and writes in a single line. The runtime does not guarantee that two consecutive SmartTags(...) writes are dispatched atomically on the PLC side—use the read-mask-write pattern to avoid race conditions.

Method 4 — PLC-Side Logic

Moving the multi-bit operation out of the HMI reduces script load on the panel and centralizes the logic in the PLC program. The technique: bind the HMI button to a single trigger bit in the PLC, and use that bit's NO contact to drive every required output coil in parallel. The button on the HMI screen keeps a single-tag, single-bit configuration—the wizard dialog remains valid, no scripting is required on the HMI side.

// S7-1500 / S7-1200 ladder example (STEP 7 V16+)
// Network 1: operator button pulse (HMI trigger)
A     "HMI_TriggerBit"     // from WinCC button, BOOL in DB
=     "TriggerPulse"       // local helper, BOOL in DB

// Network 2: drive outputs in parallel
A     "TriggerPulse"
=     "Output_1"
=     "Output_2"
=     "Output_3"
=     "Valve_Open"

// Network 3: reset a second set of outputs on the same trigger
A     "TriggerPulse"
AN    "Mode_Selector"      // interlock condition
=     "Output_4_Reset"

The PLC-side approach scales to dozens of outputs without affecting HMI performance. The button on the HMI screen keeps a single-tag, single-bit configuration—the wizard dialog remains valid. For S7-1500 with symbolic addressing, place HMI_TriggerBit in a standard data block (for example, DB100 "HMI_Interface") and mark it as Visible in HMI in the block properties.

For safety-relevant outputs, the PLC program must include the required safety interlocks; the HMI button is a command source, not a safety function. Never rely on the HMI script to enforce safety logic—use a fail-safe PLC (S7-1500F, ET 200SP F-CPU) and route the outputs through safety relays.

Method 5 — WinCC Unified Multi-Tag Selection

WinCC Unified V17 and later supports selecting multiple tags in the HMI tag table and applying a property binding to all selected rows at once. The workflow is documented in the official TIA Portal help: Configuring multiple tags (RT Unified).

  1. Open the HMI tags table in the project tree.
  2. Select the first tag, then hold the left mouse button and drag a selection box over the additional tag rows.
  3. Release on the last row. The cells highlight to confirm the multi-row selection.
  4. Open Properties > Events > Click on any selected row—the binding applies to every row in the selection.
  5. Assign the same screen object or the same script to all selected tags.

For multi-bit logic on a single word tag, the same script from Method 3 applies; only the binding mechanics change. In Unified, the runtime API exposes Tags().Item("HMI_ControlWord").Write(...) for asynchronous writes:

// WinCC Unified JavaScript on button "Click" event
import { tags } from "wincc-unified-runtime";

export function OnClick(item) {
    let value = tags("HMI_ControlWord").Read();
    value = (value | 0x0013) & ~0x000C;
    tags("HMI_ControlWord").Write(value);
}
The asynchronous Write() call returns a Promise. The runtime may reorder overlapping writes if you call Write several times inside one click handler. Coalesce the operation into a single Read — mask — Write sequence to guarantee atomicity. A second Read immediately after a Write may still return the old value because the HMI acquisition cycle has not completed; for read-after-write verification, use await on the Promise or rely on the PLC tag monitor.

Bit Masking Reference

When the strategy is "one word tag, multiple bits", the mask dictionary below covers the most common 16-bit fields. Use it to translate an output list into a single hex mask that the script can apply in one OR/AND operation.

Bit Hex (Bit 0–3) Hex (Bit 4–7) Hex (Bit 8–11) Hex (Bit 12–15) Decimal
0 0x0001 0x0010 0x0100 0x1000 1
1 0x0002 0x0020 0x0200 0x2000 2
2 0x0004 0x0040 0x0400 0x4000 4
3 0x0008 0x0080 0x0800 0x8000 8
4 0x0010 0x0100 0x1000 0x0001 (high word) 16
5 0x0020 0x0200 0x2000 0x0002 (high word) 32
6 0x0040 0x0400 0x4000 0x0004 (high word) 64
7 0x0080 0x0800 0x8000 0x0008 (high word) 128

To set bits 0, 2, and 4 in a single OR mask: 0x0001 | 0x0004 | 0x0010 = 0x0015. To reset bits 1 and 3: ~0x0002 & ~0x0008 = 0xFFF5, then AND with the current value. For a 32-bit DWord tag, prefix the mask with the high word: bit 16 = 0x00010000, bit 31 = 0x80000000. Use ULong arithmetic in the script to avoid sign extension when the high bit is set.

State Machine for a Multi-Bit Button

The SVG below shows the dispatch order of a single click event. The script reads the current word, applies the set and reset masks, writes the result, and returns. The HMI acquisition cycle carries the new value to the PLC.

Operator click Read ControlWord OR with set mask AND with NOT reset mask Write ControlWord HMI acquisition cycle to PLC

Verification and Commissioning

  1. Tag monitor — Open TIA Portal > Online > Watch table or the HMI tag simulator and confirm the values change after the button click. For a Word tag, expand the value to binary view to verify the right bits changed.
  2. PLC online — Connect to the PLC, force the HMI tag in the watch table, and verify the PLC bit flips in the same scan cycle. If the PLC sees a value with extra bits set, the HMI script read a stale value; check the HMI acquisition cycle (default 1 s) and the PLC connection's update time.
  3. Quality code — Right-click the HMI tag in the runtime and check the quality code. 0xC0 (good non-cascaded) confirms the write succeeded; 0x40 (bad non-cascaded) indicates the connection or address is wrong. Quality codes 0x40–0x7F in WinCC follow the OPC UA specification.
  4. Cycle time — In WinCC Unified, open Diagnostics > Performance and verify the script execution time stays below 50 ms to keep the HMI responsive. The Performance view shows per-task execution time and frequency.
  5. Trace — Enable Debug > Trace tag in WinCC V7 to log every write to a CSV file. The trace records the tag name, the new value, the timestamp, and the user (if user administration is enabled).

Troubleshooting Matrix

Symptom Likely Cause Corrective Action
Tag value does not change after click HMI connection in stopped state or wrong PLC address Check Connections status; recompile the HMI; download to the panel; verify the DB address in the PLC project matches the HMI tag's PLC tag or Address field
Only the first bit updates Multiple SmartTags calls overwrite each other due to async write in Unified Coalesce into a single Read — mask — Write; avoid back-to-back Write() calls inside one click handler
Quality code 0x40 (bad) Tag does not exist or HMI cannot resolve the address Verify the tag name in the script matches the HMI tag table exactly (case sensitive); check the spelling of the tag inside the string passed to SetTagBit or SmartTags
Compile error in C-script Missing semicolon or unmatched brace Open the C-editor; review the red squiggle markers; recompile; the WinCC V7 compiler points to the line number in the output window
Other tags on screen flicker Script writes to an unrelated tag by mistake Audit tag names; enable Debug > Trace tag in WinCC V7; check that the assignment target is a valid tag name, not a property name
Bit toggle produces 0-1-0 instead of 1 PLC scan reads the bit before the HMI write completes Add a one-shot edge detection in the PLC; use Change event instead of Click; check the HMI acquisition cycle (lower values reduce the window)
Script compiles but does not run Event not linked to the script Right-click the button > Properties > Events > Click; confirm the script is listed; if empty, drop the script on the event
VBScript throws type mismatch Tag is not initialized or has the wrong type Verify the HMI tag type matches the variable type (Word vs Int vs Bool); in VBScript, declare Dim ctrl As Integer for a Word tag
Unified JavaScript import error Wrong module path or runtime version Verify the project is built against WinCC Unified V17+; check the Runtime settings > Services for the runtime version

Edge Cases and Field Notes

Several situations that surface during commissioning but rarely appear in vendor documentation:

  • Acquisition cycle race: the HMI tags a button click and writes the new value, but the PLC is in stop and the next acquisition cycle reads the old value back. The operator sees the tag revert. Solution: confirm the PLC is in run, and force a tag refresh in the HMI by toggling the connection or by enabling Cyclic continuous acquisition.
  • Byte-swap on PROFINET: when the PLC and HMI use different endianness (rare on S7, common on third-party PLCs), a Word tag written as 0x0015 arrives as 0x1500. The mask dictionary in this article assumes the standard Siemens big-endian word layout. Verify with the watch table before commissioning the script.
  • User administration: if the project enforces user levels, a button click that requires a higher authorization will be silently rejected unless the script checks the current user. Use GetUserName() in WinCC V7 or HMIRuntime.UI.GetCurrentUser() in Unified to surface a friendly message.
  • Multi-language screens: the tag names are language-independent, but the button label and the operator message are not. Place the messages in the Text list editor and reference them by ID to keep the multi-language build consistent.
  • Tag length mismatch: assigning a VBScript Long to a 16-bit Word tag truncates the high word. The PLC sees only the low 16 bits. Cast with ctrl And &HFFFF to make the truncation explicit.

FAQ

Can a WinCC button drive more than one tag without scripting?

Yes. In WinCC V7, use the Setting/Resetting bits dynamic wizard. In WinCC Unified V17 and later, select multiple tag rows in the HMI tag table and apply the same screen-object binding to all of them. For WinCC Comfort/Professional (TIA Portal V15–V20), scripting is required because the standard binding dialog is single-tag per event.

How do I set bits 0, 2, and 4 of a single Word tag from one click in WinCC Professional?

Use VBScript on the button Click event: read the tag with SmartTags("ControlWord"), apply the mask (value Or &H15) And Not &H0A, then write it back with the same SmartTags assignment. The whole read-mask-write runs in one HMI acquisition cycle, so the PLC never sees a partial state.

Is it better to script the multi-tag logic in the HMI or in the PLC?

PLC-side logic is preferred for plants with many outputs because it keeps the HMI script lean, centralizes the I/O mapping, and survives HMI restarts. Use HMI scripting only when the PLC is not accessible or when the logic is purely HMI-side (for example, screen navigation and visibility toggles). For safety-relevant outputs, the PLC program is mandatory; HMI scripts must never enforce safety interlocks.

Why does my WinCC Unified script toggle bits asynchronously?

WinCC Unified's Tags().Write() returns a Promise. Multiple Write calls inside one click handler can interleave with the runtime's polling cycle, and a second Read immediately after a Write may return the old value. Coalesce the operation into a single Read — mask — Write sequence to keep the change atomic on the PLC side and use await on the Promise for verification.

Which WinCC version first supported multi-tag selection in the HMI tag table?

The drag-select multi-tag editor shipped with WinCC Unified in TIA Portal V17. The official documentation is in the TIA Portal help under Configuring tags (RT Unified) > Configuring multiple tags and is current through V21. WinCC V7 and WinCC Comfort/Professional do not have the multi-tag editor and require scripting or the dynamic wizard.

Back to blog