Acceso a variables en matrices, estructuras y bloques Permalink

Acceso a los elementos de la matriz

Sintaxis:

<name of array variable> [ <comma-separated list of dimension indexes> ]

<nombre de la variable de matriz>

Nombre de la variable de matriz

Ejemplo: aiCounter

<lista de índices de dimensión separados por comas>

Un índice por dimensión, para identificar un elemento de la matriz

Por ejemplo: 2

El índice es válido desde el mínimo hasta el máximo del índice. Por ejemplo: 0..9

Ejemplos

Matriz unidimensional con 10 componentes

//Declaration
VAR
    aiCounter : ARRAY[0..9] OF INT;
    iLocalVariable : INT;
END_VAR

// Implementation
iLocalVariable := aiCounter[2]; 

Matriz bidimensional con 2 componentes por 2

//Declaration
VAR
    aiCardGame : ARRAY[1..2, 3..4] OF INT;
    iLocal_1 : INT;
END_VAR

//Implementation
iLocal_1 := aiCardGame[1, 3];

Acceso a los componentes de la estructura

Sintaxis:

<name of structure variable> . <name of component>

<nombre de la variable de estructura>

Ejemplo: sPolygon

<nombre del componente>

Ejemplo: aiStart

Ejemplo

//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];

Acceso a variables en POU

Sintaxis:

<POU name> . <variable name>

<nombre POU>

Nombre de una instancia de bloque de funciones (FUNCTION_BLOCK) o de un programa (PROGRAM)

Ejemplo: fbController

<nombre de la variable>

Variable del POU

Ejemplo: xStart

Ejemplo

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;