Extracting Substring Characters and Linking Dynamic Text Signals Between WinCC OS and AS
In SIMATIC PCS 7 systems, extracting characters from an HMI output string—such as isolating substring 'AS2' from a composite identifier to generate a boolean supervisory input—can be executed in WinCC OS graphics via VBScript Mid() functions or in the Automation Station using standard S7 IEC string blocks (MID, FIND, EQ_STRING). Implementing string comparison requires configuring matching string lengths in Tag Management and selecting event-driven triggers to prevent excessive CPU or script execution loads.
Table of Contents
- String Data Handling Across SIMATIC PCS 7 OS and AS Layers
- Method 1: WinCC OS VBScript Extraction and Comparison
- Method 2: Automation Station (CFC) IEC String Extraction and Comparison
- Tag Management and AS-OS Data Transfer Configuration
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
String Data Handling Across SIMATIC PCS 7 OS and AS Layers
In process automation, alphanumeric strings represent batch identifiers, recipe codes, equipment IDs, and operator input strings. Frequently, supervisory logic must parse a subset of characters from a dynamic text string to trigger downstream automation actions (for example, detecting if a vessel code contains "AS2" to set an authorization bit):
* S7 String Format: In STEP 7 / CFC, a STRING variable is structured with two management header bytes: Byte 0 defines the maximum allocated length (up to 254 characters), Byte 1 defines the current actual length, followed by the ASCII character bytes.
* WinCC Text Variable: In WinCC OS, strings are mapped as Text tag 8-bit character set or Text tag 16-bit character set.
* Processing Location: String extraction can be performed at the supervisory OS layer (via VBScript or ANSI-C) or deterministically inside the Automation Station (via CFC IEC library blocks).
Method 1: WinCC OS VBScript Extraction and Comparison
To parse characters directly within a WinCC Graphics Designer screen:
1. Open the process picture (.pdl) in Graphics Designer.
2. Select the I/O field or text display object where the source string is displayed.
3. In Object Properties, navigate to Events -> Property Topics -> Output/Input -> Output Value.
4. Right-click the Change event and select VBS-Action.
5. Implement the extraction logic using the VBScript Mid() function:
Dim sourceStr, subStr, targetTag
sourceStr = ScreenItems("IOField_Source").OutputValue
' Extract 3 characters starting from character position 4
subStr = Mid(sourceStr, 4, 3)
' Compare substring against target string
Set targetTag = HMIRuntime.Tags("HMI_Input_Bool")
If subStr = "AS2" Then
targetTag.Write 1
Else
targetTag.Write 0
End If
Set targetTag = Nothing
- Set the trigger to Upon Change of the source string tag. Never use a cyclic timer (e.g., 250 ms) for string scripts to avoid unnecessary script queue load.
Method 2: Automation Station (CFC) IEC String Extraction and Comparison
For safety-critical or deterministic interlocking, string parsing should execute inside the S7-400 or CPU 410 controller rather than in WinCC:
1. In the CFC chart, open the block catalog under Libraries -> Standard Library -> IEC Function Blocks.
2. Instantiate the following standard IEC blocks:
* MID (FC26): Extracts a substring of specified length (L) starting at character position (P) from input string (IN).
* EQ_STRNG (FC10): Compares two input strings (S1 and S2) and outputs a boolean 1 if they match identically.
* FIND (FC17): Searches for the presence of a substring within a larger string and returns the character position index (returns 0 if not found).
3. Connect the dynamic source string tag to input IN of MID.
4. Set input parameter L = 3 (length) and P = 4 (start position).
5. Feed the extracted output string from MID into input S1 of EQ_STRNG.
6. Assign constant 'AS2' to input S2.
7. Connect the boolean output OUT of EQ_STRNG directly to the target APL interlock or control block input pin.
Tag Management and AS-OS Data Transfer Configuration
When passing string variables between AS and OS:
* Length Consistency: Ensure the string length declared in the S7 data block matches the length configured in WinCC Tag Management (e.g., STRING[16]). Mismatched lengths can cause buffer truncations or corrupt adjacent data bytes.
* AS-OS Compilation: When creating the source string in a CFC block with attribute S7_m_c = 'true', execute an AS-OS compilation to generate the WinCC text tag automatically, guaranteeing matching address pointers.
* Data Consistency: Because string variables span multiple data bytes, update strings as atomic records in AS logic to prevent WinCC from reading half-updated text during execution cycles.
Verification
- In WinCC runtime, enter a test string containing
"PREFIX_AS2_SUFFIX"into the input field. - Verify that the VBScript or CFC logic isolates
"AS2". - Confirm that the boolean status tag transitions from
0to1. - Enter an alternative string (e.g.,
"PREFIX_AS3_SUFFIX"): verify that the boolean output returns to0. - Check the WinCC Global Script diagnostics window (
apdiag.exe) to confirm no VBScript runtime errors or type mismatch exceptions occurred.
Limitations and Operational Precautions
- Avoid executing string manipulation scripts in WinCC cyclic screen triggers; cyclic string operations cause high CPU utilization on OS clients.
- S7-400 string operations in CFC consume significantly more CPU instruction cycles than standard integer or boolean logic; avoid executing string functions in fast cyclic interrupt OBs (e.g., OB35 at 100 ms) unless necessary.
- VBScript string comparisons are case-sensitive by default; use
UCase()in VBScript or normalized strings in AS to ensure reliable matching.
Engineer FAQ
- What is the difference between MID and FIND in S7 IEC string blocks?
MIDextracts a fixed-length substring starting at a known character offset, whileFINDsearches for a substring and returns its dynamic position index. - How are strings structured in Siemens S7-400 data blocks?
Byte 0 contains the maximum allocated length, Byte 1 contains the current actual string length, and subsequent bytes store the ASCII characters. - Can I use C-Script instead of VBScript in WinCC for string extraction?
Yes, using standard C library functions such asstrncpy()orstrstr()inside an action script triggered on tag change. - Why did my VBScript generate a 'Type Mismatch' error during string parsing?
This error occurs when the referenced tag is empty (VT_EMPTY), null, or cannot be implicitly cast to a string. Always validate tag quality before callingMid(). - Does writing to an HMI internal boolean tag automatically notify the AS controller?
Only if the tag is an external process tag mapped to an AS data block address; internal HMI tags exist solely within the WinCC memory space. - How do I make VBScript string comparison case-insensitive?
Wrap the variables inUCase(), for example:If UCase(subStr) = "AS2" Then. - Can CFC IEC string blocks handle strings longer than 254 characters?
No, standard STEP 7STRINGvariables have a maximum architectural limit of 254 ASCII characters. - What happens if the start position P in MID exceeds the length of the string?
TheMIDblock returns an empty string ('') and sets the actual length byte to 0 without causing a CPU crash. - How can I monitor active VBScript errors in WinCC runtime?
Launch the WinCC diagnosis toolC:/Program Files (x86)/Siemens/WinCC/bin/apdiag.exeand open the Output Window. - Is string comparison in CFC bumpless during redundant AS switchover?
Yes, string data in instance data blocks is synchronized across redundant fiber-optic links identically to other data types.
Technical References
- SIMATIC STEP 7 V5.6 System and Standard Functions Reference Manual
- SIMATIC HMI WinCC V7.5 VBScript for Process Communication Reference
- Siemens Industry Online Support Entry: String Operations in STEP 7 and WinCC (Entry ID 298697)
- SIMATIC PCS 7 Advanced Process Library (APL) Function Manual
Related Articles
- Extracting Recipe Materials and Parameters in SIMATIC BATCH via Export and Batch API
- Configuring Mass Digital Input State Alarms in SIMATIC PCS 7 Without OS Compile Overwrites
Related Tags
PCS 7, WinCC, VBScript, String Manipulation, CFC, IEC Functions, MID, EQ_STRNG, Tag Management, S7-400