Variables

All variables used in programsClosed The act of performing a sequence of instructions or commands. must be declared first in the variable editor.

Each variable belongs to a group and must be identified by a unique name in its group.

Groups

A group is a set of variables.

A group refers to a physical class of variables or identifies the variables local to a program or user-defined function blockClosed A function block groups an algorithm and a set of private data. It has inputs and outputs..

This table lists the possible groups:

Groups

Description

%I...

Channels of an input board.

  • Variables with same data type are linked to a physical input device.
  • See Variables for more information.

%Q...

Channels of an output board.

  • Variables with same data type are linked to a physical output device.
  • See Variables for more information.

GLOBAL

Internal variables known by all programs.

PROGRAMxxx

All internal variables local to a program.

The name of the group is the name of the program.

Retain Variables

Non volatile internal variables known by all programs.

UDFBxxx

All internal variables local to a User-Defined Function Block 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 a function block, 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 Block.

If the selected data type is STRING, you must specify a maximum length.
This cannot exceed 255 characters.

  • See the list of Data Types for more information.
  • See Call a Function Block for more information about using a function instance.
  • Specify dimensions for an internal variable to declare Arrays.

Name 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.
    • have the same name as a standard or C function or function block.
    • See the List of C Functions webpage.
  • A variable must not have the same name as a program or a user-defined function block.
  • The name of a variable must begin by a letter or an underscore (_), followed by letters, digits, or underscore marks.
    • Two consecutive underscores in a variable name is not allowed.
  • Naming is case-insensitive.
    • Two names with different cases are considered as the same.

Variable Attributes

Physical I/Os are marked as either Input or Output.

  • Each internal variable can be configured as Read / Write or Read-only.
    See Attributes for more information.
    • Read-only variables can be mapped to Outputs but not to Inputs.
    • Inputs can change state and a Read-only variable cannot change its value to match the input state.
  • Parameters of User-Defined Function Blocks are marked as either INor OUT.