Using the SFC-API (sfccli.dll) to Display Active Control Strategy Names in WinCC Graphics Designer
In SIMATIC PCS 7 (V7.1 through V9.x), the SFC-API function SFCGetControlStrategyName (from sfccli.dll) retrieves the textual name of a sequential control strategy based on its numeric ID. To display the strategy name dynamically in a WinCC I/O field, write an ANSI-C action on the 'Output Value' property that loads sfccli.dll, reads the active strategy number from the SFC instance tag (QCS), invokes the API function, and returns the character string.
Table of Contents
- SFC Control Strategies and Dynamic Visualization Requirements
- SFC-API Function Signature and Execution Architecture
- Step-by-Step Implementation in WinCC Graphics Designer
- SFC Tag Interface and Control Strategy Data Flow Matrix
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
SFC Control Strategies and Dynamic Visualization Requirements
In SIMATIC PCS 7 batch and sequential process automation, Sequential Function Charts (SFC) frequently define multiple Control Strategies (Fahrweisen). For example, a Clean-in-Place (CIP) sequence may support Strategy 1 (Water Rinse), Strategy 2 (Caustic Wash), and Strategy 3 (Acid Sanitization).
In the automation controller, the active strategy is tracked as an integer number (e.g. QCS = 1, QCS = 2). Plant operators requiring supervisory visibility on custom overview graphics should see the descriptive text string (e.g. 'Caustic Wash') rather than an arbitrary integer.
While standard PCS 7 SFC faceplates display the strategy name automatically, engineers designing custom process mimics or overview dashboards often seek to display the active strategy name inside an I/O field (EA-Feld). Attempting to embed raw C-code into graphic properties without understanding the WinCC C-script return types or the SFC Client API (sfccli.dll) leads to compiler errors and graphic freezes.
SFC-API Function Signature and Execution Architecture
Siemens provides the SFC visualization client library sfccli.dll (located in <WinCCPath>\bin\) to query SFC runtime metadata:
-
Function Prototype:
Declared in headersfccli.h:
c BOOL SFCGetControlStrategyName( LPCTSTR pChartName, // In: Pointer to SFC Chart Name (e.g. "SFC_CIP") long lNumber, // In: Control Strategy Number (e.g. 1, 2, 3) LPTSTR pControlStrategyName, // Out: Destination buffer to receive text string long length // In: Maximum buffer size (e.g. 255) ); -
Parameter Functionality:
*pChartName: Full technological name of the SFC chart or SFC instance.
*lNumber: The control strategy number currently active in the AS. This must be read dynamically from the controller tagChartName.QCS(orCS).
*pControlStrategyName: Character array allocated in memory to store the retrieved textual name.
*length: Buffer limit preventing memory overruns.
* Return Value:TRUEif the name was resolved successfully;FALSEif the chart or strategy number does not exist. -
WinCC C-Action Return Contract:
* In WinCC Graphics Designer, the Output Value (Ausgabewert) of a String I/O Field requires the C-script to return a string pointer:char*.
* Returning the BooleanbRetValfrom the main procedure triggers compiler error: 'Incompatible return type'. The script must return the populated character buffer.
Step-by-Step Implementation in WinCC Graphics Designer
1. Place and Configure the I/O Field
- In WinCC Graphics Designer, open the target process picture (
.pdl). - From the Object Palette, drag an I/O Field (EA-Feld) onto the canvas.
- In Object Properties:
* Navigate to Output/Input (Ausgabe/Eingabe).
* Set Field Type to Output (Ausgabe).
* Set Data Format to String.
2. Implement the C-Action on the Output Value Property
- In Object Properties, under Output/Input, locate property Output Value (Ausgabewert).
- Right-click the lightbulb icon in the Dynamic column and select C-Action.
- Replace the template with the following tested, memory-safe C-script:
#include "apdefap.h"
// Dynamically bind to the Siemens SFC client API library
#pragma code("sfccli.dll")
BOOL SFCGetControlStrategyName(LPCTSTR pChartName, long lNumber, LPTSTR pControlStrategyName, long length);
#pragma code()
char* _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
static char szStrategyName[256];
long lStrategyNumber = 0;
BOOL bSuccess = FALSE;
char szChartName[] = "Area1/SFC_CIP"; // Specify your exact SFC chart name
// Read the active control strategy number from the AS tag
lStrategyNumber = (long)GetTagSWord("Area1/SFC_CIP.QCS");
// Initialize buffer
memset(szStrategyName, 0, sizeof(szStrategyName));
if (lStrategyNumber > 0)
{
// Query textual strategy name from SFC-API
bSuccess = SFCGetControlStrategyName(szChartName, lStrategyNumber, szStrategyName, 255);
if (!bSuccess)
{
strncpy(szStrategyName, "Unknown Strategy", sizeof(szStrategyName) - 1);
}
}
else
{
strncpy(szStrategyName, "No Strategy Active", sizeof(szStrategyName) - 1);
}
// Return the string pointer to WinCC Graphics Designer
return szStrategyName;
}
3. Configure Execution Trigger
- In the C-Editor, click the Trigger button (clock icon).
- Assign a Tag Trigger pointing to
Area1/SFC_CIP.QCSwith cycle: Upon Change. - Using a tag trigger ensures the script executes ONLY when the control strategy changes, eliminating unnecessary CPU polling.
- Compile the script (confirm 0 Errors, 0 Warnings) and save the picture.
SFC Tag Interface and Control Strategy Data Flow Matrix
ChartName.CSWORD / INTChartName.QCSWORD / INTsfccli.dllSFCGetControlStrategyNameBOOL (Return)char*Verification
- In SIMATIC Manager, verify that SFC chart
SFC_CIPhas defined control strategies (e.g. Strategy 1: Water Rinse, Strategy 2: Caustic Wash). - Launch WinCC Runtime.
- Open the process graphic containing the configured I/O Field.
- When the SFC is idle with no strategy selected, verify the field displays 'No Strategy Active'.
- From the SFC faceplate, command Strategy 1 (Water Rinse); confirm the I/O field updates dynamically within 500 ms to display 'Water Rinse'.
- Switch to Strategy 2; confirm the text updates immediately to 'Caustic Wash'.
Limitations and Operational Precautions
- Static Buffer Scope: In WinCC C-actions, character buffers returned to Graphics Designer must be declared with
staticmemory scope (e.g.static char szStrategyName[256]). Returning a non-static local stack array produces undefined memory artifacts or application crashes. - Avoid High-Frequency Polling: Never execute this C-action on a 250 ms cyclical timer across dozens of fields. Multiple simultaneous DLL function calls on rapid timers degrade Graphics Designer UI responsiveness. Always use Tag Trigger upon Change.
- Chart Name Path Resolution: In PCS 7 multiprojects utilizing the Plant Hierarchy, the
pChartNameparameter must match the exact plant hierarchy path or chart name as registered in the SFC runtime database.
Engineer FAQ
Why did the compiler report 'No return value for main procedure'?
In Graphics Designer, a C-script attached to a string property must conclude with return <string_pointer>;. If the script ends without a return statement or returns a boolean integer, compilation fails.
Where can I find the complete list of SFC-API functions?
SFC-API functions are documented in the SIMATIC Process Control System PCS 7 SFC for S7 manual under the chapter 'SFC Application Programming Interface (SFC-API)'. Header files reside in <WinCCPath>\include\sfccli.h.
Can this function be called from VBScript instead of ANSI-C?
No. The SFC-API is exported strictly as a native C-linkage DLL (sfccli.dll). Calling it directly requires WinCC C-scripting. In VBScript, you would have to use an external ActiveX wrapper.
Technical References
- SIMATIC Process Control System PCS 7 SFC for S7 (V7.1 / V8.1) Programming Manual
- SIMATIC WinCC V7.3 Scripting: ANSI-C Function Manual
- Siemens Industry Online Support: Using SFC-API in WinCC Graphics Designer (SIOS Entry ID 109780813)
- ISA-88 Batch Control: Procedural Control Strategy Design Guidelines
Related Articles
- Resolving Disabled Control Buttons and Freezes in SIMATIC PCS 7 SFC Test Mode
- Configuring ISA-88 State Logic Transitions in PCS 7 SFC Sequences
- Best Practices for ANSI-C Scripting Performance in WinCC Graphics Designer
Related Tags
- SFC-API
- sfccli.dll
- Control Strategy
- Fahrweise
- Graphics Designer
- ANSI-C