WinCC Flexible TP177B: Animating a Button from Two Boolean Tags

David Krause13 min read
HMI ProgrammingSiemensTutorial / 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

Problem Statement

A SIMATIC TP177B Color panel (6" STN, 320×240) configured with WinCC flexible exposes only one tag per animation property on an HMI object. When a designer needs the appearance of a button — background color, foreground color, or visibility — to react to the combined state of two discrete inputs from the SIMATIC S7-300, the standard "Appearance → Tag" dialog cannot express a logical AND, OR, or XOR of two booleans. The result is that a request such as "blue when both inputs are FALSE, grey when only input B is TRUE, black when only input A is TRUE, green when both are TRUE" cannot be built directly inside the HMI configuration.

This article documents three engineering methods that solve the problem on a TP177B running WinCC flexible 2005 SP1 / 2007 / 2008 SP2 communicating with a SIMATIC S7-300 (CPU 31x) over MPI or PROFIBUS DP. The recommended solution is bit-packing on the PLC side because it consumes the least runtime resources on the panel and works on every firmware variant of the TP177B.

Why WinCC flexible Restricts Each Property to a Single Tag

The TP177B runtime image executes compiled animation expressions against a fixed polling cycle (default 1 s, configurable down to 250 ms). Each visible property of an HMI object is bound to one and only one value source at compile time, and the runtime evaluator expects either a numeric range table (for INT/DINT values) or a binary on/off mapping (for BOOL values). The compiler does not parse boolean expressions such as Tag1 AND Tag2 or arithmetic such as Tag1 * 2 + Tag2. The complete list of bindable property types in WinCC flexible 2008 SP2 is documented in the manual entry "Animating an object" and is limited to:

  • Appearance: Background color, foreground color, blinking (per tag), visibility (BOOL)
  • Motion: Horizontal/vertical position (INT, DINT, REAL)
  • Direct movement: X position, Y position, width, height (INT)
  • Operation: Enable, disable, "appears pressed" (BOOL)

Each row above accepts exactly one tag. To animate on multiple booleans you must either (a) merge the booleans into a single numeric value upstream of the panel, or (b) use a VBScript on the HMI that watches both tags and writes a third tag. Both approaches are covered below.

Note: WinCC Professional (TIA Portal) and WinCC Unified handle multi-tag animations natively through dynamic SVGs and JavaScript expression bindings. The methods described here apply specifically to the TP177B / TP170 / TP270 / MP270 generation running WinCC flexible 2005–2008 SP2.

Solution Architecture: Pack Booleans into a Word

The cleanest engineering pattern is to combine the two source booleans in the STEP 7 program into a single INT (or WORD) tag whose low two bits represent the discrete state of the pair. The combined tag is then exported to the HMI as a normal process tag. The TP177B needs only one polling variable, one area pointer, and one resource block — exactly what WinCC flexible expects.

Truth Table Mapping

Tag1 (bit 0) Tag2 (bit 1) Combined INT value Bit pattern (b1 b0) Requested color
0 (FALSE) 0 (FALSE) 0 00 Blue
1 (TRUE) 0 (FALSE) 1 01 Black
0 (FALSE) 1 (TRUE) 2 10 Grey
1 (TRUE) 1 (TRUE) 3 11 Green

When 2 booleans drive 1 color, the design space is exactly 2² = 4 states. The four-state mapping can therefore be expressed as a single INT with the value ranges 0, 1, 2, 3. Each color is bound to one numeric range in WinCC flexible's "Range" dialog.

STEP 7 Implementation (Recommended Method)

Hardware Assumptions

  • S7-300 CPU 313C, 314, 315-2 DP, 317-2 DP, or 319-3 PN/DP
  • STEP 7 V5.5 + SP2 (or V5.4 + SP5 for legacy systems)
  • TP177B Color 6" (6AV6 642-0BC01-1AX1) firmware ≥ 1.1.2
  • MPI 187.5 kbit/s or PROFIBUS DP 1.5 Mbit/s link

STL Program in OB1 / OB35

Insert the following segment in the cyclic OB1 (or in OB35 if you want a deterministic 100 ms update). It packs the two booleans Tag1_Bool and Tag2_Bool into the low bits of MW200, which is then exported to the HMI as the integer tag HMI_CombinedState.

// Pack two booleans into MW200 (HMI tag "HMI_CombinedState")
// Bit 0 = Tag1_Bool      (e.g., valve open feedback)
// Bit 1 = Tag2_Bool      (e.g., auto-mode active)

      A     "Tag1_Bool"              // Read boolean 1
      =     M     200.0              // Write into bit 0 of MW200

      A     "Tag2_Bool"              // Read boolean 2
      =     M     200.1              // Write into bit 1 of MW200

      L     MW   200                 // Load combined word
      T     "HMI_CombinedState"      // Transfer to HMI tag (INT DB / PI / MW)

LAD Equivalent

|   "Tag1_Bool"      --|=|--( M 200.0 )    // Assign boolean 1 to bit 0
|   "Tag2_Bool"      --|=|--( M 200.1 )    // Assign boolean 2 to bit 1
|                                    |
|   MW200 ----------[ MOVE ]--> "HMI_CombinedState"    // Optional explicit copy

SCL Equivalent (STEP 7 V5.5 / SCL)

// In OB1 / OB35 / FC100 (cyclic 100 ms call)
IF "Tag1_Bool" THEN
    "HMI_CombinedState".BIT0 := TRUE;
ELSE
    "HMI_CombinedState".BIT0 := FALSE;
END_IF;

IF "Tag2_Bool" THEN
    "HMI_CombinedState".BIT1 := TRUE;
ELSE
    "HMI_CombinedState".BIT1 := FALSE;
END_IF;
Why use M-bit memory instead of directly setting DB bits? M-memory (M 0.0 ... M 255.7) is always available on every S7-300 CPU, requires no DB allocation, and survives a CPU STOP-to-RUN transition with no initialisation issues. For larger projects, allocate the combined state inside a shared DB (e.g., DB100.DBX0.0 / DBX0.1) so the symbol table can carry operator-friendly names like "HMI_ValveStatus_W" of type INT.

WinCC flexible Configuration for Color Animation

  1. Open the project in WinCC flexible 2008 SP2. From the project tree, select Communication → Connections and confirm the S7-300 station is reachable. Verify the area pointer for "Date/Time" and "Coordination" are checked so that the tag refresh does not stall.
  2. Open Tags → SIMATIC S7-300 → and create a new tag:
      • Name: HMI_CombinedState
      • PLC tag: MW200 (or your DB symbol)
      • Data type: INT
      • Acquisition mode: Cyclic continuous
      • Cycle: 1 s (default; 500 ms for fast colour transitions)
  3. On the screen, drop a Button object. Double-click the button to open its Properties dialog.
  4. Select the Appearance tab and locate the Background Color property.
  5. Click the small arrow icon next to "Dynamic" and choose Range from the dropdown.
  6. In the range table that appears, define four ranges as in the table below.

Range Configuration Table

Range Constant value Background color State meaning
Value range 1 0 RGB 0, 0, 255 (Blue) Both booleans FALSE
Value range 2 1 RGB 0, 0, 0 (Black) Tag1 TRUE only
Value range 3 2 RGB 192, 192, 192 (Grey) Tag2 TRUE only
Value range 4 3 RGB 0, 255, 0 (Green) Both booleans TRUE

For each row, set the Type to "Greater than or equal to" with a Range from and Range to that include only the discrete integer. Because the combined INT will only ever take values 0, 1, 2, or 3, each range can be a single point using the inclusive lower bound. Values outside 0–3 (which cannot occur by construction) inherit the property's default color.

Alternative Method 2: HMI-Side Internal Tag with VBScript

WinCC flexible 2005 SP1 and later expose a VBScript runtime on the TP177B. A small script can watch both source booleans and write a derived integer into an internal tag (a tag not connected to the PLC). The internal tag then drives the animation exactly as in Method 1. This method is preferred when the PLC program is locked, certified, or owned by a different vendor.

Step 1: Declare Three Tags

Tag name Source Type Trigger
PLC_Tag1_Bool External (S7-300) BOOL Cyclic
PLC_Tag2_Bool External (S7-300) BOOL Cyclic
HMI_CombinedState Internal INT OnChange via script

Step 2: Write the VBScript

Open Scripts → Project Scripts and add a new procedure:

' Recalculate_CombinedState
' Triggered by "OnChange" of PLC_Tag1_Bool or PLC_Tag2_Bool

Dim iVal As Integer

If SmartTags("PLC_Tag1_Bool").Value = True Then
    iVal = 1
Else
    iVal = 0
End If

If SmartTags("PLC_Tag2_Bool").Value = True Then
    iVal = iVal + 2
End If

SmartTags("HMI_CombinedState").Value = iVal

Step 3: Wire the Event

  1. Open the Properties of PLC_Tag1_Bool, go to Events → Change value.
  2. Assign the VBScript Recalculate_CombinedState.
  3. Repeat for PLC_Tag2_Bool.

On every change of either input, the script fires, computes 0–3, and writes the internal tag. The color animation then reacts on the next cycle. Caveat: the VBScript runtime on the TP177B Color is single-threaded and synchronous; scripts longer than ~50 ms can stall the refresh of other tags. Keep the script trivial — no I/O, no file access.

Alternative Method 3: Pre-Computed FC Block on the PLC

For larger logic blocks that already combine many booleans (e.g., a valve status word with eight bits representing open, closed, fault, auto, manual, remote, interlock OK, and healthy), use a dedicated FC that writes a fully populated status word each cycle. The HMI receives a single INT or WORD that contains all the state information. This is the same pattern used in PCS 7 APL blocks and is the recommended pattern for plants with >20 HMI tags per device.

FC100 — BuildValveStatus (SCL)

FUNCTION FC100 : VOID
// Input: 16 booleans representing valve / motor status bits
// Output: VALVE_STATUS_WORD (INT) exported to HMI
VAR_INPUT
    bOpen         : BOOL;   // Bit 0
    bFault        : BOOL;   // Bit 1
    bAuto         : BOOL;   // Bit 2
    bMan          : BOOL;   // Bit 3
    bRemote       : BOOL;   // Bit 4
    bInterlockOK  : BOOL;   // Bit 5
    bHealthy      : BOOL;   // Bit 6
END_VAR
BEGIN
    "VALVE_STATUS_WORD".BIT0 := bOpen;
    "VALVE_STATUS_WORD".BIT1 := bFault;
    "VALVE_STATUS_WORD".BIT2 := bAuto;
    "VALVE_STATUS_WORD".BIT3 := bMan;
    "VALVE_STATUS_WORD".BIT4 := bRemote;
    "VALVE_STATUS_WORD".BIT5 := bInterlockOK;
    "VALVE_STATUS_WORD".BIT6 := bHealthy;
END_FUNCTION

Call FC100 from OB35 with a 100 ms update. The HMI then uses a single status word to drive multiple animations (color, blink, visibility) for the same valve faceplate, and the same word can be re-used by the WinCC flexible trend view to log the state history.

Verification Procedure on the TP177B

  1. Compile the STEP 7 program, download to the S7-300 CPU, and place the CPU in RUN.
  2. In WinCC flexible, compile the project (Project → Compiler → Check consistency → Generate).
  3. Transfer the *.fwx runtime image to the TP177B via MPI/PROFIBUS or Ethernet (RC) using the "Transfer" dialog. Enable "Remote control" if downloading over MPI.
  4. Open the screen containing the animated button. Press the button once to ensure focus is on the panel.
  5. Use STEP 7 Monitor/Modify to force Tag1_Bool and Tag2_Bool through all four combinations. Verify that the button color updates within one acquisition cycle (≤1 s with default cycle).
  6. Disconnect the forcing and verify that real-time transitions occur at the expected rate. Check the PLC scan time in PLC → Module Information → Scan Time; if the scan time exceeds 100 ms, lower the HMI acquisition cycle to 500 ms or 1 s only.

Functional Test Checklist

Step Force Tag1 Force Tag2 Expected MW200 Expected color Pass / Fail
1 FALSE FALSE 0 Blue
2 TRUE FALSE 1 Black
3 FALSE TRUE 2 Grey
4 TRUE TRUE 3 Green

Troubleshooting Matrix

Symptom on TP177B Probable cause Diagnostic step Fix
Button stays on default color Tag not connected; area pointer missing WinCC flexible → Tools → Tag simulation; verify the value updates when forcing Re-check the connection and area pointer in the S7-300 station; confirm PLC tag address matches MW200
Color "jumps" past intermediate state Acquisition cycle too fast relative to PLC scan Use a trend view on MW200; observe update rate Increase HMI cycle to 1 s, or move the packing logic into OB35 with a 100 ms cycle
Color flickers between two states Input booleans are unstable (debouncing needed) Force a constant TRUE; check the bit in VAT table Add an on-delay timer (S_ODT) before packing the boolean into MW200
Color stays on Blue even after both inputs TRUE PLC tag set as BOOL, not INT Check tag definition in WinCC flexible Change tag data type to INT (range −32768 to 32767); re-compile and transfer
Color correct on simulator but wrong on panel TP177B runtime older than the configuration target Check ProSave → OS update Update TP177B firmware to the version specified in the WinCC flexible compatibility matrix
VBScript method: color lags by 2–3 seconds Script triggers only on rising edge Confirm event is "Change value", not "Change to TRUE" Switch event to "Change value" so both edges trigger the script

Extended Applications

The same INT-tag-driven pattern supports animations beyond color:

  • Visibility: Hide the button when the combined state equals a forbidden value (e.g., block operator action when both booleans are TRUE).
  • Blinking: Combine the value of the status word with a "Blink" rate tag that oscillates 0 ↔ 1 once per second; WinCC flexible can sum both tags via a calculated tag, but on TP177B a VBScript is simpler.
  • Multi-faceplate valve control: Use one status word per device to drive up to 16 boolean animations across the faceplate, including open/closed lamps, auto/manual selector, fault indicator, and remote/local state.
  • Cross-screen consistency: Because the combined tag is sourced from the PLC, every screen on the TP177B sees the same value. This eliminates the inconsistency that occurs when multiple screens compute the same combination locally.
Design discipline: Always document the bit layout of the status word in the STEP 7 symbol table with comments. A clearly commented layout — e.g., // Bit 0 = ValveOpen, Bit 1 = ValveFault, Bit 2 = AutoMode, Bit 3 = ManualMode — prevents the operator from misreading the HMI faceplate after a future code change.

Reference: WinCC flexible Property / Tag Compatibility

Property Allowed data type Range table supported? Bound to one tag?
Background color INT, DINT Yes (0…n ranges) Yes
Foreground color INT, DINT Yes Yes
Visibility BOOL No (binary on/off) Yes
Blinking BOOL No Yes
X position INT, DINT Yes Yes
Y position INT, DINT Yes Yes
Width / Height INT Yes Yes

Reference: TP177B Color Key Specifications

Parameter Value
Article number (6" Color Touch) 6AV6 642-0BC01-1AX1
Display 5.7" STN color, 320×240
User memory 4 MB Flash
Configuration software WinCC flexible 2005 SP1 / 2007 / 2008 SP2
Interfaces RS485 / MPI / PROFIBUS DP up to 12 Mbit/s
Number of variables 256 (typical), max 1024 with option card
Number of screens 100 (typical), 500 max
Tag refresh (default) 1 s, configurable 250 ms … 10 s

Can WinCC flexible animate a button using a boolean expression such as "Tag1 AND Tag2"?

No. Each appearance property of an HMI object accepts exactly one tag. To combine two booleans, pack them into the low bits of an INT (e.g., MW200) in the STEP 7 program, then bind that INT to the property and use the range table to map each discrete value (0, 1, 2, 3) to one of four states.

How many distinct states can one INT tag drive on the TP177B?

In practice 4–8 states before the range table becomes unwieldy. An INT can hold 65 536 unique values, but WinCC flexible's range table is optimised for a handful of discrete value bands. For more than 8 states, switch to a status word with each bit representing one boolean and use a calculated INT in the HMI.

Does the bit-packing approach add measurable scan time on the S7-300 CPU?

No. A single STL segment of two A and two = instructions executes in well under 1 µs on a CPU 315-2 DP. If placed in OB1 the impact is invisible; if placed in OB35 at 100 ms there is no measurable load on the cyclic interrupt.

Why does the VBScript method lag by one or two cycles?

The "Change value" event fires after the new value has been written, and the script execution is synchronous with the runtime. If the panel is busy processing a screen change or alarm at the moment the bit transitions, the script can be deferred by up to one cycle. Use the PLC-side bit-packing method when latency below 1 s is required.

Can the same combined INT drive multiple animations simultaneously (color, blink, visibility)?

Yes. Create a separate VBScript that watches HMI_CombinedState and writes additional internal tags (e.g., HMI_BlinkRate, HMI_Visibility), each bound to its own property. The same INT can also drive an integer tag export to a trend for historical logging without additional PLC logic.

Back to blog