Accesso agli elementi dell'array
Sintassi:
<name of array variable> [ <comma-separated list of dimension indexes> ]
|
<nome della variabile dell'array> |
Nome della variabile dell'array Esempio: aiCounter |
|
<Elenco separato da virgole degli indici delle dimensioni>. |
Un indice per dimensione, in modo da identificare un elemento della matrice. Esempio: 2 L'indice è valido dal minimo al massimo. Esempio: 0..9 |
Esempi
Array monodimensionale con 10 componenti
//Declaration
VAR
aiCounter : ARRAY[0..9] OF INT;
iLocalVariable : INT;
END_VAR
// Implementation
iLocalVariable := aiCounter[2];
Matrice bidimensionale con componenti 2 volte 2
//Declaration
VAR
aiCardGame : ARRAY[1..2, 3..4] OF INT;
iLocal_1 : INT;
END_VAR
//Implementation
iLocal_1 := aiCardGame[1, 3];
Accesso ai componenti della struttura
Sintassi:
<name of structure variable> . <name of component>
|
<nome della variabile della struttura> |
Esempio: sPolygon |
|
<nome del componente> |
Esempio: aiStart |
Esempio
//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];
Accesso alle variabili nei POU
Sintassi:
<POU name> . <variable name>
|
<nomePOU> |
Nome di un'istanza di blocco funzione (FUNCTION_BLOCK) o di un programma (PROGRAM) Esempio: fbController |
|
<nome della variabile> |
Variabile del POU Esempio: xStart |
Esempio
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;