Namespace
Contents
Background
Application development requires “semi” global variables that are associated with a task and do not create conflicts if the same name is defined many times with a different namespace. Each task shall be able define a common shared variable with the same name, for example “var1”. Access from task is native like, “var1=1”, while access from command line or other tasks will require specification of a “namespace”, for example print task1::var1.
Introduction
This document describes the Namespace language feature. It presents the specifications and limitations of the feature and describes strategies in its implementation.
Specifications
Declaration
Syntax
Common shared <variable_name> as <data_type> Namespace is <namespace_name>
Scope
Global variables only.
Available for the following Data types
- Long
- Double
- String
- String of UTF8
- Joint of <robot_type>
- Location of <robot_type>
- Generic Joint
- Generic Location
- Structure
- Const Long
- Const Double
- Const String
- Const String of UTF8
- Const Joint of <robot_type>
- Const Location of <robot_type>
Namespace name
The name of a PRG task without the extension. Since it's a task name, it cannot include more than 8 characters. Characters can only be alphabetical, numerical and underline. The namespace can be a reserved word. The namespace task doesn't have to be loaded in memory.
Limitations
- Real axes - Real groups - Generic axes - Generic groups - User errors - User notes - User Semaphores - Cam tables - Compensation tables - Conveyers - PLS
In functions
- Cannot be used for function names.
- Cannot be used for parameter names.
MySub (byval param as long) namespace is MyTask → syntax error in prototype call MyTask::MySub(10) → syntax error in function call MyFunc (param as long namespace is MyTask) as string → syntax error in prototype
Multiple global variables with identical names and different namespaces are allowed
Variables with identical names and different namespaces can also vary in number of dimensions (including scalars vs. arrays), data types (including different structure types) and robot types (for point variables).
/* identical with different namespaces */ Common shared Var1 as Long Namespace is Task1 Common shared Var1 as Long Namespace is Task2 /* various number of dimensions with different namespaces */ Common shared Var2 as Double Namespace is Task1 Common shared Var2[10] as Double Namespace is Task2 Common shared Var2[3][5][7] as Double Namespace is Task3 /* various data types with different namespaces */ Common shared Var3 as String of UTF8 Namespace is Task1 Common shared Var3 as Generic Location Namespace is Task2 /* various robot types with different namespaces */ Common shared Var4 as Joint of XY Namespace is Task1 Common shared Var4 as Joint of XYZR Namespace is Task2 /* various structure types with different namespaces */ Common shared Var5 as StructType1 Namespace is Task1 Common shared Var5 as StructType2 Namespace is Task2 /* and also one without a namespace */ Common shared Var1 as Long
Applying to variables with namespaces
Access
Outside the "namespace" task
The variable can only be accessed by using a prefix added to its name. The prefix will be composed of the namespace, followed by a double colon.
<namespace>::<variable_name>
Within the "namespace" task
The variable can be accessed directly, without using its namespace prefix. It can also be accessed through its namespace prefix.
Common shared Str1 as string namespace is StrTask In StrTask.PRG: Program StrTask::Str1 = "ABCD" ? Str1 → ABCD Str1 = "EFGH" ? StrTask::Str1 → EFGH End Program From terminal, another task or library: Str = "IJKL" → Variable Str1 does not exist ? Str1 →Variable Str1 does not exist /* Unless there is a global Str1 without a namespace */ StrTask::Str1 = "IJKL" ? StrTask::Str1 →IJKL /* Namespace can be used with a function\ subroutine argument */ Common shared Str1 as string namespace is StrTask In StrTask.PRG: ? MyFunc (StrTask::Str1) ? MyFunc (Str1) From terminal, another task or library: ? MyFunc (StrTask::Str1) ? MyFunc (Str1) Variable Str1 does not exist /* Unless there is a global Str1 without a namespace */
Priority
Priority within program block
Below static variables and above global variables.
Common shared X1 as long = 1 Common shared X1 as long namespace is MyTask = 2 Common shared X2 as long namespace is MyTask = 30 Dim shared X2 as long = 40 Common shared X3 as long namespace is MyTask = 500 Dim shared X3 as long = 40 In MyTask.PRG: PROGRAM Dim X3 as long = 600 ?X1 → 2 /* X1 refers to the "namespaced" variable */ ?X2 → 40 /* X2 refers to the static variable */ ?X3 → 600 /* X3 refers to the local variable */ END PROGRAM Common shared X1 as long = 10 Common shared X1 as long namespace is MyTask In MyTask.PRG (task paused): PROGRAM X1 = 2 /* X1 refers to the "namespeced" variable */ END PROGRAM ? MyTask.PRG.MyTask::X1 →2 ? MyTask.PRG. X1 →2 /* X1 refers to the "namespeced" variable and not to the global variable */
Priority in watch command
Within commands
Commands using variables
- FOR loop
- ASCII system function
- PRINTUSING$ command
- WATCH command
Common shared Index1 as long namespace is MyTask Common shared Str1 as string namespace is MyTask Outside and inside MyTask.PRG: For MyTask::Index1 = 1 to 10 … Next MyTask::Index1 ? ASCII (MyTask::Str1, 1) PRINTU$ MyTask::Str1, "##"; 1 WATCH MyTask::Index1 /* Available only from terminal */ Inside MyTask.PRG: For Index1 = 1 to 10 … Next Index1 ? ASCII(Str1, 1) PRINTU$ Str1, "##"; 1
Commands using array names
- ARRAYSIZE system function - PASS Motion command
Save command
In order to save a "namespaced" variable, the variable name string- parameter must include the namespace prefix, even inside the namespace task.
Varlist command
In order to exhibit "namespaced" variables through Varlist command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?).
Deletevar command
In order to delete "namespaced" variables through Deletevar command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?). As with regular global variables, "namespaced" variables cannot be deleted until all tasks applying to these variables will be unloaded.