TP2200 Comfort HMI: Writing Integer Values to S7-300 PLC Tags
When a SIMATIC TP2200 Comfort Panel hosts a grid of buttons (for example, a 10×10 numeric keypad with values 0–99) and each press must deposit a unique integer into a single SIMATIC S7-300 CPU tag, the engineering goal is to write distinct constants to a shared PLC variable from each button's "Press" event without manually wiring 100 separate BCD bit-set operations. The correct method is the WinCC Comfort SetTag system function, applied once to a selection of buttons and parameterised per instance by changing only the value that each button writes. This article describes the configuration in TIA Portal V16 / V17, the connection between the TP2200 Comfort and the S7-300 CPU 319-3 PN/DP, the bulk-editing technique that reduces 100 events to a single function call, and the diagnostics that confirm the integer reached the PLC.
1. Use Case and Engineering Goal
The original requirement is straightforward: an operator presses a single button on a 22-inch TP2200 Comfort Panel; the panel sends an integer in the range 0–99 to a fixed memory location in the S7-300 CPU; the PLC program uses that integer for downstream logic (recipe index selection, jog position number, machine code, etc.). The naïve implementation would be to set and reset bits in a BCD-encoded word for every button, but BCD encoding is unnecessary when the HMI runtime can write a 16-bit integer directly to a PLC tag.
The correct design pattern uses one HMI function (the SetTag system function) on the "Press" event of every button. The function is configured once with a common tag name and a per-button constant value. Because the HMI runtime handles the actual write, the application code in the S7-300 simply reads the integer like any other input value.
Engineering benefits of this approach over BCD bit manipulation:
- Single point of configuration — 100 buttons share one system function with parameterised values.
- No bit-to-integer conversion ladder logic required in the S7-300.
- No risk of writing conflicting bits if two events overlap.
- Direct mapping to a standard
INTdata type, matching the operator's mental model. - Easier to expand to 256 (0–255), 1000 (0–999) or signed values without restructuring.
2. Prerequisites
Confirm the following before starting the configuration. Mismatched firmware or TIA Portal versions are the most common cause of compile errors and undefined tag references in the TP2200 runtime.
| Component | Specification | Notes |
|---|---|---|
| SIMATIC HMI Panel | TP2200 Comfort (6AV2 124-1MC01-0AX0) | 22" widescreen, 16M colours, 1366 × 768; WinCC Comfort/Advanced runtime |
| PLC | SIMATIC S7-300 CPU 319-3 PN/DP (6ES7 318-3EL01-0AB0) | 2 MB work memory, integrated PN interface; supports S7 connection |
| Engineering software | TIA Portal V16 Update 7 or V17 Update 5 (or later) | WinCC Comfort V16/V17 with HMI SP for TP2200 image; TIA Portal V13 SP1 is the minimum |
| PLC programming | STEP 7 V16/V17 for S7-300 | S7-300 is a legacy family; confirm TIA version supports the 319-3 PN/DP firmware |
| Connection | PROFINET (preferred) or PROFIBUS DP | PROFINET uses the integrated PN port of the 319-3; address the TP2200 in the same subnet |
| PLC tag data type |
INT (16-bit signed) or WORD
|
For 0–99 use INT with range 0–32767; WORD is also acceptable |
Reference: Siemens Support: SIMATIC S7-300 CPU 319-3 PN/DP product information; Siemens Support: SIMATIC HMI TP2200 Comfort operating instructions.
3. Architecture and Tag Model
The data flow is simple: the operator presses a button on the TP2200; the HMI runtime executes a SetTag function that writes a constant value to a single PLC tag of type INT; the S7-300 CPU reads the tag cyclically in OB1 or in the relevant logic block.
3.1 PLC tag definition (S7-300)
Create a tag in the default tag table of the S7-300 CPU. The address choice depends on the data type and your memory layout:
| Tag name | Data type | Address | Range | Purpose |
|---|---|---|---|---|
iButtonValue |
INT | MW 100 | 0–99 (limited in HMI) | Holds the last button press |
bButtonPressed |
BOOL | M 200.0 | 0/1 | Edge-detected "press happened" flag (optional) |
iButtonAck |
INT | MW 102 | 0–99 | Mirror of iButtonValue used for handshake (optional) |
A typical STEP 7 V16/V17 declaration block:
DATA_BLOCK "DB_HMI_Interface"
STRUCT
iButtonValue : INT; // Last button value, 0..99
bButtonPressed : BOOL; // One-shot flag set on press
iButtonAck : INT; // Handshake echo (optional)
END_STRUCT;
END_DATA_BLOCK
For the simplest implementation, place the value in a bit-memory word (MW 100) and let OB1 pick it up directly.
3.2 HMI tag and connection
On the TP2200 side, the SetTag function references an HMI tag whose connection points to the S7-300 iButtonValue. TIA Portal typically creates the HMI tag automatically from the PLC tag if you drag the PLC tag into the HMI tag table. Confirm the following properties:
- Connection:
HMI_Connection_1(PROFINET, S7-300, slot 2 of the CPU rack) - Acquisition mode:
Cyclic in operation(default) orOn demand - Update cycle: 1 s (default) is acceptable for a 10×10 grid; reduce to 100 ms for jog-style applications
3.3 Why one shared tag, not 100 separate tags
It is tempting to create 100 PLC tags and assign each to a different button. That works but inflates the communication load (100 acquisitions per cycle) and bloats the tag table. A single shared INT tag with a per-button SetTag constant produces the same behavioural result with one tag and one read cycle.
4. The SetTag Method (Step-by-Step)
The SetTag system function is documented in the WinCC Comfort/Advanced system manual under "System functions for tags and values". It assigns a defined value to a tag — either an HMI tag or, if the HMI tag is a PLC tag, to the underlying PLC variable.
4.1 Open the screen that hosts the button grid
- In the TIA Portal project tree, expand
TP2200 > Screens. - Double-click the screen that contains the 10×10 button grid (for example,
Screen_Keypad). - Confirm the screen has been compiled successfully before adding events.
4.2 Add the SetTag function to the entire button selection
- In the editor, marquee-select all 100 buttons (Ctrl+A inside the screen, or use Shift+click to multi-select).
- Open the Inspector pane (View > Inspector) and switch to the Events tab.
- Click on the
Pressevent row — a small arrow appears; click it to open the function list. - Navigate to System functions > Tags and values > SetTag and double-click it. The function is added to the
Pressevent of all 100 buttons simultaneously.
SetTag, applies the function to every selected object. If you add SetTag to a single button first, the same function is added only to that one button and you would have to repeat the process 99 times.
4.3 Configure the tag and value parameters
After SetTag is in the event list, the function appears as:
SetTag(TagName, Value)
With all 100 buttons still selected, configure the parameters:
- Click on the
TagNamefield of the first button. A browser opens. - Select the HMI tag that points to the PLC's
iButtonValue(for example,HMI_Tag_iButtonValue). - The tag is now the same on every selected button. Do not change this field per button.
- Click on the
Valuefield of each button individually and enter the desired integer: 0 for the first button, 1 for the second, …, 99 for the hundredth. Use the Inspector to step through each button or click the buttons in the screen in numerical order while the Properties window is open.
Bulk-value entry via clipboard (optional):
- Open the Inspector's Events list for a single button.
- Copy the configured
SetTagline. - Select the next 99 buttons and paste the line into each
Pressevent. - Edit the
Valuefield per button.
4.4 Generate an automatic value sequence (advanced)
When the 100 values form a monotonic sequence 0–99, you can avoid manual entry by using a script that initialises the value fields from the button label. In TIA Portal V16/V17, the SetTag function supports a constant expression such as "Index" bound to the button's text. The pattern is:
- Add
SetTagto all buttons as in section 4.2. - For the
Valuefield, click the function browser and choose Constants > Multiplex tag > Index of the button if your runtime supports it, or use theButtonNumbersystem tag from WinCC. - Alternatively, write a small VBScript that iterates over the buttons and assigns the values programmatically. This is documented in the WinCC Comfort V16 scripting manual.
SetTag is in the order of 1–3 ms per call on a TP2200 Comfort with firmware V16.0.x. A 100-button event is therefore well below the HMI's 100 ms scan budget.
5. Alternative Approaches and When to Use Them
While SetTag is the standard solution, three other methods apply in specific contexts. Each is summarised with trade-offs so the engineer can choose deliberately.
5.1 Direct tag connection (no script)
Bind each button's Press event to a different PLC tag using the Set bit while key is pressed or Set value property in the button configuration. The PLC then reads 100 discrete bits and converts them with priority encoding. Use this only if the S7-300 has spare inputs/outputs and you need the HMI to inform the PLC which button was pressed by means of a 1-of-N code, for instance when the HMI is a redundant input device and a separate supervisor must arbitrate.
5.2 Indirect tagging with an array index
Define a PLC array aButtonTable[0..99] OF INT with the constants 0..99 preloaded, and use SetTagByIndex from the WinCC runtime to read from aButtonTable[i] where i is the button index. This pattern becomes useful when the values are dynamic (loaded from a recipe) and not hard-coded.
5.3 VBScript on the Press event
For complex logic, attach a global VBScript function to the Press event. The function receives the source object as Me and can extract a custom property to compute the value. Example:
Sub Button_Press(ByVal item)
Dim intValue
intValue = CInt(item.Text) ' assume button label is the value
SmartTags("iButtonValue") = intValue ' writes to the HMI tag bound to the PLC
End Sub
Reference: Siemens: WinCC Comfort V16/V17 VBScript reference.
6. Wiring, Connection, and Update Cycle
6.1 PROFINET connection
For an S7-300 CPU 319-3 PN/DP (6ES7 318-3EL01-0AB0), the integrated PROFINET port is on the CPU itself (X1, two-port switch). Configure as follows:
- Open Devices & Networks in TIA Portal.
- Drag the TP2200 to the same subnet as the CPU 319-3 PN.
- Assign IP addresses — for example, CPU 192.168.0.1, TP2200 192.168.0.2 — both with subnet mask 255.255.255.0.
- Interconnect the HMI connection to the S7-300 "PLC_1" with slot 2 (CPU 319-3 PN/DP occupies slot 2 of rack 0).
The PROFINET connection is the recommended transport for the S7-300 / TP2200 pairing because the CPU 319-3 has an integrated PN interface and no additional CP is required. For older 319-3 DP variants without PN, use the PROFIBUS DP interface and a CP 343-1 Lean for Ethernet on the HMI side, or use MPI as a fallback (slower, 187.5 kbit/s).
6.2 Update cycle and acquisition mode
Open the HMI connection in TIA Portal and verify:
-
Acquisition mode for tags:
Cyclic in operation(default 1 s) — adequate for 0–99 keypad presses where human reaction time dominates. - Acquisition cycle for the area pointer: 100 ms — applies to date/time and area pointer transfers.
- Connection resource on the S7-300: The 319-3 PN/DP provides 16 S7 connection resources; one is consumed by the TP2200 connection. Free resources remain for STEP 7 online, another HMI, or an OPC UA server.
7. PLC-Side Ladder Logic to Read the Integer
The PLC side does not need conversion. A minimal STEP 7 V16/V17 OB1 segment that reads the value and stores it on a positive edge:
// OB1 - Segment 1: Capture iButtonValue on press
A M 200.0 // bButtonPressed (set by HMI separately, optional)
FP M 200.1 // Edge memory bit
JCN END1
L MW 100 // Load iButtonValue from HMI
T MW 110 // Store as "last accepted value"
SET // Optional: latch acknowledgement
= M 200.2
END1: NOP 0
If you want a full handshake (HMI writes value, PLC acknowledges), use the SetBitWhileKeyPressed pattern combined with a Tag multiplexing or use a status word: HMI sets iButtonValue and toggles bButtonAck; PLC reads, processes, then writes back bButtonAck = 0 which the HMI uses to release the operator's button animation.
8. Verification and Diagnostics
After compilation and download, perform the following checks in order. Each test maps a specific failure mode to a corrective action.
- Online connection: In TIA Portal, click "Go online" with the TP2200 selected. The status indicator should turn green and the project number should match.
-
Tag visibility: Open an HMI watch table (
HMI Tags>Monitor) and confirmHMI_Tag_iButtonValueupdates in real time. -
PLC visibility: Open a STEP 7 watch table on the S7-300 with the tag
MW 100("Monitor/Modify"). Press a button on the TP2200. The watch table should show the integer within one update cycle (default 1 s). -
Function trace: Use the TP2200's Diagnostics screen (Start Center > Diagnostics). The "Events" log shows the last
SetTaginvocations and any tag-write errors. -
End-to-end test: Press each of the 100 buttons in turn. Verify the S7-300
MW 100shows the corresponding integer 0–99. A mismatch (off-by-one) usually indicates a labelling offset in the button order.
iButtonValue tag. The operator gets a visual confirmation that the value reached the PLC, and you can confirm whether the problem is in the HMI write or the PLC read.\div>
9. Troubleshooting Matrix
| Symptom | Likely root cause | Verification step | Fix |
|---|---|---|---|
| Button press does nothing |
SetTag added to Release event instead of Press
|
Inspector > Events shows the function on the wrong row | Move SetTag to the Press event |
| PLC reads only 0 | HMI tag not connected to a PLC tag; pure internal HMI variable | Watch table on HMI tag shows correct value; PLC sees 0 | Re-link the HMI tag to the S7-300 iButtonValue in the connection settings |
| PLC reads wrong values | Value parameter offset by one (button labelled 0 sends 1, etc.) | Compare button label and Value field for one button |
Re-enter the value parameters starting from 0 |
| Communication error on HMI | PROFINET IP mismatch or wrong slot assignment | TP2200 Start Center > Network > Ping to CPU IP | Set both ends to the same subnet and correct slot (CPU 319-3 = slot 2) |
| Compile error "tag not found" | HMI tag name typo in SetTag
|
Project-wide search for the tag | Reassign the tag in the function's parameter list |
| Values flicker between presses |
SetTag is in the Change event that fires repeatedly |
Inspector > Events shows Change selected | Switch to Press (one-shot) |
| Tag update too slow (> 1 s) | Default 1 s acquisition cycle | HMI tag properties > Update cycle | Lower to 100 ms for fast jog-style applications |
| S7-300 reports resource error | CPU connection resource exhausted (more than 16 S7 connections) | STEP 7 online > CPU diagnostic buffer | Reduce number of HMI / OPC UA / PG connections; combine tags onto one HMI |
| Integer range overflow | Value entered exceeds INT range or signed interpretation |
Watch table shows negative number | Use 0–99 only, or change PLC tag to WORD for unsigned 16-bit |
10. Extended Patterns: Building a 10×10 Grid Efficiently
When the grid is a strict 10×10 keypad, four engineering refinements cut engineering time from hours to minutes.
10.1 Use the keypad faceplate template
WinCC Comfort ships a numeric input faceplate in the "Controls > My controls > Numeric input" library. Drop one instance on the screen, set its range to 0–99, and wire its output value to iButtonValue. No 100-button configuration is required.
10.2 Use a screen with a single multiplexed button
Build a 4×3 numeric pad (digits 0–9, clear, enter). The PLC builds the multi-digit value by shifting and adding. This is the standard pattern for full numeric entry and uses 12 buttons instead of 100. The PLC program accumulates: iValue := (iValue * 10) + iDigit.
10.3 Use the "Index" property of the button
For grids laid out in a loop, give each button an Index property (0..99). The SetTag function accepts a tag as the Value parameter; bind it to the Index of the source object using a tag-multiplex expression. The result is automatic sequencing without manual data entry.
10.4 Generate a configuration script
Use the TIA Portal Openness API (C#) to script the creation of 100 buttons with their SetTag events and value parameters. This is the right approach when the keypad is replicated across many screens or many HMI stations. The Openness API is documented at Siemens Support: TIA Portal Openness.
11. Performance and Memory Considerations
| Resource | Typical value on TP2200 Comfort V16.0 | Notes |
|---|---|---|
| Active screen memory for 100 buttons | ~ 250 kB | Each button object ~ 2.5 kB after compilation |
| SetTag execution per call | 1–3 ms | Includes tag-write queue dispatch |
| PROFINET cycle on the S7 connection | 1 s default, 100 ms minimum | Set in HMI tag properties |
| S7-300 CPU 319-3 work memory usage | + 0.4 kB for one INT + 2 bits |
Negligible impact |
| PROFINET frame size for one tag write | ~ 30 bytes per cycle | Including PROFINET overhead |
12. Safety and Best-Practice Notes
- Use screen-level authorisation on the keypad screen to prevent unauthorised operators from changing values (Start Center > Users).
- Set the HMI tag's acquisition mode to "On demand" for non-critical values to reduce PROFINET traffic.
- Enable audit trail on the value tag for GMP-compliant installations.
- Always verify the value range in the PLC: clamp the integer to 0–99 with a
LIMITinstruction before using it as an array index.
13. Related Siemens Documentation
- Siemens Support: SIMATIC S7-300 / S7-300F system manual — connection resources, diagnostics
- Siemens Support: SIMATIC HMI TP2200 Comfort operating instructions — hardware, firmware, image
-
Siemens Support: WinCC Comfort V16 system manual — system functions including
SetTag - Siemens Support: STEP 7 V16 / V17 in TIA Portal — S7-300 programming reference
14. FAQ
What is the data type of the PLC tag that receives the integer from the TP2200?
Use INT (16-bit signed) for values 0–99, or WORD (16-bit unsigned) if you also need bit-level access. Both map cleanly to a WinCC Comfort SetTag value parameter and to PROFINET S7 communication.
Do I need to create 100 separate PLC tags for 100 buttons?
No. A single shared PLC tag of type INT is enough. Each button's SetTag writes a different constant value to the same tag, and the S7-300 reads that one tag. This keeps the tag table small and the PROFINET cycle to a single write per press.
Can I avoid configuring 100 events manually?
Yes. In TIA Portal, marquee-select all 100 buttons before adding the SetTag system function. The function is applied to every selected button at once. You then only have to set the Value parameter per button, which is one click per button. For fully automatic sequencing, use the TIA Portal Openness API or a VBScript that iterates over the buttons.
Is the BCD bit-set approach ever justified?
Rarely. BCD encoding is appropriate only when the HMI must write to a 16-bit field where each button manipulates a specific bit (legacy migration of hand-wired panels, or systems that share a single physical wire pair). For modern HMI-to-PLC communication over PROFINET, SetTag with an INT tag is faster, simpler, and easier to maintain.
Why does my S7-300 see the value only after a delay?
The default HMI tag acquisition cycle is 1 s. Open the HMI tag's properties in TIA Portal and lower the cycle to 100 ms (the minimum supported on TP2200 Comfort). Also confirm that the HMI connection is online (Start Center > Connections) and that the PROFINET link to the CPU 319-3 PN/DP is up.
Can I use this pattern with a CPU 319F-3 PN/DP for safety-related logic?
You can use the HMI to send a non-safety value (for example, a recipe number) to a CPU 319F-3 PN/DP, but the safety logic itself must be driven by fail-safe I/O and a certified F-program, never by an HMI write. The TP2200 is a visualisation device and is not safety-certified.