Difference between revisions of "Namespace"

From SoftMC-Wiki
Jump to: navigation, search
(Save command)
(Varlist command)
Line 274: Line 274:
 
==== Varlist command====
 
==== 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 (*, ?).
 
In order to exhibit "namespaced" variables through Varlist command, the variables must include a namespace prefix, which can be partial with wild cards (*, ?).
 +
<pre>
 +
Common shared Var1 as long namespace is MyTask1 = 10
 +
Common shared Var2 as double namespace is MyTask1 = 0.5
 +
Common shared Var1 as string namespace is MyTask2 = "ABC"
  
 +
At least part of the namespace prefix must be used in Varlist command:
  
 +
? Varlist MyTask1::Var1 →MyTask1::Var1
 +
? Varlist MyTask1::* →MyTask1::Var1, MyTask1::Var2
 +
? Varlist MyTask?::Var? →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1
 +
? Varlist *::Var1 →MyTask1::Var1, MyTask2::Var1
 +
? Varlist *::* →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1
  
 
+
/* Without any part of the namespace prefix */
 
+
? Varlist Var* →No variables found
 
+
</pre>
 
 
 
 
 
 
 
 
  
 
====Deletevar command====
 
====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 (*, ?).  
 
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.
 
As with regular global variables, "namespaced" variables cannot be deleted until all tasks applying to these variables will be unloaded.

Revision as of 07:25, 24 April 2016

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

Unavailable for the following elements

- 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
Common shared JntArray[4] as joint of XYZR namespace is MyTask 
Common shared DblArray[4] as double namespace is MyTask 

Outside and inside MyTask.PRG:

PASS Scara Nodes = MyTask:: JntArray Stretchvector = MyTask:: DblArray

? ARRAYSIZE(MyTask :: JntArray, 1)

Inside MyTask.PRG:

PASS Scara Nodes = JntArray Stretchvector = DblArray

? ARRAYSIZE(JntArray, 1)

Save command

In order to save a "namespaced" variable, the variable name string- parameter must include the namespace prefix, even inside the namespace task.

Common shared Var1 as long namespace is MyTask = 10
Common shared Var1 as long = 1000

Namespace prefix should be used both inside and outside MyTask.PRG:
/* saving a “namespaced” variable */
Save File = "MySave.PRG" Type = Long Variablename = "MyTask::Var1"

Result in MySave.PRG:

MYTASK::VAR1 = 10

/* saving a regular (that doesn’t have a namespace) global variable */
Save File = "MySave.PRG" Type = Long Variablename = " Var1"

Result in MySave.PRG:

VAR1 = 1000

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 (*, ?).

Common shared Var1 as long namespace is MyTask1 = 10
Common shared Var2 as double namespace is MyTask1 = 0.5
Common shared Var1 as string namespace is MyTask2 = "ABC"

At least part of the namespace prefix must be used in Varlist command:

? Varlist MyTask1::Var1	 →MyTask1::Var1
? Varlist MyTask1::*	 →MyTask1::Var1, MyTask1::Var2
? Varlist MyTask?::Var?	 →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1
? Varlist *::Var1		 →MyTask1::Var1, MyTask2::Var1
? Varlist *::*			 →MyTask1::Var1, MyTask1::Var2, MyTask2::Var1

/* Without any part of the namespace prefix */	
? Varlist Var*			 →No variables found

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.