Skip to main content

3.1 Introduction to Namespace

3.1.1 Concept of Namespace

  • A namespace is a language element that combines other language elements into a combination. The name of a language element declared in one namespace can be used in other namespaces
  • Elements of the namespace can be accessed outside the namespace by adding the namespace name in front. Being in the same namespace is not required but allows access by this method

3.1.2 Significanceof Namespace

  • Namespace can avoid naming conflicts of identifiers such as variables and functions

3.1.3 Use of namespace

  • For specific UI usage, please refer to User Manual

  • SYS is the system library namespace, which can be accessed by default users. SYS is referenced by default when compiling

  • Users need to write the namespace name when writing STRUCT, GVS, and PU

  • For PRG variables, the PRG name is a sub-namespace; the full access path is ".namespace.PRG name.Variable name". user can directly use the variable name to access within this PRG

  • For GVS variables, the full access path is ".namespace.variable name"

  • For the STRUCT type, the full access path is ".namespace.STRUCT name"

  • For FB type, the full access path is ".namespace.FB name"

  • Access to FB instance

    • If the FB instance is declared in GVS, the full access path is ".namespace.FB instance name"
    • If the FB instance is declared in another FB, the FB instance can only be accessed in the FB where the current FB instance variable is declared. Use the "FB instance name" directly
  • For FC calls, the full access path is ".namespace.FC name"

  • Referenced in the same namespace, the namespace can be defaulted, but if the related name exists in SYS in the default mode, compilation error will occur. The namespace cannot be defaulted at this time

3.1.4 Namespace reconstruction

Serial numberObject identifierModify only this object identifierReconstruct all referenced objects
1Default namespaceOnly modify the default namespace name and do not reconstruct other objects
2GVS namespace nameOnly modify the GVS namespace nameRename this GVS namespace + reconstruct the references of all global variables under this GVS name (including: IO mapping table, monitoring table)
3The namespace name of the PRGModify only the namespace name of the PRG and change it to the file name simultaneouslyRename the namespace of this PRG + reconstruct all references to this PRG, including references to all variables of the PRG; including monitoring tables
4FC namespace nameModify only the FC namespace name and modify the file name simultaneouslyRename this FC namespace + reconstruct all references (calls) of this FC
5FB namespace nameModify only the FB namespace name and modify the file name simultaneouslyRename this FB namespace + reconstruct the FB type in all instance declarations of this FB
6Namespace name of UDT (struct)Modify only the namespace name of the STRUCT and modify the file name simultaneouslyRename this UDT namespace + reconstruct the UDT type in all instance declarations of this UDT
warning
  • "." represents the global namespace. The global namespace "." can only be followed by a specific first-level namespace name, not other object identifiers (variable names, PU names, UDT names). In other words, variable names, PU names, and UDT names must be defined with specific namespace names
  • Users cannot use "SYS" as the first-level namespace name. "SYS" is the first-level namespace name of the system library, and user program units can access it by default. When the system is compiled, "SYS" will be referenced by default ("SYS" is only the first-level namespace name occupied by the system, not a keywords)
  • In the same namespace, member names cannot be repeated
  • Variable names, PU names, and UDT names must start with "." if they use full access paths. However, if the namespace of a global variable is a sub-namespace of a PU namespace, the global variable can be accessed in the PU using "sub-namespace.variable name"
  • When the identifier is accessed using a fully qualified name, it must start with "."
  • If the object name in the program unit does not start with ".", the system will only check the current namespace of the PU and members under SYS (including sub-namespaces) by default
  • When compiling, the variables in the program unit that do not start with "." are queried from local to global. If both local and global variables exist, local variables are accessed first