Arrays
An array tag holds several values of one type under one name, numbered from 0. Levels, a DINT array of 5, holds Levels[0] to Levels[4].
One name, numbered values
A DINT array of 5 called Levels, after a few readings:
| Element | Value |
|---|---|
| Levels[0] | 12 |
| Levels[1] | 15 |
| Levels[2] | 19 |
| Levels[3] | 0 |
| Levels[4] | 0 |
The first element is 0, so an array of 5 ends at 4. There is no Levels[5].
Create an array tag
- Stop the PLC. In the Tags table, click + Tag.
- Type a name, such as
Levels, and choose ARRAY under Array in Type. - Choose the Element type: BOOL, DINT or REAL.
- Type the Dimensions:
5for a list of 5, or4, 3for a grid of 4 rows and 3 columns. - Click Create. The Tags table shows the type as
DINT[5]orDINT[4×3]. Expand the row to see every element.
Dimensions
| Dimensions | Type | Elements | First and last |
|---|---|---|---|
| 5 | DINT[5] | 5 | Levels[0] … Levels[4] |
| 4, 3 | REAL[4×3] | 12 | Grid[0,0] … Grid[3,2] |
| 2, 3, 4 | BOOL[2×3×4] | 24 | Bits[0,0,0] … Bits[1,2,3] |
An array has one to three dimensions and 1 to 256 elements in all. In Grid[1,2] the first number is the row and the second the column.
Use one element
Where an instruction accepts an element, choose the array tag in the Inspector, then type each index. MOV SpeedSet Levels[2] writes one element and leaves the others as they are. Each index is a fixed number.
Work on a whole line
Copy array and Fill array work on a line of elements. In a list the line is the whole array; in a grid you choose which row or column.
| Rung | Levels before | Levels after |
|---|---|---|
| FILL Value 0, Dest Levels, Dest start 0, Count 5 | 12 15 19 0 0 | 0 0 0 0 0 |
| COPY Source Levels, Source start 0, Dest Levels, Dest start 1, Count 4 | 12 15 19 7 0 | 12 12 15 19 7 |
The second rung shifts every reading one place along, ready for a new one in Levels[0]. Copy array reads every source element before it writes, so a copy inside one array works even when the ranges overlap.
Good to know
- An array tag is always a Global tag.
- The element type and dimensions are fixed once the tag is made. To change them, make a new tag.
- A range past the end of the array is a fault, and nothing is written. Check Start plus Count against the size.
- Tag export to a CSV file leaves array tags out. Save the project file to keep them.
- Arena export does not accept Copy array or Fill array.