Comparing SCL Source Files in SIMATIC PCS 7: Native Tools, Text Diffs, and Version Management

Comparing SCL Source Files in SIMATIC PCS 7: Native Tools, Text Diffs, and Version Management

To compare two Structured Control Language (SCL) source files in SIMATIC PCS 7 effectively, export the SCL sources as ASCII text files and utilize a specialized visual file diff tool such as Beyond Compare, WinMerge, or Total Commander, or employ the native Siemens SIMATIC Version Cross Manager (VXM). While the STEP 7 'Compare Blocks' utility compares compiled binary byte-code in the blocks folder, it cannot evaluate high-level SCL source text, variable comments, or algorithmic formulas. Exporting sources via SCL Editor (File -> Export Source) enables precise line-by-line syntax comparison, whitespace filtering, and bidirectional merging.

Table of Contents

Structured Control Language (SCL) Sources vs Compiled Binary Blocks

In SIMATIC PCS 7 and STEP 7 engineering, custom algorithmic blocks, complex mathematical calculations, and communication drivers are frequently authored in Structured Control Language (SCL), an IEC 61131-3 compliant high-level programming language similar to Pascal. Within an S7 program, SCL code exists in two distinct representations:

  1. The SCL Source Text (Sources container): A human-readable ASCII text file containing high-level code, variable declarations, engineering formulas, comments, and compiler directives ({ S7_m_c := 'true' }).
  2. The Compiled Block Binary (Blocks container): The machine-executable Function Block (FB) or Function (FC) generated when the SCL source is compiled into S7 Machine Code (Statement List / AWL machine instructions).

When engineers seek to compare two versions of an SCL algorithm, conflating these two layers leads to ineffective analysis.

Limitations of the STEP 7 Native 'Compare Blocks' Utility

Engineers familiar with the native STEP 7 utility Compare Blocks (s7wbmpbx.exe - Bausteine vergleichen) often attempt to use it to compare SCL algorithms. However, Compare Blocks is designed strictly for compiled binary blocks:

  • Loss of SCL Abstraction: Compare Blocks decompiles both blocks into raw Statement List (AWL) mnemonics. Complex high-level constructs (such as FOR...TO...DO loops, CASE statements, and array index calculations) are expanded into dozens of raw register jumps and accumulator operations, making algorithmic comparison virtually incomprehensible.
  • Missing Comments and Layout: The compiled binary in the PLC or offline block folder strips all programmer comments and variable indentation. Comparing compiled blocks reveals that differences exist, but fails to explain why or show the original source line that was altered.
  • Spurious Differences: Changes in SCL compiler optimization settings or timestamp headers trigger false mismatch alerts in Compare Blocks even when the high-level source code is identical.

Recommended Workflow 1: Exporting SCL Sources for Visual Text Diff

The industry-standard, most effective method for comparing SCL source code relies on external visual diff utilities:

  • Exporting SCL Text: Inside the S7 SCL Editor, SCL sources can be exported directly to standard text files (*.scl or *.txt).
  • Visual Diff Engines: Modern utilities—such as Beyond Compare, WinMerge, KDiff3, or Total Commander (Compare by Content)—provide advanced visual text analysis specifically suited for programming:
  • Side-by-side color-coded syntax highlighting.
  • In-line character difference tracking.
  • Ignorable whitespace, line-ending (CRLF vs LF), and case-sensitivity filtering.
  • Direct three-way merging and conflict resolution.

Recommended Workflow 2: SIMATIC Version Cross Manager (VXM)

For plants requiring an integrated, audit-trailed Siemens environment, SIMATIC Version Cross Manager (VXM) is the certified optional package:

  • Native S7 Project Parsing: VXM opens two STEP 7 projects, multiprojects, or library archives directly without requiring manual text exports.
  • Object-Level Diff: VXM parses the Sources container directly, highlighting differences between SCL sources, CFC charts, hardware configurations, and symbol tables.
  • Change History and Tracking: Integrated with SIMATIC Version Trail (VT), VXM generates structured discrepancy reports conforming to regulatory change management standards (such as FDA 21 CFR Part 11 or ISO 9001).

Comparing SCL Sources vs Binary Blocks: Technical Tradeoffs Matrix

The following table compares the capabilities of SCL source text comparison against compiled binary block comparison:

Engineering DimensionSCL Source Text Diff (WinMerge / Beyond Compare)Compiled Block Compare (STEP 7 Native)SIMATIC Version Cross Manager (VXM)Target AnalyzedHigh-level SCL source text (*.scl)Compiled MC7/AWL machine code in BlocksS7 Project database objects directlyReadabilityHigh; preserves formulas, indentation, commentsLow; decompiles to raw accumulator AWLHigh; graphical tree and source diffRequires Export?Yes (Export to .scl or .txt)No (Direct offline/online block comparison)No (Reads S7 project files directly)Whitespace FilteringFully supported (ignores spaces/tabs)Not applicableSupportedOnline CPU CompareNo (CPU only holds compiled binary)Yes (Compares offline block to running CPU)No (Offline project comparison)License RequirementFree open-source or commercial diff toolIncluded in standard STEP 7 licenseDedicated Siemens VXM license required

Step-by-Step Export and Comparison Procedure

Follow this sequence to execute a precision SCL comparison using external diff tools:

  1. Export Source 1: In SIMATIC Manager, navigate to Project A, open the Sources folder, and double-click the SCL source. In the SCL Editor, select File -> Export Source.... Save the file as Source_v1.scl.
  2. Export Source 2: Repeat the process for Project B or the library folder, saving as Source_v2.scl.
  3. Launch Visual Diff Tool: Open Beyond Compare or WinMerge.
  4. Load Files: Drag Source_v1.scl to the left pane and Source_v2.scl to the right pane.
  5. Configure Filter Rules: Enable Ignore Unimportant Differences (comments, trailing spaces) to isolate pure algorithmic logic changes.
  6. Analyze Discrepancies: Review highlighted differences in variable declarations, logic branches (IF...THEN...ELSE), and block attributes.

Verification

Verify accurate SCL source alignment and compilation:

  1. After merging or reconciling differences in the SCL Editor, click File -> Save.
  2. Execute File -> Compile in the SCL Editor (or press Ctrl + F9).
  3. Confirm that the compiler output window reports '0 Errors, 0 Warnings'.
  4. In SIMATIC Manager, verify that the compiled FB/FC in the Blocks folder reflects the updated timestamp.
  5. Run the native STEP 7 'Compare Blocks' utility against the target AS; confirm that code differences are resolved.

Limitations and Operational Precautions

Adhere to the following operational precautions:

  • Source-to-Block Divergence: Never assume the compiled block in the AS matches the SCL source file in the Sources container; if an engineer edited the block in AWL directly or failed to recompile the SCL source, the source text and running block will diverge.
  • Interface Attribute Changes: Modifying SCL input/output variables or block attributes (S7_m_c) alters the block interface; updating the block in CFC requires recompilation and may invalidate delta downloads.
  • Character Encoding: Ensure visual diff tools are configured for ANSI / Windows-1252 encoding to prevent corruption of special German umlauts (ä, ö, ü) in block comments.

Engineer FAQ

Can I compare an SCL source directly against a running PLC?

No. PLCs execute compiled machine code (MC7) and do not store SCL source text. You can only compare the compiled block binary against the PLC using Compare Blocks.

What happens if an SCL source is edited but not compiled?

The SCL source text updates in the Sources container, but the compiled FB/FC in the Blocks container and in the running AS remains unchanged, creating a dangerous code divergence.

Does exporting an SCL source strip any block properties?

No. Exporting an SCL source exports the entire ASCII file, including compiler directives, attributes (such as S7_m_c, S7_alarm_ui), and variable declarations.

Technical References

Related Articles

Related Tags

  • SCL Programming
  • Source Code Compare
  • WinMerge / Beyond Compare
  • Version Cross Manager (VXM)
  • STEP 7 Compare Blocks
  • SCL Source Export
6 respuestas