Global Variables

In the Object Organizer, the Resources tab in the Global Variables folder contains three objects by default (the preassigned names of the objects are in brackets):

All variables defined in these objects are known throughout the project. If the Global Variables folder is not expanded (plus sign in front of the folder), open it by double-clicking or pressing <Enter> in the line. Select the corresponding object. The 'Edit Object' command opens a window with the global variables defined so far.

Several variable lists

If you have declared a large number of global variables and you want to better structure your global variable list, then you can create additional variable lists. Normal global variables (VAR_GLOBAL) and variable configurations (VAR_CONFIG) must be defined in separate objects. In the Object Organizer, select the Global Variables folder or one of the existing objects with global variables and execute the command 'Project' 'Insert Object'. Give the object an appropriate name in the dialog box that appears. This creates another object with the keyword VAR_GLOBAL. If you want to have an object with variable configuration, change the keyword to VAR_CONFIG accordingly.

Global variables

Global variables can be declared as "normal" variables, constants or remanent variables that are known throughout the project.

Creating a global variable list

To create a new global variable list, select the entry 'Global variables' in the Object Organizer at the Resources or a global variable list already created there. If you then select the command 'Project' 'Object' 'Insert', the Global Variable List dialog opens.

By the way, this dialog opens to display an already made configuration of the global variable list marked in the Object Organizer also with the command'Project' 'Object' 'Properties'.

Editing the lists for remanent global variables

If it is supported by the runtime system, it is possible to work with remanent variables.

There are two types of remanent global variables

Persistent and retain variables are retained in the event of a controlled shutdown of the runtime system or an 'online' 'reset cold' or a download.

Persistent variables are not automatically retain variables!

Remanent variables additionally get the keyword RETAIN or PERSISTENT...

Syntax:

VAR_GLOBAL RETAIN
(* Variablendeklarationen *)
END_VAR
VAR_GLOBAL PERSISTENT
(* Variablendeklarationen *)
END_VAR

Global constants

Global constants are additionally assigned the keyword CONSTANT.

Syntax:

VAR_GLOBAL CONSTANT
(* Variablendeklarationen *)
END_VAR

Variable configuration

In function blocks, addresses for inputs and outputs can be specified for variables defined between the keywords VAR and END_VAR which are not completely defined. Addresses that are not completely defined are marked with an asterisk.

Sample:

FUNCTION_BLOCK locio
VAR
    loci AT %I*: BOOL := TRUE;
    loco AT %Q*: BOOL;
END_VAR

Two local I/O variables are defined here, a local-In (%I*) and a local-Out (%Q*).

If you want to configure local I/Os, the object Variable_Configuration is available by default for variable configuration in the Object Organizer in the Resources tab. The object can be renamed and additional objects can be created for the variable configuration.

The variable configuration editor works like the declaration editor. Variables for local I/O configuration must be placed between the keywords VAR_CONFIG and END_VAR. The name of such a variable consists of a complete instance path, where the individual function block and instance names are separated by dots. The declaration must contain an address whose class (input/output) corresponds to that of the address not fully specified (%I*, %Q*) in the function block. The data type must also match the declaration in the function block.

Configuration variables whose instance path is not valid because the instance does not exist are marked as errors. Conversely, an error is also reported if no configuration exists for an instance variable. To get a complete list of all required configuration variables, the menu command 'All instance paths' in the menu 'Insert' can be used.

Sample:

In a program there is the following definition of function blocks:

PROGRAM PLC_PRG
VAR
    Hugo: locio;
    Otto: locio;
END_VAR

Then a correct variable configuration looks like this:

VAR_CONFIG
    PLC_PRG.Hugo.loci AT %IX1.0 : BOOL;
    PLC_PRG.Hugo.loco AT %QX0.0 : BOOL;
    PLC_PRG.Hugo.loci AT %IX1.0 : BOOL;
    PLC_PRG.Otto.loco AT %QX0.3 : BOOL;
END_VAR

Two local I/O variables are defined here, a local-In (%I*) and a local-Out (%Q*).

Global Variables 1:

An output that is used in the variable configuration must not be described in the project directly or via a variable (AT declaration), since this is not observed.

'Insert''All Instance Paths'

This command creates a VAR_CONFIG - END_VAR function block containing all instance paths present in the project. Existing declarations are not re-inserted to preserve existing addresses. This menu item is available in the variable configuration window when the project is compiled ('Project''Rebuild all').

Document frame

If you need to document a project several times, for example with German and with English comments, or if you want to document several similar projects that use the same variable names, then you can save yourself a lot of work by creating a document frame with the command 'Extras' 'Make Docuframe file'. You can load the created file into any text editor and edit it. The file begins with the line DOKUFILE, then follows a listing of the project variables, with three lines given for each variable, a line VAR, which indicates when a new variable is coming, then a line with the name of the variable, and finally an empty line. You can now replace this line with a comment about the variable. Simply delete variables from the text that you do not want to document. You can create as many document frames as you want for your project.

Global Variables 2:

Windows Editor with document frame

To use a document frame, enter the command 'Extras' 'Link Docu File'. If you now document the entire project, or print parts of your project, then the comment that you created in the document frame is inserted in the program text for all variables. This comment appears only in the printout!

'Extras' 'Make Docuframe File'

Use this command to create a document frame. The command is available when a Global Variable object is selected. The dialog for saving files under a new name opens. In the field for the file name the extension *.txt is already entered. Select any name. A text file is now created in which all variables of your project are listed.

'Extras' 'Link Docu File'

Use this command to select a document frame. The dialog for opening files opens. Select the desired document frame and press OK. If you now document the entire project, or print parts of your project, then the comment that you created in the document frame is inserted in the program text for all variables. This comment appears only in the printout! To create a document frame use the command 'Extras' 'Make Docuframe File'.