-

Defining Namespaces for POUs

Further Info
For a description what namespaces are, how to access elements of a namespace, nested namespaces, etc., see the topic "General Information on Namespaces".

This topic contains the following sections:

General notes on defining namespaces for POUs

Defining a namespace in the 'Settings' editor of the POU

Note
If the namespace for a POU is changed in the 'Settings' editor, the namespace is automatically updated in the COMPONENTS area and vice versa.

To define a namespace for a POU in the 'Settings' editor (not available for safety-related POUs), proceed as follows:

  1. In the COMPONENTS area, double-click the POU for which you want to define a namespace and open its 'Settings' editor in the editors area.
  2. In the 'Namespace' field, either enter a new namespace name or choose an existing name from the selection list (the selection list provides all namespaces defined in your project). Confirm the name with <Enter>.
    To create a nested namespace, enter the namespace names separated by a . (dot), e.g., NamespaceA.NamespaceB.NamespaceC.

    In the COMPONENTS area, the POU name is automatically updated displaying the full qualified name of the POU.

Defining a namespace in the COMPONENTS area

To define a namespace for a POU in the COMPONENTS area, proceed as follows:

  1. In the COMPONENTS area, select the POU and press <F2>. (If a namespace is already defined for a POU, pressing <F2> preselects only the POU name without the namespace).
  2. Enter the namespace by prefixing the POU name with the namespace name followed by a . (dot), e.g., NamespaceA.MyFB.
    To create a nested namespace, enter the namespace names separated by a . (dot), e.g., NamespaceA.NamespaceB.NamespaceC.MyFB.

To delete a namespace for a POU, either delete the namespace name entered in the 'Namespace' field in the 'Settings' editor of the POU or remove the namespace name in the POU name in the COMPONENTS area.

Defining 'Usings' for a POU

To use a POU outside of the namespace where it is defined, you usually have to specify the full qualified name of the POU. For example, if you want to instantiate the FB POU 'NamespaceA.MyFB' in a program POU, you have to specify the full qualified name 'NamespaceA.MyFB' in the program POU. In order not to have to enter the full qualified name every time, you can add the namespace of the FB POU to the list of 'Usings' of the program POU. This allows you to use the short name (without namespace identifier) of the FB POU in the calling program POU (see also the example below).

When defining 'Usings' for a POU, note the following:

To add a namespace to the 'Usings' list of a POU, proceed as follows:

  1. In the COMPONENTS area, double-click the POU for which you want to add a namespace to the 'Usings' list and open its 'Settings' editor in the editors area.
  2. In the 'Usings' table, left-click into the combobox below the table header and select a namespace from the list or enter the name of the desired namespace (Intellisense is supported). Confirm the selection with <Enter> or clicking outside of the combobox. The selection list contains all namespaces (including the nested namespaces) that are available in your project. (When you confirm the selection, a new empty entry is added to the table).

    Repeat this step for all namespaces you want to add.

Example of the 'Usings' behavior

To remove a namespace from the 'Usings' list, select the entry in the list and press <Del>.

Representation of FU and FB POUs in the graphic editor depending on namespace

In the graphic editor, the function block type is always displayed within the block symbol of an instantiated function or function block POU. Depending on the namespace setting for the instantiated POU and the 'Using' declaration for the calling POU, the block type is prefixed with an additional character as shown in the following examples for an FB POU:

Block symbolMeaning
FB POU is not bound to any namespace (POU is a member of the global namespace).
Labeling: no prefix character before block type.
FB POU is a member of a namespace. The calling POU is not part of the same namespace.
Labeling: hash (#) character before block type.
FB POU is a member of a namespace. The calling POU is part of the same namespace or the namespace is added to the 'Usings' list of the calling POU.
Labeling: asterisk (*) character before block type.

The tooltip of the block symbol always shows the full qualified name of the function block type.