Configuring Simultaneous Multi-Bit Commands Using APL_OP_BUTTON in WinCC Faceplates

Configuring Simultaneous Multi-Bit Commands Using APL_OP_BUTTON in WinCC Faceplates

In SIMATIC PCS 7 custom faceplates based on the Advanced Process Library (APL), setting two or more boolean tags simultaneously from a single APL_OP_BUTTON element cannot be achieved using the default Dynamic Wizard single-bit configuration. Instead, implement one of two proven engineering patterns: (1) map both command bits into a single structured Command Word (DWORD or WORD) on the AS technological block, allowing APL_OP_BUTTON to write an integer bitmask atomically via SetTagWord/SetTagDWord; or (2) customize the button's OnClick C-script event to execute sequential SetTagBit calls incorporating the parent picture's GetTagPrefix() within the same execution frame. The Command Word approach is strongly recommended by Siemens to guarantee atomic, deterministic cycle execution in the controller.

Table of Contents

Executive Summary

Designing customized operator control and monitoring (OCM) faceplates in SIMATIC PCS 7 frequently involves tailoring standard Advanced Process Library (APL) graphical objects to meet specialized operational requirements. A common functional demand is commanding dual operations from a single operator action—for example, simultaneously opening a purge valve and asserting a cycle start request, or simultaneously resetting an alarm latch and acknowledging an interlock.

The standard APL button template, APL_OP_BUTTON, is designed out-of-the-box to toggle or pulse a single boolean tag. Engineers attempting to adapt this element often struggle when trying to bind multiple dynamic tags to a single button click. Attempting to attach multiple Dynamic Wizards overwrites previous actions. This technical guide explains the execution mechanics of WinCC C-scripting and AS cycle synchronization, details how to implement atomic multi-bit command words in CFC charts, provides the verified C-script code for dual-tag writing, and outlines best practices to prevent race conditions during network latency spikes.

Architecture and Fundamental Mechanics

The interaction between WinCC operator buttons and AS controller logic involves asynchronous communication queues and cyclic execution frames:
1. Dynamic Wizard Limitations on APL_OP_BUTTON:
* The standard APL_OP_BUTTON utilizes WinCC C-actions (such as APL_SetBit or APL_PulseBit) stored in the button's Events > Mouse > Mouse Click trigger.
* The Dynamic Wizard associates only one target tag property with the button's internal tag connection.
2. The Risk of Multi-Tag Race Conditions:
* If a script issues two independent boolean write requests over the network (SetTagBit for Tag A, followed by SetTagBit for Tag B):
* In high-traffic industrial networks, the two write frames may arrive across different PLC execution cycles.
* If the AS controller evaluates its logic between the arrival of Tag A and Tag B, an intermediate, inconsistent state is executed for one CPU scan cycle, potentially tripping interlocks or causing process bumps.
3. Architectural Solution 1: Atomic Command Word (Recommended):
* In the AS controller block, configure a single 16-bit or 32-bit integer input parameter (e.g., OpCommand of type WORD or DWORD).
* Bit 0 represents Command A (e.g., Value 16#0001); Bit 1 represents Command B (e.g., Value 16#0002). Setting both bits simultaneously writes the integer bitmask 16#0003.
* The faceplate button writes this single word in one atomic communication packet via SetTagWord(GetTagPrefix() + "OpCommand", 3).
* In the AS chart, an elementary demultiplexer block (e.g., BitsToWord or standard bit-unpacking logic) decodes the bits simultaneously within the exact same CPU cycle.
4. Architectural Solution 2: Scripted Dual-Write via C-Action:
* If controller logic cannot be modified to accept a command word, the button's OnClick event can be scripted to write both tags sequentially within the local C-script thread using the parent window's TagPrefix.

Step-by-Step Implementation Procedure

Step 1: Determine Command Architecture (Command Word vs. Dual Tags)

  1. Evaluate whether the AS block interface can accept a structured WORD or DWORD parameter.
  2. If modifying the AS block is permissible, adopt the Command Word approach (proceed to Step 2).
  3. If existing CFC blocks cannot be altered and require separate digital inputs, adopt the Scripted Dual-Write approach (proceed to Step 3).

Step 2: Configure Atomic Command Word in AS and Faceplate

  1. In the target CFC chart or technological block, create an input parameter: OpOrder (WORD).
  2. Interconnect the bits of OpOrder to your application logic (e.g., Bit 0 -> StartCommand, Bit 1 -> ResetCommand).
  3. Mark OpOrder with attribute S7_m_c = true and compile the OS.
  4. In WinCC Graphics Designer, open the custom faceplate picture (e.g., @PG_CustomUnit_Standard.pdl).
  5. Select the APL_OP_BUTTON element.
  6. In Object Properties, navigate to Events > Mouse > Mouse Click.
  7. Assign a C-action that writes the combined bitmask:
    c char szTag[255]; sprintf(szTag, "%s%s", GetTagPrefix(GetParentPicture(lpszPictureName), lpszPictureName), "OpOrder"); SetTagWord(szTag, 0x0003); // Sets Bit 0 and Bit 1 simultaneously

Step 3: Implement Scripted Dual Boolean Tag Write (Alternative)

  1. Open the custom faceplate in WinCC Graphics Designer.
  2. Right-click the APL_OP_BUTTON and select Properties.
  3. Open Events > Mouse > Mouse Click and insert the following C-script:
    ```c
    #include "apdefap.h"
    void OnClick(char lpszPictureName, char lpszObjectName, char lpszPropertyName)
    {
    char szTag1[255];
    char szTag2[255];
    char
    pszPrefix = GetTagPrefix(GetParentPicture(lpszPictureName), lpszPictureName);

    if (pszPrefix != NULL)
    {
    sprintf(szTag1, "%s%s", pszPrefix, "CommandBit1");
    sprintf(szTag2, "%s%s", pszPrefix, "CommandBit2");

       // Execute sequential writes within same script cycle
       SetTagBit(szTag1, 1);
       SetTagBit(szTag2, 1);
    

    }
    }
    ```
    4. If momentary pulse behavior is required, configure an automatic reset script or let the AS controller reset the bits after execution.

Step 4: Verify Tag Security and Permission Interlocks

  1. Ensure the operator clicking the button possesses Authorization 5 (Process controlling) or Authorization 6 (Higher process controlling) in WinCC User Administrator.
  2. Ensure the parent faceplate evaluates OS_Perm to grey out the button if operating conditions are invalid.

Step 5: Save and Download Project

  1. Save the modified faceplate in Graphics Designer.
  2. In SIMATIC Manager, perform an OS Compile ('Changes only') and download to runtime stations.

Verification

  1. In WinCC Runtime, open the custom faceplate.
  2. Open the online CFC chart on the Engineering Station to monitor the target block inputs in real time.
  3. Click the customized APL_OP_BUTTON on the faceplate.
  4. Observe the online CFC chart: verify that both digital signals transition from 0 to 1 within the exact same execution cycle without observable delay.
  5. Confirm that field actuators or logic sequences commanded by both bits execute in unison without triggering timing interlocks.

Limitations and Operational Precautions

  1. Dual SetTagBit script calls do not guarantee atomic execution in the AS; network latency or packet fragmentation can cause one bit to arrive one CPU cycle earlier than the second.
  2. Always include null pointer validation (if (pszPrefix != NULL)) when querying GetTagPrefix, as unhandled null strings will crash the WinCC script engine.
  3. Custom C-scripts embedded in faceplates must be documented thoroughly; running the OS Project Editor will not repair errors in user-created faceplate files.
  4. Ensure operator authorization is validated in script prior to issuing tag write commands.

Engineer FAQ

Why is writing a Command Word better than writing two boolean tags?

A Command Word is transmitted in a single atomic communication packet, ensuring both bits arrive and take effect in the exact same AS execution cycle, eliminating race conditions.

Can I set two tags using a standard Dynamic Wizard in WinCC?

No. The Dynamic Wizard supports binding only one target tag per wizard execution. Multi-tag writing requires custom C-scripting or word bitmasking.

How does GetTagPrefix work in custom faceplates?

It retrieves the hierarchical plant path (e.g., Plant/Unit/Device.) passed by the parent block icon, allowing the faceplate to reference block pins without hardcoded tag paths.

Can I reset the bits automatically after 2 seconds?

Yes, either by using a timer block in the AS controller (recommended), or by configuring an asynchronous timer callback in WinCC scripting.

Does modifying APL_OP_BUTTON affect other standard faceplates?

Only if you edit standard factory template pictures (@PG_...). Always create a copy of the faceplate with a unique custom name to protect standard library pictures.

Technical References

Related Articles

Related Tags

  • APL_OP_BUTTON
  • WinCC Faceplates
  • C-Script
  • TagPrefix
  • Multi-Bit Control
20 respuestas