Working with Variables
Groups
A group is a set of variables. A group either refers to a physical class of variables, or identifies the variables local to a program or user-defined function block. Below are the possible groups:
Groups | Description |
GLOBAL | Internal variables known by all programs |
RETAIN | Non volatile internal variables known by all programs |
%I... | Channels of an input board - variables with same data type linked to a physical input device |
%Q... | Channels of an output board - variables with same data type linked to a physical output device |
PROGRAMxxx | All internal variables local to a program (the name of the group is the name of the program) |
UDFBxxx | All internal variables local to a User-Defined Function Block A function block groups an algorithm and a set of private data. It has inputs and outputs. plus its IN and OUT parameters (the name of the group is the name of the program) |
Data type and dimension
Each variable must have a valid data type. It can be either a basic data type or a function block. In the later case, the variable is an instance of the function block. Physical I/Os must have a basic data type. Instances of function blocks can refer either to a standard block, or to a User Defined Function A function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. Block.
If the selected data type is STRING, you must specify a maximum length. This cannot exceed 255 characters.
Refer to the list of available data types for more information. Refer to the section describing function blocks for further information about how to use a function instance.
Additionally, you can specify dimension(s) for an internal variable, in order to declare an array.
Naming a variable
A variable must be identified by a unique name within its parent group. The
variable name cannot be a reserved keyword of the programming languages and
cannot have the same name as a standard function or function block
The name of a variable must begin by a letter or an underscore ("_") mark, followed by letters, digits or underscore marks. It is not allowed to put two consecutive underscores within a variable name. Naming is case-insensitive. Two names with different cases are considered as the same.
%IX | 1 byte input - BOOL or SINT |
%QX | 1 byte output - BOOL or SINT |
%IW | 2 bytes input - INT |
%QW | 2 bytes output - INT |
%ID | 4 bytes input - DINT or REAL |
%QD | 4 bytes input - DINT or REAL |
%IL | 8 bytes input - LINT or LEAL |
%QL | 8 bytes output - LINT or LEAL |
%IS | STRING input |
%QS | STRING output |
Attributes of a variable
Physical I/Os are marked as either "Input" or "Output". Each internal variable can be configured as Read/Write or Read Only. Read Only variables can be mapped to Outputs, but not to Inputs. This is because Inputs can change state and a Read Only variable would not be able to change its value to match the input state.
Parameters of User-Defined Function Blocks are marked as either INor OUT.