Difference between revisions of "MC-Basic Generic Elements"

From SoftMC-Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
 
Writing complex multi-axis applications requires high level software organization. Avoid code repetition by encapsulating blocks of code into functions or subroutines. Code blocks of setup or query properties, which can be applied for all (or at least several) groups or axes in the system, and can be assembled into functions and subroutines. For example, if there are a number of identical motors in the system, their setup is the same. Write the following lines only once, instead of repeating them for each axis:
 
Writing complex multi-axis applications requires high level software organization. Avoid code repetition by encapsulating blocks of code into functions or subroutines. Code blocks of setup or query properties, which can be applied for all (or at least several) groups or axes in the system, and can be assembled into functions and subroutines. For example, if there are a number of identical motors in the system, their setup is the same. Write the following lines only once, instead of repeating them for each axis:
<br/><br/><br/><br/><br/><br/>
+
 
 
<pre>
 
<pre>
 
A1.PFac = 0x8000
 
A1.PFac = 0x8000
 
 
A1.VFac = A1.PFac/1000
 
A1.VFac = A1.PFac/1000
 
 
A1.AFac = A1.VFac/1000
 
A1.AFac = A1.VFac/1000
 
 
A1.JFac = A1.AFac/1000
 
A1.JFac = A1.AFac/1000
 
 
A1.VMax = 290
 
A1.VMax = 290
 
 
A1.AMax = 1500
 
A1.AMax = 1500
 
 
A1.DMax = A1.AMax
 
A1.DMax = A1.AMax
 
 
A1.Acc = A1.Amax
 
A1.Acc = A1.Amax
 
 
A1.Dec = A1.DMax
 
A1.Dec = A1.DMax
 
 
 
 
</pre>
 
</pre>
 +
 
Another example is writing common procedures as subroutines or functions that can later be applied in any system independently of how many axes or groups are defined. For example, switching on an output when an axis reaches its target:
 
Another example is writing common procedures as subroutines or functions that can later be applied in any system independently of how many axes or groups are defined. For example, switching on an output when an axis reaches its target:
 
<pre>
 
<pre>
 
<nowiki>While A1.IsMoving <> 0 </nowiki>
 
<nowiki>While A1.IsMoving <> 0 </nowiki>
 
 
  Sleep 1
 
  Sleep 1
 
 
End While
 
End While
 
 
Sys.Dout.1 = 1
 
Sys.Dout.1 = 1
 
</pre>
 
</pre>
 +
 
= ELEMENTID =
 
= ELEMENTID =
 
Depending on the system configuration, the MC can have several axes or groups defined. These motion elements are actually user interfaces of the system's internal memory or internal function calls. They are pointers to actual groups and axes.
 
Depending on the system configuration, the MC can have several axes or groups defined. These motion elements are actually user interfaces of the system's internal memory or internal function calls. They are pointers to actual groups and axes.
Line 40: Line 30:
 
<pre>
 
<pre>
 
SYS.NUMBERAXES = 4  
 
SYS.NUMBERAXES = 4  
 
 
Common Shared G2 As Group AxNm = A3 AxNm = A4
 
Common Shared G2 As Group AxNm = A3 AxNm = A4
 
 
Common Shared G1 As Group AxNm = A1 AxNm = A2
 
Common Shared G1 As Group AxNm = A1 AxNm = A2
 
 
 
? A1.ELEMENTID
 
? A1.ELEMENTID
 
 
1
 
1
 
 
? A2.ELEMENTID
 
? A2.ELEMENTID
 
 
2
 
2
 
 
? G2.ELEMENTID
 
? G2.ELEMENTID
 
 
33
 
33
 
 
? G1.ELEMENTID
 
? G1.ELEMENTID
 
 
34
 
34
 
</pre>
 
</pre>
 +
 
== Declaration ==
 
== Declaration ==
 
Generic elements resemble other MC-Basic variables (longs, doubles, strings) in declaration syntax and scope (global, static and local), as well as in the ability to define arrays of up to 10 dimensions.
 
Generic elements resemble other MC-Basic variables (longs, doubles, strings) in declaration syntax and scope (global, static and local), as well as in the ability to define arrays of up to 10 dimensions.
 
<pre>
 
<pre>
 
<nowiki>COMMON SHARED|DIM {SHARED} <axis_name> {[]…} AS GENERIC AXIS</nowiki>
 
<nowiki>COMMON SHARED|DIM {SHARED} <axis_name> {[]…} AS GENERIC AXIS</nowiki>
 
 
<nowiki>COMMON SHARED|DIM {SHARED} <group_name> {[]…} AS GENERIC GROUP</nowiki>
 
<nowiki>COMMON SHARED|DIM {SHARED} <group_name> {[]…} AS GENERIC GROUP</nowiki>
 
</pre>
 
</pre>
 +
 
== Assignment ==
 
== Assignment ==
 
<pre>
 
<pre>
 
<nowiki><</nowiki>generic_element_name<nowiki>>{[]…} = <</nowiki>real_element_name>
 
<nowiki><</nowiki>generic_element_name<nowiki>>{[]…} = <</nowiki>real_element_name>
 
 
<nowiki><</nowiki>generic_element_name<nowiki>>{[]…} = <</nowiki>generic_element_name<nowiki>>{[]…}</nowiki>
 
<nowiki><</nowiki>generic_element_name<nowiki>>{[]…} = <</nowiki>generic_element_name<nowiki>>{[]…}</nowiki>
 
</pre>
 
</pre>
 +
 
During declaration, all generic elements receive a zero element identifier, which prevents their usage as motion elements prior to assignment. If an unassigned generic element is used, an error is returned:
 
During declaration, all generic elements receive a zero element identifier, which prevents their usage as motion elements prior to assignment. If an unassigned generic element is used, an error is returned:
 
<pre>
 
<pre>
 
Common Shared Gen_Axis As Generic Axis
 
Common Shared Gen_Axis As Generic Axis
 
 
 
? Gen_Axis.ElementID
 
? Gen_Axis.ElementID
 
 
0
 
0
 
 
? Gen_Axis.VMax
 
? Gen_Axis.VMax
 
 
Error: 3005, "Nonexistent group or axis", Module: Motion
 
Error: 3005, "Nonexistent group or axis", Module: Motion
 
</pre>
 
</pre>
 +
 
Through assignment, a generic element receives the element identifier of another motion element, either “real” or generic, thus becoming a pointer to this element and acquiring all its properties.
 
Through assignment, a generic element receives the element identifier of another motion element, either “real” or generic, thus becoming a pointer to this element and acquiring all its properties.
 
<pre>
 
<pre>
 
Gen_Axis = A1
 
Gen_Axis = A1
 
 
? Gen_Axis.ElementID
 
? Gen_Axis.ElementID
 
 
1
 
1
 
 
? A1.VMax  
 
? A1.VMax  
 
 
290
 
290
 
 
? Gen_Axis.VMax  
 
? Gen_Axis.VMax  
 
 
290
 
290
 
</pre>
 
</pre>
 +
 
By recurring assignments, generic elements have the ability to change their pointed axis or group as many times as desired.
 
By recurring assignments, generic elements have the ability to change their pointed axis or group as many times as desired.
 
<pre>
 
<pre>
 
Gen_Axis = A2
 
Gen_Axis = A2
 
 
? Gen_Axis.ElementID
 
? Gen_Axis.ElementID
 
 
2
 
2
 
 
? A2.VMax  
 
? A2.VMax  
 
 
360
 
360
 
 
? Gen_Axis.VMax  
 
? Gen_Axis.VMax  
 
 
360
 
360
 
</pre>
 
</pre>
 +
 
The left-side (assigned) element of the assignment statement cannot be a “real” axis or group. It must always be a generic element.
 
The left-side (assigned) element of the assignment statement cannot be a “real” axis or group. It must always be a generic element.
 
<pre>
 
<pre>
 
A1 = Gen_Axis
 
A1 = Gen_Axis
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
</pre>
 
</pre>
 +
 
The right-side element of the assignment statement can be either generic or a “real”. A group cannot be assigned to a generic axis, and an axis cannot assign a generic group.
 
The right-side element of the assignment statement can be either generic or a “real”. A group cannot be assigned to a generic axis, and an axis cannot assign a generic group.
 
<pre>
 
<pre>
 
Common Shared Gen_Group As Generic Group
 
Common Shared Gen_Group As Generic Group
 
 
 
Gen_Axis = G1
 
Gen_Axis = G1
 
 
Error: 7067, "Wrong input type", Module: Translator
 
Error: 7067, "Wrong input type", Module: Translator
 
 
Gen_Group = A1
 
Gen_Group = A1
 
 
Error: 7067, "Wrong input type", Module: Translator
 
Error: 7067, "Wrong input type", Module: Translator
 
</pre>
 
</pre>
 +
 
Joint axes cannot be used in either sides of assignment statement.
 
Joint axes cannot be used in either sides of assignment statement.
 
<pre>
 
<pre>
 
Gen_Group.j1 = A1
 
Gen_Group.j1 = A1
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
 
Gen_Axis = G1.j1
 
Gen_Axis = G1.j1
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
</pre>
 
</pre>
Line 164: Line 123:
 
<pre>
 
<pre>
 
<nowiki>Dim Shared Gen_Axes_List[32] As Generic Axis</nowiki>
 
<nowiki>Dim Shared Gen_Axes_List[32] As Generic Axis</nowiki>
 
 
<nowiki>Gen_Axes_List[1] = A1</nowiki>
 
<nowiki>Gen_Axes_List[1] = A1</nowiki>
 
 
<nowiki>Gen_Axes_List[2] = A2</nowiki>
 
<nowiki>Gen_Axes_List[2] = A2</nowiki>
 
 
<nowiki>Gen_Axes_List[3] = A3</nowiki>
 
<nowiki>Gen_Axes_List[3] = A3</nowiki>
 
 
<nowiki>Gen_Axes_List[4] = A4</nowiki>
 
<nowiki>Gen_Axes_List[4] = A4</nowiki>
 
 
<nowiki>? Gen_Axes__List[1]</nowiki>
 
<nowiki>? Gen_Axes__List[1]</nowiki>
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
 
<nowiki>Gen_Axes__List[4] = Gen_Axes__List[1]+ 3</nowiki>
 
<nowiki>Gen_Axes__List[4] = Gen_Axes__List[1]+ 3</nowiki>
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
 
<nowiki>If Gen_Axes__List[3] > Gen_Axes__List[2] Then</nowiki>
 
<nowiki>If Gen_Axes__List[3] > Gen_Axes__List[2] Then</nowiki>
 
 
   -->Syntax Error
 
   -->Syntax Error
 
 
DeleteGroup Gen_Group
 
DeleteGroup Gen_Group
 
 
‘ Gen_Group is a global generic group
 
‘ Gen_Group is a global generic group
 
 
Error: 7039, "Syntax Error", Module: Translator
 
Error: 7039, "Syntax Error", Module: Translator
 
</pre>
 
</pre>
 +
 
== Functions ==
 
== Functions ==
 
Generic elements can be defined “by reference” in MC-Basic functions and subroutines. Axes or groups passed as arguments could be either “real” or generic. For example, axis setup can be encapsulated in a subroutine. In this example, the subroutine arguments are “real” axes:
 
Generic elements can be defined “by reference” in MC-Basic functions and subroutines. Axes or groups passed as arguments could be either “real” or generic. For example, axis setup can be encapsulated in a subroutine. In this example, the subroutine arguments are “real” axes:
 
<pre>
 
<pre>
 
Sub AxisSetUp(Ax As Generic Axis)
 
Sub AxisSetUp(Ax As Generic Axis)
 
 
Ax.PFac = 0x8000
 
Ax.PFac = 0x8000
 
 
Ax.VFac = Ax.PFac/1000
 
Ax.VFac = Ax.PFac/1000
 
 
Ax.AFac = Ax.VFac/1000
 
Ax.AFac = Ax.VFac/1000
 
 
Ax.JFac = Ax.AFac/1000
 
Ax.JFac = Ax.AFac/1000
 
 
Ax.VMax = 290
 
Ax.VMax = 290
 
 
Ax.AMax = 1500
 
Ax.AMax = 1500
 
 
Ax.DMax = Ax.Amax
 
Ax.DMax = Ax.Amax
 
 
Ax.Acc = Ax.Amax
 
Ax.Acc = Ax.Amax
 
 
Ax.Dec = Ax.DMax
 
Ax.Dec = Ax.DMax
 
 
 
 
 
End Sub
 
End Sub
 
 
Call AxisSetUp(A1)
 
Call AxisSetUp(A1)
 
 
Call AxisSetUp(A2)
 
Call AxisSetUp(A2)
 
 
Call AxisSetUp(A3)
 
Call AxisSetUp(A3)
 
 
Call AxisSetUp(A4)
 
Call AxisSetUp(A4)
 
</pre>
 
</pre>
 +
 
An entire array of generic elements can be passed (by reference) to functions and subroutines. Here, the argument is generic:
 
An entire array of generic elements can be passed (by reference) to functions and subroutines. Here, the argument is generic:
 
<pre>
 
<pre>
 
<nowiki>Sub AxesListSetUp(AxList[*] As Generic Axis)</nowiki>
 
<nowiki>Sub AxesListSetUp(AxList[*] As Generic Axis)</nowiki>
 
 
Dim i as long
 
Dim i as long
 
 
For i = 1 To Sys.NumberAxes
 
For i = 1 To Sys.NumberAxes
 
 
<nowiki>AxList[i].PFac = 0x8000</nowiki>
 
<nowiki>AxList[i].PFac = 0x8000</nowiki>
 
 
<nowiki>AxList[i].VFac = AxList[i].PFac/1000</nowiki>
 
<nowiki>AxList[i].VFac = AxList[i].PFac/1000</nowiki>
 
 
<nowiki>AxList[i].AFac = AxList[i].VFac/1000</nowiki>
 
<nowiki>AxList[i].AFac = AxList[i].VFac/1000</nowiki>
 
 
<nowiki>AxList[i].JFac = AxList[i].AFac/1000</nowiki>
 
<nowiki>AxList[i].JFac = AxList[i].AFac/1000</nowiki>
 
 
 
 
 
Next
 
Next
 
 
End Sub
 
End Sub
 
 
Call AxesListSetUp(Gen_Axes_List)
 
Call AxesListSetUp(Gen_Axes_List)
 
</pre>
 
</pre>
 +
 
The element type (i.e., axis or group) of an argument must match the function or subroutine declaration. Otherwise, a translation error occurs.
 
The element type (i.e., axis or group) of an argument must match the function or subroutine declaration. Otherwise, a translation error occurs.
 
<pre>
 
<pre>
 
Call AxisSetUp(G1) ‘ G1 is a group
 
Call AxisSetUp(G1) ‘ G1 is a group
 
 
--> Variable passed by reference has another type as in subroutine/function declaration
 
--> Variable passed by reference has another type as in subroutine/function declaration
 
</pre>
 
</pre>
 +
 
Trying to define generic elements “by value” generates an error:
 
Trying to define generic elements “by value” generates an error:
 
<pre>
 
<pre>
 
Sub AxisSetUp(ByVal Ax As Generic Axis)
 
Sub AxisSetUp(ByVal Ax As Generic Axis)
 
 
 
 
 
End Sub
 
End Sub
 
 
--> Cannot pass an axis or a group by value to subroutine/function
 
--> Cannot pass an axis or a group by value to subroutine/function
 
</pre>
 
</pre>
 +
 
Joint (J) axes cannot serve as function or subroutine arguments.
 
Joint (J) axes cannot serve as function or subroutine arguments.
 
<pre>
 
<pre>
 
Call AxisSetUp(G1.j1)
 
Call AxisSetUp(G1.j1)
 
 
--> Syntax Error
 
--> Syntax Error
 
</pre>
 
</pre>
 +
 
Generic elements can also serve as returned values of MC-Basic functions. Both “real” and generic elements can be assigned to returned values. For example, to generalize the former code, an axis-indexing function can be added, in which a “real” axis is assigned to the return value:
 
Generic elements can also serve as returned values of MC-Basic functions. Both “real” and generic elements can be assigned to returned values. For example, to generalize the former code, an axis-indexing function can be added, in which a “real” axis is assigned to the return value:
 
<pre>
 
<pre>
 
Function JointAxisByIndex(Byval I As Long) As Generic Axis
 
Function JointAxisByIndex(Byval I As Long) As Generic Axis
 
 
Select Case I  
 
Select Case I  
 
 
  Case 1
 
  Case 1
     
 
 
   JointAxisByIndex = G1.J1
 
   JointAxisByIndex = G1.J1
 
 
  Case 2
 
  Case 2
 
 
   JointAxisByIndex = G1.J2
 
   JointAxisByIndex = G1.J2
 
 
  …
 
  …
 
 
End Select
 
End Select
 
 
End Function  
 
End Function  
 
</pre>
 
</pre>
 +
 
Then, write a general loop:
 
Then, write a general loop:
 
<pre>
 
<pre>
 
Dim A As Generic Axis
 
Dim A As Generic Axis
 
 
For Index = 1 to Sys.NumberAxes
 
For Index = 1 to Sys.NumberAxes
 
 
A = AxisByIndex(Index)
 
A = AxisByIndex(Index)
 
 
  Call AxisSetUp(A)
 
  Call AxisSetUp(A)
 
 
Next
 
Next
 
</pre>
 
</pre>
 +
 
The generic element-returning function itself cannot be used as an argument since generic elements can only be passed by reference,and a function call is passed by value.
 
The generic element-returning function itself cannot be used as an argument since generic elements can only be passed by reference,and a function call is passed by value.
 
<pre>
 
<pre>
 
For Index = 1 to Sys.NumberAxes
 
For Index = 1 to Sys.NumberAxes
 
 
  Call AxisSetUp( AxisByIndex(Index) )
 
  Call AxisSetUp( AxisByIndex(Index) )
 
 
Next
 
Next
 
 
--> Cannot pass a constant or a complex expression by reference to subroutine/function
 
--> Cannot pass a constant or a complex expression by reference to subroutine/function
 
</pre>
 
</pre>
 +
 
Joint (J) axes cannot be assigned to return values.
 
Joint (J) axes cannot be assigned to return values.
 
<pre>
 
<pre>
 
Function JointAxisByIndex(Byval I As Long) As Generic Axis
 
Function JointAxisByIndex(Byval I As Long) As Generic Axis
 
 
  Select Case I
 
  Select Case I
 
 
   Case 1  
 
   Case 1  
 
 
 
     JointAxisByIndex = G1.J1 --> Syntax Error
 
     JointAxisByIndex = G1.J1 --> Syntax Error
 
 
   Case 2
 
   Case 2
 
 
     JointAxisByIndex = G1.J2 --> Syntax Error
 
     JointAxisByIndex = G1.J2 --> Syntax Error
 
 
   …
 
   …
 
 
End Select
 
End Select
 
 
End Function
 
End Function
 
</pre>
 
</pre>
Line 339: Line 241:
 
<pre>
 
<pre>
 
With Gen_Axis
 
With Gen_Axis
 
 
PFac = 0x8000
 
PFac = 0x8000
 
 
VFac = PFac/1000
 
VFac = PFac/1000
 
 
AFac = VFac/1000
 
AFac = VFac/1000
 
 
JFac = AFac/1000
 
JFac = AFac/1000
 
 
 
 
 
End With
 
End With
 
</pre>
 
</pre>
 +
 
'''WITH''' can be used on assigned and unassigned generic elements. These generic elements can be assigned and/or re-assigned later. This changes the '''WITH''' element without writing a new '''WITH''' command.
 
'''WITH''' can be used on assigned and unassigned generic elements. These generic elements can be assigned and/or re-assigned later. This changes the '''WITH''' element without writing a new '''WITH''' command.
 
<pre>
 
<pre>
 
With Gen_Axis
 
With Gen_Axis
 
 
? With
 
? With
 
 
GEN_AXIS
 
GEN_AXIS
 
 
? VMax
 
? VMax
 
 
Error: 3005, "Nonexistent group or axis", Module: Motion
 
Error: 3005, "Nonexistent group or axis", Module: Motion
 
 
Gen_Axis = A1
 
Gen_Axis = A1
 
 
? VMax
 
? VMax
 
 
290
 
290
 
 
Gen_Axis = A2
 
Gen_Axis = A2
 
 
? VMax
 
? VMax
 
 
360
 
360
 
</pre>
 
</pre>

Revision as of 14:39, 26 March 2014

Writing complex multi-axis applications requires high level software organization. Avoid code repetition by encapsulating blocks of code into functions or subroutines. Code blocks of setup or query properties, which can be applied for all (or at least several) groups or axes in the system, and can be assembled into functions and subroutines. For example, if there are a number of identical motors in the system, their setup is the same. Write the following lines only once, instead of repeating them for each axis:

A1.PFac = 0x8000
A1.VFac = A1.PFac/1000
A1.AFac = A1.VFac/1000
A1.JFac = A1.AFac/1000
A1.VMax = 290
A1.AMax = 1500
A1.DMax = A1.AMax
A1.Acc = A1.Amax
A1.Dec = A1.DMax
…

Another example is writing common procedures as subroutines or functions that can later be applied in any system independently of how many axes or groups are defined. For example, switching on an output when an axis reaches its target:

While A1.IsMoving <> 0 
 Sleep 1
End While
Sys.Dout.1 = 1

ELEMENTID

Depending on the system configuration, the MC can have several axes or groups defined. These motion elements are actually user interfaces of the system's internal memory or internal function calls. They are pointers to actual groups and axes.

During system configuration (“Sys.NumberAxes = n” and group definitions), each axis and group receives a unique element identifier. Axes get successive element identifiers ranging from 1 to 32, according to axis number. Groups get successive identifiers ranging from 33 to 64, according to declaration order. You cannot change these element identifiers.

The value of the element identifier is queried directly with ELEMENTID (read-only).

SYS.NUMBERAXES = 4 
Common Shared G2 As Group AxNm = A3 AxNm = A4
Common Shared G1 As Group AxNm = A1 AxNm = A2
? A1.ELEMENTID
1
? A2.ELEMENTID
2
? G2.ELEMENTID
33
? G1.ELEMENTID
34

Declaration

Generic elements resemble other MC-Basic variables (longs, doubles, strings) in declaration syntax and scope (global, static and local), as well as in the ability to define arrays of up to 10 dimensions.

COMMON SHARED|DIM {SHARED} <axis_name> {[]…} AS GENERIC AXIS
COMMON SHARED|DIM {SHARED} <group_name> {[]…} AS GENERIC GROUP

Assignment

<generic_element_name>{[]…} = <real_element_name>
<generic_element_name>{[]…} = <generic_element_name>{[]…}

During declaration, all generic elements receive a zero element identifier, which prevents their usage as motion elements prior to assignment. If an unassigned generic element is used, an error is returned:

Common Shared Gen_Axis As Generic Axis
? Gen_Axis.ElementID
0
? Gen_Axis.VMax
Error: 3005, "Nonexistent group or axis", Module: Motion

Through assignment, a generic element receives the element identifier of another motion element, either “real” or generic, thus becoming a pointer to this element and acquiring all its properties.

Gen_Axis = A1
? Gen_Axis.ElementID
1
? A1.VMax 
290
? Gen_Axis.VMax 
290

By recurring assignments, generic elements have the ability to change their pointed axis or group as many times as desired.

Gen_Axis = A2
? Gen_Axis.ElementID
2
? A2.VMax 
360
? Gen_Axis.VMax 
360

The left-side (assigned) element of the assignment statement cannot be a “real” axis or group. It must always be a generic element.

A1 = Gen_Axis
Error: 7039, "Syntax Error", Module: Translator

The right-side element of the assignment statement can be either generic or a “real”. A group cannot be assigned to a generic axis, and an axis cannot assign a generic group.

Common Shared Gen_Group As Generic Group
Gen_Axis = G1
Error: 7067, "Wrong input type", Module: Translator
Gen_Group = A1
Error: 7067, "Wrong input type", Module: Translator

Joint axes cannot be used in either sides of assignment statement.

Gen_Group.j1 = A1
Error: 7039, "Syntax Error", Module: Translator
Gen_Axis = G1.j1
Error: 7039, "Syntax Error", Module: Translator

Limitations

Generic elements cannot be printed. Arithmetic, logic and bitwise operators cannot be applied on generic elements.

Generic elements cannot be used as conditions in flow control statements and event definitions.

Generic elements cannot be recorded.

Generic elements cannot be structure elements.

Generic element cannot serve as parameters of C functions.

Deletion of global generic element cannot be performed with DELETEVAR or DELETEGROUP. Hardware or software reset (RESET ALL) is required.

Dim Shared Gen_Axes_List[32] As Generic Axis
Gen_Axes_List[1] = A1
Gen_Axes_List[2] = A2
Gen_Axes_List[3] = A3
Gen_Axes_List[4] = A4
? Gen_Axes__List[1]
Error: 7039, "Syntax Error", Module: Translator
Gen_Axes__List[4] = Gen_Axes__List[1]+ 3
Error: 7039, "Syntax Error", Module: Translator
If Gen_Axes__List[3] > Gen_Axes__List[2] Then
  -->Syntax Error
DeleteGroup Gen_Group
‘ Gen_Group is a global generic group
Error: 7039, "Syntax Error", Module: Translator

Functions

Generic elements can be defined “by reference” in MC-Basic functions and subroutines. Axes or groups passed as arguments could be either “real” or generic. For example, axis setup can be encapsulated in a subroutine. In this example, the subroutine arguments are “real” axes:

Sub AxisSetUp(Ax As Generic Axis)
Ax.PFac = 0x8000
Ax.VFac = Ax.PFac/1000
Ax.AFac = Ax.VFac/1000
Ax.JFac = Ax.AFac/1000
Ax.VMax = 290
Ax.AMax = 1500
Ax.DMax = Ax.Amax
Ax.Acc = Ax.Amax
Ax.Dec = Ax.DMax
…
End Sub
Call AxisSetUp(A1)
Call AxisSetUp(A2)
Call AxisSetUp(A3)
Call AxisSetUp(A4)

An entire array of generic elements can be passed (by reference) to functions and subroutines. Here, the argument is generic:

Sub AxesListSetUp(AxList[*] As Generic Axis)
Dim i as long
For i = 1 To Sys.NumberAxes
AxList[i].PFac = 0x8000
AxList[i].VFac = AxList[i].PFac/1000
AxList[i].AFac = AxList[i].VFac/1000
AxList[i].JFac = AxList[i].AFac/1000
…
Next
End Sub
Call AxesListSetUp(Gen_Axes_List)

The element type (i.e., axis or group) of an argument must match the function or subroutine declaration. Otherwise, a translation error occurs.

Call AxisSetUp(G1) ‘ G1 is a group
--> Variable passed by reference has another type as in subroutine/function declaration

Trying to define generic elements “by value” generates an error:

Sub AxisSetUp(ByVal Ax As Generic Axis)
…
End Sub
--> Cannot pass an axis or a group by value to subroutine/function

Joint (J) axes cannot serve as function or subroutine arguments.

Call AxisSetUp(G1.j1)
--> Syntax Error

Generic elements can also serve as returned values of MC-Basic functions. Both “real” and generic elements can be assigned to returned values. For example, to generalize the former code, an axis-indexing function can be added, in which a “real” axis is assigned to the return value:

Function JointAxisByIndex(Byval I As Long) As Generic Axis
Select Case I 
 Case 1
   JointAxisByIndex = G1.J1
 Case 2
   JointAxisByIndex = G1.J2
 …
End Select
End Function 

Then, write a general loop:

Dim A As Generic Axis
For Index = 1 to Sys.NumberAxes
A = AxisByIndex(Index)
 Call AxisSetUp(A)
Next

The generic element-returning function itself cannot be used as an argument since generic elements can only be passed by reference,and a function call is passed by value.

For Index = 1 to Sys.NumberAxes
 Call AxisSetUp( AxisByIndex(Index) )
Next
--> Cannot pass a constant or a complex expression by reference to subroutine/function

Joint (J) axes cannot be assigned to return values.

Function JointAxisByIndex(Byval I As Long) As Generic Axis
 Select Case I
  Case 1 
    JointAxisByIndex = G1.J1 --> Syntax Error
  Case 2
    JointAxisByIndex = G1.J2 --> Syntax Error
  …
End Select
End Function

WITH

WITH can be given in three contexts: configuration file, terminal and task. All three contexts of WITH can be applied to generic elements.

With Gen_Axis
PFac = 0x8000
VFac = PFac/1000
AFac = VFac/1000
JFac = AFac/1000
…
End With

WITH can be used on assigned and unassigned generic elements. These generic elements can be assigned and/or re-assigned later. This changes the WITH element without writing a new WITH command.

With Gen_Axis
? With
GEN_AXIS
? VMax
Error: 3005, "Nonexistent group or axis", Module: Motion
Gen_Axis = A1
? VMax
290
Gen_Axis = A2
? VMax
360