Namespaces in ST: usage
Language elements of a namespace can be accessed from outside this namespace as follows:
Naming the fully qualified name
Define the language element with its fully qualified name. The fully qualified name of the language element consists of the namespace identifiers and the identifier of the language element that are separated by .
(dots).
Example |
---|
|
Restriction It is not possible to define function →calls with the fully qualified name. For such cases, define the |
Using the USING namespace directive
Define a USING
namespace directive. The USING
directive enables the access to language elements contained in the specified namespace to be used in the following elements:
Element |
Insert the |
---|---|
within the ST-object |
at the beginning of the ST-object (as first line in the ST-editor) |
within the global-object |
in front of the section |
within the PLC-object |
in front of the section
Best practice is to define only one |
within a namespace |
behind the name of the namespaces |
within a →function block |
behind the name of the function block |
within a →class | behind the name of the class |
within a →function |
behind the name of the function or the data type of the return value for the function |
Another element where the USING
directive can be inserted:
Element |
Insert the |
---|---|
within the ST-interface of a C-/C++-block |
after |
A USING
directive starts with the keyword USING
, followed by the fully qualified name of the namespaces and ;
(see example 1 below). The USING
directive enables the access to the specified namespace only, it does not enable access to other nested namespaces (see example 2 below).
It is also possible to specify a USING
instruction within the application navigator (see under "Actions with folders/objects in context with namespaces" for details). In this case, the ST-editor does not need a USING
namespace directive to this namespace.
Restrictions
|
The following examples are based on the ST-code of example 2 under "Namespaces in ST: declaration".
Example 1: Correct access |
---|
|
Example 2: Faulty access |
---|
|