Variables

All variables used in programs 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 block.

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.

%Q...

Channels of an output board.

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

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.

  • The latest values from RETAIN variables are stored from the Runtime into a file on the hard disk drive (HDD).
  • In case of a warm (re)start, or a cold start, the Runtime initializes the variables with these stored values.
  • The Runtime stores these values periodically per default, triggered every 10ms in an own, lower priority thread.
  • The storage can be configured using either:
    • The menu tab entry Project/Settings.../Runtime/Cycle time.
    • The function F_SAVERETAIN used in the program code.
  • If a device with zenon does not have a robust HDD, it is recommended to deactivate the periodical storage and store seldom.
    • This can be done via a manual function call.

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.
  • See Call a Function Block 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.
      • 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.