Overview: Why a 32-Bit Tag Is the Correct Path
The Option Group control in WinCC — used in WinCC Flexible 2008 SP5, TIA Portal WinCC Comfort / Advanced, and TIA Portal WinCC Professional — is a single-selection widget for mutually exclusive operator choices such as Manual / Auto, Local / Remote, or Off / On / Service. Internally, the control maintains a single integer property called Selected Box. WinCC writes the value of that property to the PLC every acquisition cycle as a 32-bit bitmask: exactly one bit is set, and the position of the bit tells the PLC which box the operator clicked. The most common beginner mistake is to wire a discrete boolean (e.g. a tag called Manual) to the property; the runtime rejects it with a compile error because the on-the-wire encoding requires at least 32 bits. This article documents the canonical 32-bit binding, the VBScript fallback for legacy PLC programs that demand one BOOL per mode, and the field-proven gotchas that bite engineers the first time they configure one.
There are two valid architectures:
- Bitmask (recommended): bind one DWORD to Selected Box on the HMI side and let the PLC extract individual bits with mask operations. Minimal data-point count, no VBS, deterministic on S7-1200 / S7-1500 / S7-300 / S7-400.
- Discrete booleans (legacy): bind the same DWORD to Selected Box and add a VBScript Change event that mirrors the bit pattern into separate BOOL tags. Use only when the PLC program cannot be modified.
Prerequisites
- TIA Portal V16 or later, or WinCC Flexible 2008 SP5 with the matching service pack installed on the engineering station.
- WinCC Comfort / Advanced / Professional runtime, or a WinCC Flexible RT target on a SIMATIC Comfort Panel, KTP, or Mobile Panel (tested on TP700, TP1200, KTP1200, MP277).
- PLC: SIMATIC S7-1200 (firmware V4.4 or later), S7-1500 (firmware V2.0 or later), S7-300, or S7-400 with an HMI connection already configured in Devices & Networks and a free data word in the process image or a DB.
- A 32-bit data location (DWORD or DINT) in the PLC that the HMI has write authorization for. The location must be byte-aligned.
- Operator authorization configured for the screen containing the Option Group (default level 0 is sufficient for unprivileged mode selection; raise it if the mode change is a privileged action).
Option Group Properties That Matter
| Property | Properties pane location | Range / Type | Effect |
|---|---|---|---|
| Number of boxes | Geometry | 1 – 32 (integer) | Defines the maximum selectable options. Bits 0 … n-1 of the bound tag are used. |
| Index 1 text … Index 32 text | Texts (or Font in WinCC Flexible) | String, max 32 characters | Operator-visible label for each option. Edit per language for multilingual projects. |
| Selected Box (process tag) | Output / Input → dynamic | 32-bit tag (DWORD / DINT) | Runtime value: the bitmask of the currently selected box. |
| Box count (process tag) | Output / Input | Integer tag (optional) | Reports the configured number of boxes for use in VBS or C# scripts. |
| Operator control enable | Miscellaneous → Enable | Boolean tag (optional) | Locks / unlocks the control from the PLC side. 1 = enabled, 0 = greyed out. |
| Authorization | Security | Auth level (0 – 7) | Operator level required to change the selection. Silent drop if unmet. |
0000 0000 0000 0000 0000 0000 0000 0010 — decimal 2, hex 0x0002. The integer value equals the bit pattern. This is the single largest source of confusion reported in the field.Tag Type Selection: Why DWORD Is Mandatory
The WinCC tag picker for the Selected Box attribute only offers data types wide enough to hold the bitmask. For 1 to 32 boxes, the on-the-wire value spans 1 to 32 bits, so the minimum legal tag is DWORD (unsigned 32-bit) or DINT (signed 32-bit). Wiring a single BOOL produces a compile error: "Invalid data type for tag 'Manual' at property 'Selected Box' of object 'Option group_1'."
| Tag type | Selected Box behavior | On-the-wire encoding (2-option example) |
|---|---|---|
| BOOL | Compile error — tag picker disables selection | N/A |
| INT (16-bit) | Allowed but limited to ≤ 16 boxes | Bit n set at value 2n |
| DINT (32-bit, signed) | Recommended for ≤ 32 boxes | Bit n set at value 2n, valid range 1 … 231-1 |
| DWORD (32-bit, unsigned) | Equivalent to DINT for unsigned semantics | Bit n set at value 2n, full 0 … 232-1 range |
| REAL / LREAL | Compile error | N/A |
Declare a single tag — e.g. HMI_OptGroup_Mode of type DWORD in a dedicated HMI-facing DB or in the default HMI tag table — and assign it to Selected Box at static index 0x1. Do not assign a second tag at a different static index. The runtime ignores subsequent indices for this attribute; assigning a second tag will only confuse the compiler and produce a tag that the runtime never updates. The PLC then reads that single DWORD and uses AND / word-mask instructions to test each option.
Bit-to-Box Mapping
The mapping is little-endian and 1-based. Box N is mapped to bit (N-1) of the bound DWORD. With the HMI side writing the integer value V to the PLC, the relationship is:
V = 2(N-1) for the currently selected box N
| Selected box | Bit 0 (Manual) | Bit 1 (Auto) | Bit 2 (Service) | Decimal V | Hex V |
|---|---|---|---|---|---|
| 1 (Manual) | 1 | 0 | 0 | 1 | 0x0001 |
| 2 (Auto) | 0 | 1 | 0 | 2 | 0x0002 |
| 3 (Service) | 0 | 0 | 1 | 4 | 0x0004 |
| None (during transition) | 0 | 0 | 0 | 0 | 0x0000 |
At no time are two bits simultaneously high — the Option Group is mutually exclusive by design. If your RT shows a value with multiple bits set, the tag is being written from another source (e.g. a recipe, a VBS, another HMI screen, or a PLC write that the runtime has not yet overwritten) and the bit pattern has been corrupted. Apply a sanity mask in the PLC and ignore any value outside 20 … 231.
Step-by-Step Configuration (TIA Portal V18)
- Open the screen that will contain the control, drag Option group from the toolbox under Controls → Selection onto the canvas.
- With the control selected, open the Properties pane → Geometry and set Number of boxes to the count you need (here 2 for Manual / Auto).
- In Properties → Texts, set Index 1 text = "Manual", Index 2 text = "Auto". For multilingual projects, switch the project language in the task bar and re-enter the texts; WinCC stores them per language in the project database.
- In the PLC project tree, open the HMI tag table (e.g. HMI_Tags) and add a new tag: name =
HMI_OptGroup_Mode, connection = the S7 connection, PLC tag = the DWORD in the PLC DB (or create an HMI-side DWORD and let the connection map it). For S7-1500, the recommended approach is a tag of type DWord in a DB with optimized access; for S7-300, a DWORD in a standard DB. - Back on the screen, select the Option Group. In Properties → Output/Input, click the dynamic icon next to Selected Box. Choose Tag in the dialog, then pick
HMI_OptGroup_Mode. The static index defaults to 0x1, which is what you want — leave it. Do not add a second dynamic entry under a different static index. - (Optional) Bind the Box count property to an INT tag if you want the configured number to be visible in the PLC for diagnostics.
- Compile the HMI project (right-click the HMI device → Compile → Software (rebuild all)). Address any tag-type errors before downloading.
- Download to the panel or the WinCC Runtime. Open RT and toggle the option group. Watch
HMI_OptGroup_Modein the PLC's watch table: it should cycle 1 → 2 → 1 → 2 … as the operator clicks.
PLC-Side Read Code
S7-1200 / S7-1500 in Structured Text (TIA Portal V18):
// DB "HMI_Interface"
// HMI_OptGroup_Mode : DWORD; // written by HMI, never written by PLC
// bManualMode : BOOL; // local view
// bAutoMode : BOOL;
"HMI_Interface".bManualMode := ("HMI_Interface".HMI_OptGroup_Mode AND 16#0001) <> 0;
"HMI_Interface".bAutoMode := ("HMI_Interface".HMI_OptGroup_Mode AND 16#0002) <> 0;
// Mutual-exclusivity safety: if RT somehow writes 3 (bits 0 and 1 both set),
// prioritize Manual and clear Auto.
IF ("HMI_Interface".HMI_OptGroup_Mode AND 16#0003) = 16#0003 THEN
"HMI_Interface".HMI_OptGroup_Mode := 16#0001;
END_IF;
S7-300 / S7-400 ladder (STEP 7 V5.7):
// DB100.DBX0.0 = "Manual" BOOL
// DB100.DBX0.1 = "Auto" BOOL
// DB100.DBD2 = "HMI_OptGroup_Mode" DWORD
A DB100.DBD2
AN M 100.0 // temporary bit to test bit 0
= DB100.DBX0.0
A DB100.DBD2
AN M 100.1
= DB100.DBX0.1
S7-300 SCL (Classic):
"HMI_Interface".bManualMode := DWORD_TO_BOOL("HMI_Interface".HMI_OptGroup_Mode AND 16#0001);
"HMI_Interface".bAutoMode := DWORD_TO_BOOL("HMI_Interface".HMI_OptGroup_Mode AND 16#0002);
S7-1500 with symbolic bit-slice (TIA V18, optimized DB):
"HMI_Interface".HMI_OptGroup_Mode.%X0 := ("HMI_Interface".HMI_OptGroup_Mode AND 16#0001) <> 0;
"HMI_Interface".HMI_OptGroup_Mode.%X1 := ("HMI_Interface".HMI_OptGroup_Mode AND 16#0002) <> 0;
VBS Fallback: Discrete Boolean Tags
Some legacy PLC programs expect one BOOL per mode (e.g. DB.Mode_Manual and DB.Mode_Auto) and the developer cannot add a DWORD buffer. The cleanest solution in that case is a small VBScript on the Option Group's Change event that mirrors the bit pattern into separate boolean tags. The script is a few lines:
' Attach to Option group_1 -> Events -> Change
Sub OnChange(ByVal Item)
Dim selBox
selBox = SmartTags("HMI_OptGroup_Mode") ' 32-bit tag (DWORD)
' Reset all mode booleans
SmartTags("Mode_Manual") = False
SmartTags("Mode_Auto") = False
SmartTags("Mode_Service") = False
' Set the matching bit
If (selBox And 1) <> 0 Then SmartTags("Mode_Manual") = True
If (selBox And 2) <> 0 Then SmartTags("Mode_Auto") = True
If (selBox And 4) <> 0 Then SmartTags("Mode_Service") = True
End Sub
The opposite direction — driving the Option Group selection from the PLC (e.g. forcing Auto on a fault) — is done by writing the DWORD tag from the PLC. The control re-renders automatically on the next acquisition cycle (default 1 s on Comfort, 500 ms on Professional, configurable under Connection → Update). To force an immediate redraw, write the tag from the PLC using "HMI_Interface".HMI_OptGroup_Mode := 16#0004; and ensure the tag's acquisition cycle is set to Continuous rather than On demand.
WinCC Flexible vs. TIA Portal: Behavior Differences
| Aspect | WinCC Flexible 2008 SP5 | TIA Portal WinCC Comfort / Advanced | TIA Portal WinCC Professional |
|---|---|---|---|
| Tag type for Selected Box | 32-bit, picker may accept INT for ≤ 16 boxes | DWORD / DINT only | DWORD / DINT only |
| Number of boxes | 1 – 32 | 1 – 32 | 1 – 32 |
| Default static index | 0x1 | 0x1 | 0x1 |
| Event language | VBScript only | VBScript only | VBScript + C# (UWP / Win32 RT) |
| Index text limit | 32 chars | 32 chars (multilingual via text list) | 32 chars (text list or direct) |
| Acquisition cycle default | 1 s | 1 s | 500 ms |
| Multi-language texts | Project languages | Project languages + text list | Project languages + text list |
Projects migrated from WinCC Flexible to TIA Portal WinCC Comfort keep the same wire format — no PLC changes are required. The Option Group object is binary-compatible: an HMI tag that was a DWORD in Flexible remains a DWORD in TIA Portal. Confirm against the official WinCC Flexible 2008 Option Group reference and the SIMATIC WinCC Professional / Comfort / Advanced programming manual before commissioning a migrated screen.
Verification Checklist
- Compile the HMI project with no warnings on the Option Group object. A warning on the Selected Box binding almost always means the tag type is wrong.
- Start RT. Open the watch table on the PLC side. Confirm that
HMI_OptGroup_Modereads1when option 1 is active and2when option 2 is active. - Click each option ten times. Confirm that the value never reads
0,3, or any value with two bits set. A non-zero transient during switching is acceptable only if it lasts less than one acquisition cycle. - Force a value from the PLC side (e.g.
MW = 4). The HMI should show option 3 active within one acquisition cycle. If the HMI does not update, the tag's Update property is set to On demand; switch it to Continuous. - Cycle power on the HMI. The option group reverts to its configured default (typically box 1). If the application requires power-loss retention, store the last selection in a retentive DB on the PLC and write it back to the HMI tag on startup.
- Verify operator authorization: log in at the required level and confirm the value changes; log out and confirm the control greys out and writes are silently dropped.
- Confirm in the HMI tag simulator or HMI trace that the bit pattern transitions cleanly: no spikes, no zero-during-transition unless the option group is configured to start at None.
Troubleshooting Matrix
| Symptom | Likely root cause | Fix |
|---|---|---|
| Compile error "Invalid data type" on Selected Box | BOOL or INT tag used where DWORD is required | Re-declare tag as DWORD / DINT |
| First option sets bit 1 but second option leaves bit 1 set | Two tags assigned to two different static indices of Selected Box | Assign only one tag at static index 0x1; remove the second assignment |
| PLC reads 0 in all states | Acquisition cycle paused or connection stopped | Check HMI connection status, verify Update = "On" in tag properties |
| Value flickers between 1 and 2 | Tag also written by PLC, or by another HMI screen | Remove the second writer, leave only the Option Group as source |
| Operator click does nothing | Operator control enable tag is FALSE | Check the enable tag from PLC, or remove the binding |
| Value 3 (bits 0 and 1 both set) | Tag width > 32 bits truncated, or a recipe writes a non-bitmask value | Use a separate DWORD, not a shared flag word |
| Wrong option highlighted | Number of boxes changed after configuration; text indices shifted | Re-enter Index 1 / Index 2 texts after changing box count |
| VBS event "Object required: 'SmartTags'" | VBS attached to a screen object that does not have a tag binding | Verify the Option Group has a tag on Selected Box before attaching the event |
| Control greyed out, no writes | Operator authorization level unmet | Lower the Authorization property or log in at the required level |
| HMI shows correct option but PLC sees different value | Two HMI connections to the same PLC, second one overwriting | Check Devices & Networks for duplicate S7 connections and remove the unused one |
| Compile error "Tag does not exist" after migration | Migrated project still references Flexible-only tag references | Re-assign the tag in the new TIA Portal tag table |
| Value stuck at last selection after reboot | Tag is also written by PLC startup OB, conflicting with HMI default | Coordinate: PLC writes the retentive last state, HMI renders it on first cycle |
Field-Proven Caveats
- Power-loss retention: the Option Group has no built-in retentive storage. If the panel reboots, the runtime re-initializes the control to box 1. Push the last selection from the PLC on startup if the application requires mode persistence.
- Multi-language: index texts can be entered directly in Properties → Texts, but the recommended approach for WinCC Comfort / Advanced / Professional is to use a Text list and bind the Option Group's text range to it. That way translators edit one list, not every screen. Reference the SIMATIC WinCC programming manual section on text lists for syntax.
- Operator authorization: write access from the panel to the PLC tag requires the operator to be at the configured authorization level. If writes are silently dropped, check the Authorization property on the screen and on the tag itself, and confirm the user is logged in at the required level (visible in the user view).
-
Tag length and pointer alignment: the HMI tag must be byte-aligned in the PLC. Bit tags (e.g.
DB.DBX0.1) cannot be aggregated into a DWORD view from the HMI side — declare the DWORD first, then expose individual bits from the PLC program. On S7-1500 with optimized DBs, use the symbolic bit-slicetag.%Xnnotation; on S7-300, declare the DWORD with standard (non-optimized) access. - Migration from ProTool: legacy ProTool projects with an Option Group assigned to an INT tag compile and run, but the operator only sees the first 16 boxes. Audit the box count and switch to DWORD before commissioning a migrated screen.
-
WebNavigator / WinCC Unified: the option group behavior is the same in WinCC Unified (V17+) with the additional option of an Output event in JavaScript. The VBS approach is not available in Unified; use the JavaScript analog and bind to the selectedIndex property of the
HMIOptionGroupcontrol. - Shared tag across multiple option groups: do not bind two Option Group controls to the same DWORD unless they are guaranteed to display the same selection. The runtime writes the last-clicked box's bit pattern, so a click on the first control will deselect the second. Use two distinct DWORDs if you need two independent groups in the same screen.
-
Audit trail: the operator's last click is not logged by the runtime. If the application requires 21 CFR Part 11-style audit, add a manual log entry in the VBS Change event using
HMIRuntime.Traceor push the value to a CSV log on the PLC side.
Diagnostics: Tag Monitor and HMI Trace
During commissioning, open the WinCC tag monitor (TIA Portal: Online → Tag monitor; WinCC Flexible: Tools → Tag Monitor) and add the HMI_OptGroup_Mode tag. Click each option and observe the value transitions: option 1 should produce a stable 1, option 2 a stable 2. A non-zero transient during switching is acceptable only if it lasts less than one acquisition cycle. For deeper analysis, enable the HMI trace (Online → Trace) and capture the bit pattern with a 100 ms sample period. The trace will show whether the runtime ever writes a value outside 1, 2, 4, 8, … — if it does, the tag is being written from another source.
On the PLC side, add the DWORD to a watch table with a 200 ms trigger and force values from the HMI to confirm round-trip behavior. A working configuration shows a clean 1 ↔ 2 transition with no dead time greater than one acquisition cycle.
Recipe Integration
When the Option Group selection must be saved and restored as part of a recipe, do not bind the recipe element directly to the Selected Box attribute. Instead, bind the Selected Box to a dedicated DWORD tag and add a small VBS handler on the recipe's Activate event that writes the recipe value to that DWORD. This keeps the bitmask encoding in one place and prevents a recipe with an invalid value (e.g. 7, which has three bits set) from corrupting the runtime state. Validate the recipe value in the handler: If (recipeValue And (recipeValue - 1)) <> 0 Then recipeValue = 1 rejects any value that is not a power of two and falls back to option 1.
Why does my BOOL tag show "Invalid data type" when I assign it to Selected Box?
The WinCC Option Group writes a 32-bit bitmask, not a single boolean. Change the tag type to DWORD or DINT in the HMI tag table. The integer value will be 1, 2, 4, 8, 16 … for boxes 1, 2, 3, 4, 5 — each option corresponds to one bit of the value.
How do I extract the individual option from the DWORD on the PLC side?
Use a bitwise AND with the option's mask: DB.HMI_OptGroup_Mode AND 16#0001 tests bit 0 (option 1), AND 16#0002 tests bit 1 (option 2), and so on. On S7-1500 with optimized access you can also use the symbolic bit-slice DB.HMI_OptGroup_Mode.%X0.
Do I need VBScript to set separate boolean tags in the PLC?
Not necessarily. The recommended approach is one DWORD on the HMI side and bitmask extraction in the PLC — no VBS required. Use VBS only when the PLC program cannot be modified and must see individual BOOLs. The VBS Change event handler reads the DWORD and writes the booleans on every operator click.
Can the PLC force the option group to a specific selection?
Yes. Write the corresponding bitmask value to the same DWORD tag the Option Group is bound to. The control re-renders on the next acquisition cycle (default 1 s on Comfort, 500 ms on Professional). Set the tag's Update property to Continuous for immediate redraw on PLC write.
How do I make the selection survive an HMI power cycle?
The Option Group has no built-in retentive storage. Store the last value in a retentive DB on the PLC (e.g. DB.LastMode : DWORD; RETAIN), and in the PLC startup OB write it back to the HMI tag: "HMI_Interface".HMI_OptGroup_Mode := "HMI_Interface".LastMode;. The runtime picks it up on the first acquisition cycle after boot.