Scope Operators

Definition

In extension to the IEC operators, there are several possibilities to disambiguate the access to variables or modules if the variables or module name is used multiple times within the scope of a project.

The following scope operators can be used:

  • global scope operator

  • global variable list name

  • enumeration name

  • library namespace

  • global node operator

Global Scope Operator

An instance path starting with dot (.) opens a global scope (namespace). Therefore, if there is a local variable with the same name <varname> as a global variable, then .<varname> refers to the global variable.

Global Variable List Name

You can use the name of a global variable list as a namespace for the variables enclosed in this list. Thus, it is possible to declare variables with identical names in different global variable lists and, by preceding the variable name by <global variable list name>., it is possible to access the desired one.

Syntax

<global variable list name>.<variable>

Example

The global variable lists globlist1 and globlist2 each contain a variable named varx. In the following line, varx out of globlist2 is copied to varx in globlist1:

globlist1.varx := globlist2.varx;

If a variable name declared in more than one global variable lists is referenced without the global variable list name as a preceding operator, a message will be generated.

Library Namespace

You can add the library namespace to a POU as a prefix separated by a dot to make the access to the POU unique. By default, the namespace of a library is identical to the library name.

Example: LIB_A.FB_A

Syntax

<library namespace>.<library POU>

Example

If a library which is included in a project contains the POU FB_A and there is also a POU FB_A defined locally in the project, then you can assign the name LIB_A.FB_A to the function block of the library in order to differentiate from the POU.

var1 := FB_A(in := 12); // Call of the project function block FB_A
var2 := LIB_A.FB_A(in := 22); // Call of the library function block FB_A

You can define another name for the namespace either in the Project Information when creating a library project in the Project Information (by default in the Project menu), or later in the Properties dialog box of an included library in the Library Manager.

Enumeration Name

You can use the type name of an enumeration to disambiguate the access to an enumeration constant. Therefore, it is possible to use the same constant in different enumerations.

The enumeration name has to precede the constant name, separated by a dot (.).

Syntax

<enumeration name>.<constant name>

Example

The constant Blue is a component of enumeration Colors as well as of enumeration Feelings.

color := Colors.Blue; // Access to enum value Blue in type Colors
feeling := Feelings.Blue; // Access to enum value Blue in type Feelings

Global Node Operator

Variables declared in GVLs or POUs of the Global node of the Applications tree can be accessed by prefixing them with the operator "__POOL.".