Overview: The Runtime Tag Binding Problem
Operators in many WinCC screens need to inspect or modify the value of an arbitrary process tag whose identity is decided at runtime - commonly driven by a listbox, combobox, or selection tree of parameter names. The naive approach of writing a value through SetOutputValue only pushes the current value once; the I/O Field does not track subsequent tag changes, and the operator cannot edit the live tag value through the field.
The correct solution is to create a tag connection (a dynamic link) between the I/O Field's OutputValue (WinCC V7) or ProcessValue (WinCC Unified) property and the chosen process tag. In WinCC this is exposed as a script-callable API:
-
WinCC V7 (Classic) C-Editor:
SetLink/GetLinkfunctions. -
WinCC V7 VBS Editor: Direct write to the screen-item property via the
HMIRuntime/ScreenItemsobject model. -
WinCC Unified V20 (TIA Portal): Tag dynamization through
ProcessValue.SetTagName(...)and configuration-side tag binding under Properties → General → Process value.
This document walks through each environment with verified function signatures, complete code, update-cycle handling, and field-proven commissioning checks.
Architecture: How an I/O Field Tag Link Works
An I/O Field is a normal screen object with three relevant properties:
| Platform | Property | Purpose |
|---|---|---|
| WinCC V7 | OutputValue |
Bidirectional dynamic tag (read/write). |
| WinCC V7 | Output |
Static text fallback (no link). |
| WinCC Unified | ProcessValue |
Bidirectional dynamic tag (read/write). |
| WinCC Unified | ProcessValueMode |
Selects Constant / Tag / Script dynamization. |
A link is the runtime container that binds the property to (a) a tag name, (b) an acquisition/refresh cycle, and (c) the data type interpretation. Once a link exists, the visualization reflects the tag value every cycle, and operator edits are written back through the same link - identical behavior to a statically-configured link.
Environment Prerequisites
| Tool | Required Version / Component |
|---|---|
| WinCC V7 (Classic) | WinCC V7.4 SP1 or later; C-Editor + VBS-Editor licensed. |
| WinCC Unified (TIA Portal) | TIA Portal V20 with WinCC Unified runtime; JavaScript or VBS runtime enabled. |
| Visualization PC | RT (Runtime) license matching the count of I/O Fields being dynamically re-linked (default license consumption is 0 unless tags were created externally). |
| Project Tags | HMI tags defined in the project's tag management, or address tags pointing to a connected PLC (S7-1200/1500, Modbus, OPC UA). |
Verify the C-Editor and VBS-Editor are activated under Project → Properties → Options. On WinCC Unified, scripting must be enabled under Runtime settings → Scripting.
WinCC V7 C-Script: SetLink and GetLink
The C-Editor exposes two internal C functions that mutate and inspect an object-property tag link. Both are documented in the WinCC V7 Help under Internal Functions → Graphics → Link.
Function signatures
BOOL SetLink( LPCTSTR lpszPictureName,
LPCTSTR lpszObjectName,
LPCTSTR lpszPropertyName,
LPCTSTR lpszTagName);
DWORD GetLink( LPCTSTR lpszPictureName,
LPCTSTR lpszObjectName,
LPCTSTR lpszPropertyName,
DWORD dwSize,
LPTSTR lpszVariable,
LPDWORD lpdwResult);
| Parameter | Meaning |
|---|---|
lpszPictureName |
Picture file name including the .PDL extension. Pass NULL or the active picture's name when scripting on the current picture. |
lpszObjectName |
Object name as defined in Graphics Designer (case-sensitive). |
lpszPropertyName |
For an I/O Field, OutputValue creates a dynamic tag link; Output is static text. |
lpszTagName |
Full tag name string from the tag manager. Project tags need no prefix. Internal tags are acceptable. |
dwSize / lpszVariable
|
Output buffer for GetLink; allocate at least MAX (256) TCHARs. |
lpdwResult |
Receives link status code: 0 = no link, 1 = constant, 2 = tag link, 3 = script link. |
Complete C example - listbox-driven parameter selection
/* OnClick event handler of a listbox that triggers a re-link */
void OnClick(char* lpszPictureName, char* lpszObjectName)
{
BOOL bRet;
char szSelText[256] = "";
/* Retrieve the currently selected text item from the listbox */
bRet = GetText(lpszPictureName, "ListBox1", "Text", 256, szSelText);
if (bRet == FALSE) { printf("GetText failed: %s\r\n", GetLastError()); return; }
/* Bind the I/O Field's OutputValue to the chosen tag */
bRet = SetLink(lpszPictureName, "IOField_Param", "OutputValue", szSelText);
if (bRet == FALSE) { printf("SetLink failed: %s\r\n", GetLastError()); return; }
/* Confirmation - read back the link state */
DWORD dwResult = 0;
char szLinkedTag[256] = "";
GetLink(lpszPictureName, "IOField_Param", "OutputValue", 256, szLinkedTag, &dwResult);
printf("Link=%s state=%lu\r\n", szLinkedTag, dwResult);
}
The I/O Field immediately begins displaying the new tag and refreshes on every acquisition cycle of the tag's configured cycle (see section Update Cycle Management).
SetLink with a non-existent tag name returns FALSE with WinCC system error 0x800xxxxx logged in WinCC_SysLog.Log. Pre-validate the tag with TlgGetNumberOfTagsAvailable + SSMGetTag if the selection list is user-modifiable.Update Cycle Management
Both screen-object links and tags carry an update cycle. Without configuring the cycle, the runtime falls back to the picture's standard cycle (default 1 s).
Available update cycles
| Cycle | Typical Use |
|---|---|
| 250 ms | Fast analog values, position feedback. |
| 500 ms | Setpoint entry, mid-rate numeric values. |
| 1 s | Default picture cycle - acceptable for most operator entries. |
| 2 s / 5 s / 10 s | Slow diagnostics counters, totals. |
| On change | Event-driven tags - lowest CPU load. |
| Upon picture change | One-shot value at navigation time. |
Setting the cycle programmatically
The C-Editor cycle API includes:
/* Set cycle of an existing tag link on a screen-object property */
bRet = SetLink(lpszPictureName, "IOField_Param", "OutputValue", "MyTagName", "500 ms");
/* Where supported (WinCC 7.5+), pass cycle name as 5th argument. If unsupported,
the cycle is inherited from the tag's configured acquisition cycle in the
tag manager. */
When changing cycles at runtime the script must re-issue SetLink; the cycle parameter is part of the link descriptor and is not edited in place.
WinCC V7 VBScript: Direct Property Assignment
The VBS script equivalent avoids SetLink/GetLink because the VBS object model permits direct write to the OutputValue property with a tag-name string. The runtime implicitly calls the underlying link creation routines.
Complete VBS example
' OnClick of the parameter listbox
Sub OnClick(ByVal Item, ByVal value)
Dim szTagName
szTagName = ""
' Read selected text from the listbox
Dim lb
Set lb = ScreenItems("ListBox1")
szTagName = lb.Text
' Validate non-empty
If Len(szTagName) = 0 Then
ShowSystemAlarm("No parameter selected")
Exit Sub
End If
' Bind I/O Field
Dim iof
Set iof = ScreenItems("IOField_Param")
iof.OutputValue = szTagName ' dynamic link created automatically
End Sub
Reading back the link in VBS
Dim iof, szLinked, bLink
Set iof = ScreenItems("IOField_Param")
szLinked = iof.OutputValue ' returns the linked tag name string
bLink = iof.IsLinked("OutputValue") ' True / False
VBS offers no direct handle on the update cycle; the field inherits the tag's configured cycle. The standard cycle of the picture object can be edited via Properties → Misc → Update Cycle before the tag is linked.
WinCC Unified V20 (TIA Portal): Configuration-Based Binding
WinCC Unified uses the ProcessValue property of I/O Field-like screen objects. Static binding through TIA Portal is the documented primary path; the official V20 example walks the inspector procedure:
- Select the I/O Field on the canvas.
- In the Inspector window, expand Properties → General → Process value.
- In the Dynamization column, click the empty stub next to the value field.
- Select the entry Tag from the dropdown list.
- Pick an HMI tag from the tag selector.
The full official procedure is documented at Example: Configuring an IO field (RT Unified) - TIA Portal V20.
Configuration parameters visible in Inspector
| Parameter | Effect |
|---|---|
| Tag name | Fully qualified HMI tag name including namespace path. |
| Acquisition cycle | Polling interval the runtime reads the tag source. |
| Quality code | Enables visualization of "bad quality" operator warning. |
| Reset / Initial value | Cold-start value if no source value is present. |
WinCC Unified V20 Scripting: ProcessValue Mutators
Unified provides object handles via Screen.Items and item-typed mutators on ProcessValue. The runtime supports both JavaScript (ES2017) and VB.
JavaScript example (RT script action triggered by parameter listbox onClick)
// Exports function "OnSelectParameter" linked via event-mapping
import { Screen } from 'M_HMI/RT/Classes';
export function OnSelectParameter(selectedName) {
if (!selectedName || typeof selectedName !== 'string') {
import('M_HMI/RT/Functions').then(F => F.ShowSystemAlarm("No parameter selected"));
return;
}
const iof = Screen.Items.Element("IOField_Param");
if (iof === null) { throw new Error("I/O Field not found"); }
// Property assignments on Unified invoke the dynamization engine.
iof.ProcessValue.Tag = selectedName;
iof.ProcessValue.Cycle = '500 ms'; // optional cycle override
iof.ProcessValueMode = 1; // 1 = tag binding
}
VB example
Public Sub OnSelectParameter(sTag As String)
If Len(sTag) = 0 Then
ShowSystemAlarm("No parameter selected")
Exit Sub
End If
Dim iof = Screen.Items.Element("IOField_Param")
If iof Is Nothing Then Throw New System.Exception("I/O Field not found")
iof.ProcessValue.Tag = sTag
iof.ProcessValue.Cycle = "500 ms"
End Sub
Reading back the link
// JavaScript
const iof = Screen.Items.Element("IOField_Param");
const linkName = iof.ProcessValue.Tag;
const linkCycle = iof.ProcessValue.Cycle;
const linkState = iof.ProcessValueMode; // 0 constant, 1 tag, 2 script
ProcessValue.Tag, ProcessValue.Cycle, and ProcessValueMode are valid for V20; verify against your installed version of TIA Help as object models may differ between V17, V18, V19, and V20. Confirm with the engineering tool's IntelliSense on your specific firmware.Pattern: RT Parameter Listbox + I/O Field (Step-by-Step Procedure)
This procedure builds a complete runtime-switchable parameter viewer using the V7 C-Editor; the VBS and Unified equivalents share the same event flow.
-
Configure the I/O Field. In Graphics Designer drop a Bar IO Field named
IOField_Param. Under Properties → Output, set Data format to decimal or hex as required; cycle is initially 1 s. -
Configure the parameter listbox. Drop a List Box named
ListBox1. Populate Selection entries with the tag names the operator may choose, for exampleMotor1_Speed,Motor1_Torque,Tank_Level. -
Bind listbox events. Select the listbox, open Properties → Events → Selection changed, set action to
C Actionand open the script editor. - Paste the C script from the section WinCC V7 C-Script above. Compile with F7.
- Tag-side setup. In Tag Manager confirm each candidate tag has an Acquisition cycle matching the desired refresh (250 ms for active control loops, 1-2 s for diagnostic values).
- Compile the picture (Right-click the picture → Compile) and download to the RT-PC.
- Activate Runtime and verify by selecting different parameters; the IO Field must show their values and accept operator entries that immediately write back.
Common Errors and Diagnostics Matrix
| Symptom | Root Cause | Remedy |
|---|---|---|
IO Field always displays # (undefined) after SetLink. |
Tag name misspelled or not loaded in RT. | Check tag manager; confirm tag appears in RT under Tags view. |
SetLink returns FALSE with system log error 0x80090032. |
Object not in current picture, picture not activated. | Pass full picture name; confirm RT is running; verify object name. |
| Operator writes to IO Field are not persisted. | IO Field Configuration → Data Input disabled. | Properties → Input/Output → Set "Data input" / "Operator input" permission. |
| Value flickers / shows last value 2 s after operator entry. | Update cycle set too low (On Change but operator entry is forced through cycle). | Switch to 250 ms or add the operator write through an event-driven script. |
VBS error "Object variable not set" on ScreenItems("IOField_Param"). |
Wrong object name or object belongs to a different picture. | Activate the target picture; verify case-sensitive name in Graphics Designer. |
Unified: ProcessValue.Tag assignment silently ignored. |
Scripting not enabled in runtime; project not rebuilt. | Project → Compile → Rebuild all; confirm Runtime → Scripting is "Enabled". |
Verification Procedure
- Open Graphics Designer in simulated Runtime (Tools → Runtime Simulator).
- Switch each listbox entry; visually confirm the IO Field value updates within one cycle.
- Edit the IO Field and confirm the underlying PLC tag updates by triggering a read in TIA Online / S7-PCT / PLC browse.
- Log the link state with a debug
printf/ShowSystemAlarmon the first frame to confirm the link, then disable logs. - Cycle test: change the parameter choice rapidly (1 s cadence) and confirm no exception dialogs in WinCC_SysLog.
- Final validation: power-cycle the RT-PC; on reboot, the IO Field should restore its last linked tag (Unified: persist via
ProcessValueModetag, V7: configure persistent RT storage for the parameter name).
Security, Performance, and Best Practices
-
Validate any tag name supplied by an operator or external file.
SetLinkwith an arbitrary string is a method for unauthenticated tag access; in safety-related screens, restrict the candidate list to a hard-coded array and reject strings not in the array. -
Avoid
OnClickspam. Put a 250 ms debounce on the parameter change event to prevent the link engine from re-binding on every selection click. - Group multiple links into one script - re-linking all ten I/O Fields on screen to switch from "View Alarms" mode to "View Diagnostics" mode is more efficient in one C action than ten event handlers.
- Watch CPU. Each high-frequency cycle tag costs IO. If the operator's selection changes a high-rate tag, the picture cycle should be raised or the high-rate tag should be assigned a different cycle after link.
- Centralize tag-name maps. Maintain a mapping table of display-string to internal tag name in C/VBS or in a script-side dictionary; never concatenate raw screen objects. Raw concatenation enables injection ("MyTag;ERP_CONNECTION").
What is the difference between SetLink and direct property assignment in WinCC V7?
SetLink is the internal C function that creates or replaces the dynamic link to a tag and returns a Boolean status; it is accessible only from the C-Editor. In VBS the equivalent is assigning the tag name string to the I/O Field's OutputValue property - the runtime invokes the same link engine internally. C also provides GetLink, which returns the current linked tag name and a state code (0 none, 2 tag link, 3 script link).
Can I also change the update cycle programmatically via SetLink?
Yes, in WinCC 7.4 SP1 and later a cycle-name variant of SetLink exists where the fifth argument supplies a cycle string such as "500 ms". If your C-Compiler does not expose this overload, the cycle is inherited from the tag's acquisition cycle in tag management. For Unified, assign iof.ProcessValue.Cycle = "500 ms" after the tag is bound.
Why does the IO Field flicker between old and new values after re-link?
The flicker occurs when the link is replaced while the previous cycle update is in progress. In VBS re-enter the value once after setting the link, or call SetLink from a debounced single-event so the runtime completes one cycle before the next re-link. Update the picture-standard cycle to match the new tag's acquisition cycle before re-linking to avoid clock-skew flicker.
Does dynamic re-linking consume an additional RT license?
No. Dynamic linking reuses existing licenses allocated by the project's static tags. It does not create new external tags per re-link. However, importing a tag from a tag library at runtime does carry licensing implications matching the library license - keep all candidate tags statically present in the tag manager.
Is this approach deprecated in WinCC Unified V20?
No. The V20 documentation explicitly covers configuring I/O Field tag dynamization through Inspector (Properties → General → Process value → Dynamization → Tag), and V20 scriptable mutators ProcessValue.Tag, ProcessValue.Cycle, and ProcessValueMode remain supported for runtime scenarios such as parameter viewers. Verify exact property names against IntelliSense in your installed TIA Portal build, as object models may differ between V17-V20.