Namespaces
Namespaces group related types and POUs under a common name, preventing name clashes and making large projects easier to navigate.
Declaring a namespace
Section titled “Declaring a namespace”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_TYPEEND_NAMESPACEInternal namespaces
Section titled “Internal namespaces”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_NAMESPACENested namespaces
Section titled “Nested namespaces”Namespaces can be nested directly:
NAMESPACE Plant NAMESPACE Drives FUNCTION_BLOCK Motor ... END_FUNCTION_BLOCK END_NAMESPACEEND_NAMESPACEQualified names
Section titled “Qualified names”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_VARThe USING directive
Section titled “The USING directive”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 ConveyorVAR m : Motor; // resolves to Drives.Motor via USINGEND_VAREND_FUNCTION_BLOCKMultiple namespaces are separated by commas in a single USING, or you can
write several USING directives.