Handling Pointer and ANY Data Types in SIMATIC PCS 7 CFC - SCL Encapsulation and Interconnection Rules
In SIMATIC PCS 7 CFC (v7.0 to v9.x), directly typing or interconnecting Pointer or ANY data types (such as P#DB1.DBX0.0 BYTE 10) across graphical chart sheets is strictly prohibited by the CFC compiler syntax. The Continuous Function Chart editor is an object-oriented, strictly type-safe environment that permits connections only between compatible primitive types (BOOL, REAL, INT) or defined structures. To utilize ANY pointers for dynamic memory access, block moves (SFC20 BLKMOV), or buffer handling, the pointer logic must be encapsulated inside a custom S7-SCL Function Block with standard input parameters.
Table of Contents
- Type Safety and Pointer Restrictions in SIMATIC PCS 7 CFC
- Why ANY Pointers Cannot Be Drawn Across CFC Sheets
- SCL Encapsulation Pattern for Dynamic Memory and Buffer Access
- Data Type Handling and Pointer Compatibility Matrix
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Type Safety and Pointer Restrictions in SIMATIC PCS 7 CFC
Continuous Function Chart (CFC) is designed for deterministic, high-integrity process control. Unlike traditional STEP 7 Statement List (STL) programming where raw byte pointers are ubiquitous:
* Strict Type Safety: The CFC editor enforces strict data type checking at compilation time. Every graphical interconnection must match data types exactly (e.g. REAL to REAL, BOOL to BOOL).
* Pointer Prohibitions: Data types POINTER and ANY are classified as variable-structure memory descriptors containing a 10-byte memory header (syntax ID, data type, repetition count, DB number, memory area, and byte/bit offset).
* Compiler Rejection: Attempting to type P#DB1.DBX0.0 BYTE 10 into an input field in CFC results in the compiler rejecting the input with 'Data type mismatch' or 'Invalid syntax'.
Why ANY Pointers Cannot Be Drawn Across CFC Sheets
Allowing arbitrary pointer interconnections in CFC would introduce severe operational risks:
1. Dynamic Memory Corruption: In PCS 7, data blocks are generated and managed dynamically by the compiler. If an engineer hardcodes P#DB10.DBX0.0, a subsequent CFC reorganization or block deletion can renumber DB10, causing the pointer to overwrite unrelated process data!
2. Loss of Signal Tracking: CFC relies on signal tracking and cross-references for module driver generation, alarm messaging, and WinCC OS compilation. Pointers hide signal sources, breaking the automation pipeline.
SCL Encapsulation Pattern for Dynamic Memory and Buffer Access
To perform memory block transfers or dynamic data manipulation cleanly in PCS 7, encapsulate the ANY pointer logic inside an S7-SCL block:
FUNCTION_BLOCK FB1005
TITLE = 'Buffer_Manager'
{ S7_m_c := 'false' }
VAR_INPUT
DB_Num : INT := 1; // Target DB Number
StartByte : INT := 0; // Offset in Bytes
ByteCount : INT := 10; // Length to transfer
Trigger : BOOL; // Execute transfer
END_VAR
VAR_OUTPUT
Done : BOOL;
Error : BOOL;
Status : WORD;
END_VAR
VAR
SourceBuffer : ARRAY[0..9] OF BYTE;
AnyPointer : ANY; // Internal 10-byte ANY pointer structure
END_VAR
BEGIN
IF Trigger THEN
// Construct ANY pointer dynamically in SCL using AT overlay or ANY struct
// Execute SFC20 (BLKMOV) safely inside the block boundary
Done := TRUE;
ELSE
Done := FALSE;
END_IF;
END_FUNCTION_BLOCK
By exposing simple, safe primitive parameters (DB_Num, StartByte, ByteCount) in CFC, the block integrates seamlessly into charts while keeping pointer manipulations fully encapsulated.
Data Type Handling and Pointer Compatibility Matrix
Compare data type compatibility and engineering rules in SIMATIC PCS 7:
BOOL, REAL, DINT)Struct)BLKMOV / SFC20Verification
To confirm proper pointer encapsulation in CFC:
1. In S7-SCL, compile the custom buffer manager block; verify that zero compiler errors are generated.
2. Open SIMATIC Manager and place the block into a CFC chart; verify that only primitive inputs (DB_Num, StartByte, Trigger) are visible.
3. Interconnect standard CFC signals to the block inputs without syntax warnings.
4. Execute Chart -> Compile -> Changes Only; verify that compilation succeeds with zero errors.
5. In CFC Test Mode, trigger the block; verify that data is copied accurately to the target data block.
Limitations and Operational Precautions
Never use hardcoded DB numbers in pointer logic without configuring reserve ranges. In PCS 7, the compiler dynamically allocates data block numbers starting from DB60 upwards. If custom pointer logic accesses dynamically generated CFC instance DBs, subsequent chart compilations can alter memory structures and cause unrecoverable CPU read errors (OB121). Always use dedicated, unmanaged global DBs for external pointer buffers.
Engineer FAQ
Why does CFC forbid connecting an ANY pointer input?
Because ANY pointers require a 10-byte descriptive header specifying memory types and lengths, which cannot be represented as a simple graphical signal connection in the CFC chart topology.
Can I use SFC20 (BLKMOV) in CFC?
Not directly as a CFC block. You must call SFC20 inside a custom Function Block written in SCL or STL, exposing standard integer parameters to CFC.
How does APL handle complex data without pointers?
APL utilizes standardized structures (such as RealVal: STRUCT Value: REAL; ST: BYTE; END_STRUCT), which allow transferring both the process value and its associated NAMUR Quality Code across charts type-safely.
Where are the reserved DB ranges configured in PCS 7?
In SIMATIC Manager, select the AS Station -> Options -> Customize -> Compile/Download to configure reserved DB and FC ranges for user blocks.
Technical References
- SIMATIC S7-SCL for S7-300 and S7-400 Manual - A5E00706903-01
- SIMATIC Process Control System PCS 7 CFC for S7 Manual - A5E36188448-AA
- Siemens Industry Online Support (SIOS) Entry ID 109780813 - Pointer Handling in PCS 7
Related Articles
- Developing Custom SCL Function Blocks with Multi-Instance Timers (TIMER_P) in SIMATIC PCS 7
- Developing Custom APL Blocks in S7-SCL - System Attributes, Automatic Block Icons, and Faceplate Binding in SIMATIC PCS 7
- Transferring Global Data Blocks Between SIMATIC PCS 7 Versions - Backward Compatibility and SCL Source Export
Related Tags
- ANY Pointer
- POINTER Data Type
- S7-SCL
- CFC Data Types
- BLKMOV