Skip to content

Namespaces

Namespaces group related types and POUs under a common name, preventing name clashes and making large projects easier to navigate.

A namespace is declared with NAMESPACE … END_NAMESPACE and contains type declarations, functions, function blocks, classes, interfaces and — nested — further namespaces.

NAMESPACE Drives
FUNCTION_BLOCK Motor
...
END_FUNCTION_BLOCK
TYPE
Direction : (FORWARD, REVERSE);
END_TYPE
END_NAMESPACE

Prefix the declaration with INTERNAL to restrict the namespace’s contents to the project that declares it (it is not exported for use by other projects / libraries).

NAMESPACE INTERNAL Diagnostics
...
END_NAMESPACE

Namespaces can be nested directly:

NAMESPACE Plant
NAMESPACE Drives
FUNCTION_BLOCK Motor ... END_FUNCTION_BLOCK
END_NAMESPACE
END_NAMESPACE

Refer to a member of a namespace by its dotted path. Nested namespaces are chained with ..

VAR
m1 : Drives.Motor;
m2 : Plant.Drives.Motor;
dir : Drives.Direction := Drives.Direction#FORWARD;
END_VAR

USING imports one or more namespaces so their members can be referenced unqualified. It may appear at the top of a POU or namespace, before the declarations.

USING Drives, Plant.Drives;
FUNCTION_BLOCK Conveyor
VAR
m : Motor; // resolves to Drives.Motor via USING
END_VAR
END_FUNCTION_BLOCK

Multiple namespaces are separated by commas in a single USING, or you can write several USING directives.