Access to array elements
Syntax:
<name of array variable> [ <comma-separated list of dimension indexes> ]
|
<name of array variable> |
Name of the array variable Example: aiCounter |
|
<comma-separated list of dimension indexes> |
One index per dimension, so that one element of the array is identified Example: 2 The index is valid from the index minimum to the index maximum. Example: 0..9 |
Examples
One-dimensional array with 10 components
//Declaration
VAR
aiCounter : ARRAY[0..9] OF INT;
iLocalVariable : INT;
END_VAR
// Implementation
iLocalVariable := aiCounter[2];
Two-dimensional array with 2 times 2 components
//Declaration
VAR
aiCardGame : ARRAY[1..2, 3..4] OF INT;
iLocal_1 : INT;
END_VAR
//Implementation
iLocal_1 := aiCardGame[1, 3];
Access to structure components
Syntax:
<name of structure variable> . <name of component>
|
<name of structure variable> |
Example: sPolygon |
|
<name of component> |
Example: aiStart |
Example
//Declaration type
TYPE S_POLYGONLINE :
STRUCT
aiStart : ARRAY[1..2] OF INT := [-99, -99];
aiPoint1 : ARRAY[1..2] OF INT;
aiPoint2 : ARRAY[1..2] OF INT;
aiPoint3 : ARRAY[1..2] OF INT;
aiPoint4 : ARRAY[1..2] OF INT;
aiEnd : ARRAY[1..2] OF INT := [99, 99];
END_STRUCT
END_TYPE
//Declaration structure variable
VAR
sPolygon : S_POLYGONLINE;
iPoint : INT;
END_VAR
//Implementation
iPoint := sPolygon.aiPoint1[1];
Access to variables in POUs
Syntax:
<POU name> . <variable name>
|
<POU name> |
Name of a function block instance (FUNCTION_BLOCK) or a program (PROGRAM) Example: fbController |
|
<variable name> |
Variable of the POU Example: xStart |
Example
FUNCTION_BLOCK FB_Controller
VAR_INPUT
xStart : BOOL;
END_VAR
VAR_OUTPUT
END_VAR
VAR
ControlDriveA : S_CONTROL;
END_VAR
IF xStart = TRUE THEN
//Symbolic bit access
ControlDriveA.bitEnableOperation := TRUE;
END_IF
PROGRAM PLC_PRG
fbController : FB_Controller;
END_VAR
fbController();
fbController.xStart := TRUE;