In Siemens SCL (Structured Control Language), an ARRAY is a data structure used to store multiple values of the same data type under a single variable name. Each individual value, known as an array element, can be accessed using one or more integer-based indices.
An array is essentially a list of data elements that share a uniform data type. This list is referred to as an array tag, while the elements within it are the array elements.
The structure and properties of each array element are typically identical and can be centrally defined through the array tag. A tag of the ARRAY data type represents a fixed-size collection of components, all having the same base data type. All data types except ARRAY itself are allowed as element types.
When defining an ARRAY in SCL, the index limits are enclosed in square brackets, and the data type follows the keyword OF. The index range can be fixed using integers, constants (local or global), or formal parameters of a block. You can also use a variable definition with ARRAY[*]. The lower limit must always be less than or equal to the upper limit.
SCL supports up to six dimensions in an ARRAY, with limits specified and separated by commas. A typical one-dimensional ARRAY declaration looks like: MyArray: ARRAY[1..10] OF INT;
Arrays offer a structured and efficient way to manage multiple variables of the same data type under a single tag. Instead of declaring many individual variables, you can use a single array tag to group similar elements together, making your code cleaner and more organized.
By defining shared properties at the array tag level, you ensure consistency across all elements. Each element in the array can still be accessed and used just like a normal tag, allowing you to treat them as individual variables where needed.
This not only simplifies configuration and maintenance but also helps reduce programming errors, improves scalability, and enables more flexible use of loops and indexing for repetitive operations—especially useful in automation and control systems.
In Siemens SCL (Structured Control Language), arrays can be categorized based on the number of dimensions and how they are defined. Understanding the types of arrays helps in writing clean, efficient, and scalable PLC programs.
1. Single-Dimensional Array:
This is the most commonly used array type. It stores elements in a single row and is accessed using a single index.
Example: MyArray: ARRAY[1..5] OF INT;
2. Multi-Dimensional Array (Up to 6 Dimensions):
SCL allows arrays with up to six dimensions, useful for complex data structures like grids or tables. Each dimension is separated by a comma.
Example: Matrix: ARRAY[1..3, 1..3] OF REAL;
3. Fixed-Size Array:
The array size is predefined with fixed index limits. This is the most stable and widely used type in PLC applications.
Example: Status: ARRAY[0..9] OF BOOL;
4. Variable-Size Array (ARRAY[*]):
This type is used when the array size is not known during declaration and will be set dynamically. It's commonly used in function blocks where the array dimensions are passed as parameters.
Example: DataBuffer: ARRAY[*] OF BYTE;
Note: While SCL supports multi-dimensional arrays in the PLC, HMI systems (like RT Advanced/Professional) only support one-dimensional arrays.
The maximum size and range of an ARRAY in Siemens SCL depend on several important factors, including the data type used, the memory settings, and the target CPU. Understanding these limits is essential for efficient memory usage and reliable program behavior.
The key factors influencing ARRAY limits include:
• Data Type of the ARRAY Elements: Different data types (e.g., INT, BOOL, REAL) consume different amounts of memory.
• Memory Reservation: In blocks with optimized access, memory is managed differently, allowing larger index ranges.
• Block Type: Whether the array is declared in a standard block, multi-instance, or an optimized block.
• Maximum Data Block Size: Defined by the CPU capabilities and TIA Portal version.
• CPU Memory Capacity: Each Siemens PLC has a defined memory limit; refer to the hardware manual for details.
You can find more details under: Basic information on loading block extensions without reinitialization.
Block Type | Format | Allowed Index Range | Allowed Data Types |
---|---|---|---|
Standard | ARRAY[low limit..high limit] OF <DataType> | -32,768 to 32,767 | All data types except ARRAY |
Optimized | ARRAY[low limit..high limit] OF <DataType> | -2,147,483,648 to 2,147,483,647 | All data types except ARRAY |
A single dimension array in Siemens SCL is a simple list of values that are all of the same data type and arranged in a straight line. It is represented using a single index, making it easy to declare and access each element individually.
The syntax for declaring a single dimension array is:
array_name: ARRAY[a..b] OF DataType;
Where:
IF #value[0] < 10.11 THEN #real_value[0] := #real_value[2] + #real_value[1]; #real_value[3] := #real_value[3] - #real_value[4]; #motor_start := TRUE; END_IF; IF #value[1] > 20.21 THEN #motor_start := FALSE; END_IF;
In this example, we check array values using index positions and perform arithmetic operations using the array elements. This is a clear and simple use of a single dimension array in process control.
A multi-dimensional array in Siemens SCL is an array with more than one index, allowing you to store data in a table or matrix-like format. These arrays are useful when you need to organize data across rows and columns, such as storing grid values or multiple sets of parameters.
The syntax for declaring a multi-dimensional array is:
array_name: ARRAY[a1..b1, a2..b2] OF DataType;
Where:
#real_multi[0, 0] := 3.144; #real_multi[0, 1] := 1.234; #real_multi[0, 2] := #real_multi[0, 0] + #real_multi[0, 1];
In this example, we store values in the first row and perform a calculation by accessing specific elements using their two-dimensional index positions.
Arrays are highly useful in automation programming and can simplify the handling of large sets of related data. Below are some common use cases where array tags are effectively used in Siemens SCL:
• Grouping Process Values in Profile Trends:
Arrays allow you to group related process values that are recorded at different time intervals. These values can be mapped and analyzed using profile trends.
• Accessing Trend Values Dynamically:
You can display a series of recorded values from a trend by gradually increasing the array index. This makes it easy to visualize historical data in a stepwise manner.
• Configuring Discrete Alarms:
Array elements can represent bits in a sequence, making them ideal for setting up discrete alarms with successive bit numbers, especially in alarm management systems.
• Storing Machine Data in Recipes:
Arrays are useful for storing complete machine parameter sets or production data records in a recipe. This ensures consistent configuration and easy retrieval during runtime.
When working with arrays on Siemens HMI devices (such as RT Advanced and RT Professional), certain limitations must be considered:
• Single-Dimension Only: Arrays used in HMI systems can only have one dimension. If the PLC program uses multi-dimensional arrays, these will be mapped as separate individual tags on the HMI.
• Elementary Data Types Only: Arrays must consist of basic data types without any nested or structured elements. Complex types like structures or user-defined types are not supported in HMI arrays.
• Zero-Based Indexing: The lower index of the array must start at 0. If your PLC array starts with a different value, the HMI will automatically shift the index range to begin from zero.
• No Scaling or Multiplexing: Scalable arrays do not support features like value ranges, linear scaling, or tag multiplexing. These features are only available for individual tags, not array elements.