Namespaces in ST: declaration
NAMESPACE name
( * optional_begin *) USING Namespace_2;
USING Namespace_3; (* optional_end *)
(* user-defined declaration of POU and/or data types *)
END_NAMESPACE
Meaning |
declaration of a →namespace, name must be an →IEC-identifier (see example 1 below) or a fully qualified name A namespace can contain the following language elements:
It is also possible to declare namespaces (and the above language elements in them) within the ST-interface of a C-/C++-block. Restrictions
If you declare language elements in a namespace, you can sure use them outside of this namespace as well. It is also possible to specify a namespace when creating certain ST language elements (see " Creating application in ST ") or within the application navigator (see "Actions with folders/objects in context with namespaces"). |
NAMESPACE N1 (* starting the declaration of the namespace 'N1' *)
FUNCTION F1
// ... declaration
END_FUNCTION
TYPE
T1: STRUCT
Elem1 : BOOL;
// ... and more declaration
END_STRUCT;
END_TYPE
FUNCTION_BLOCK FB1
// ... declaration
END_FUNCTION_BLOCK
END_NAMESPACE (* ending the declaration of the namespace 'N1' *)
NAMESPACE Standard (* starting the declaration of the namespace 'Standard' *)
NAMESPACE Timers (* starting the declaration of the nested namespace 'Standard.Timers' *)
NAMESPACE HighResolution (* starting the declaration of the nested namespace 'Standard.Timers.HighResolution' *)
FUNCTION TimeTick: DWORD (* 'TimeTick' is included in the namespace 'Standard.Timers.HighResolution'; compare examples 3 and 4. *)
// ... declaration
END_FUNCTION
END_NAMESPACE (* ending the declaration of the nested namespace 'Standard.Timers.HighResolution' *)
TYPE
LOCAL_TIME: STRUCT
Elem1 : BOOL;
// ... and more declaration
END_STRUCT;
END_TYPE
FUNCTION_BLOCK TON
VAR_INPUT
In : BOOL;
PT : TIME;
END_VAR
// ... and more declaration
END_FUNCTION_BLOCK
END_NAMESPACE (* ending the declaration of the nested namespace 'Standard.Timers' *)
NAMESPACE Counters (* starting the declaration of the nested namespace 'Standard.Counters' *)
FUNCTION_BLOCK CUP
// ... declaration
END_FUNCTION_BLOCK
FUNCTION_BLOCK CDOWN
// ... declaration
END_FUNCTION_BLOCK
END_NAMESPACE (* ending the declaration of the nested namespace 'Standard.Counters' *)
END_NAMESPACE (* ending the declaration of the namespace 'Standard' *)
NAMESPACE Standard.Timers.HighResolution
FUNCTION TimeResolution: DWORD (* 'TimeResolution' is included in the namespace 'Standard.Timers.HighResolution'; compare examples 2 and 4. *)
// ... declaration
END_FUNCTION
END_NAMESPACE
NAMESPACE Standard.Timers
NAMESPACE HighResolution
FUNCTION TimeLimit: DWORD (* 'TimeLimit' is included in the namespace 'Standard.Timers.HighResolution'; compare examples 2 and 3. *)
// ... declaration
END_FUNCTION
END_NAMESPACE
END_NAMESPACE