Difference between revisions of "MC-Basic:WITH"

From SoftMC-Wiki
Jump to: navigation, search
Line 10: Line 10:
  
 
|DESCRIPTION=
 
|DESCRIPTION=
This command sets a default motion element (axis or group). Thereafter, the motion element is operated on without having to explicitly indicate the motion element name. The default motion element exists only in a With block, which is terminated by the End With keywords.
+
This command sets a Default Motion Element (axis or group). Thereafter, the motion element is operated on without having to explicitly indicate the motion element name. <br>
 +
 
 +
There are 4 ways to use the '''With''' statement:
 +
 
 +
 
 +
# '''With - Config.prg''' - The element who set as Default Motion Element (DME) at the '''Config.prg''' file, function as DME for whole system. Therefore the only way to change/stop the DME is to "kill" the Config.prg task, and manually change the defaults. <br/> In case of using ''Local With'' statement - The DME will be the one declared on the local statement, and change back to the "Config.prg With" after the task finished. 
 +
# '''Local With''' - Set up a DME for local task. Unlike the "Config With" - using a ''local With'' statement require to use ''With <element>..........End With'' method. <br> This way of use replace the current DME (that declare on the Config.prg or in the Terminal) with a new one, until the task complete.
 +
#'''Terminal With''' - This way of use designated for run-time changes. After declaring a DME on the terminal, the chosen element will function as DME as long as the user didn't send an "End With" command via terminal. A ''With'' command used inside the terminal scope does not affect any programs or vice-versa.
 +
# '''WithGlobal''' - The DME which create with the "WithGlobal" command replaced the ''With - Config.prg'' without shut down the system, or create a new DME in case that there is no such a thing. For more information - [[MC-Basic:WITHGLOBAL|'''WITHGLOBAL''']]
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
<!-- The default motion element exists only in a With block, which is terminated by the End With keywords. -->
  
 
|TYPE=
 
|TYPE=
Line 27: Line 43:
 
Configuration, Task or Terminal
 
Configuration, Task or Terminal
  
In the Configuration scope, the specified motion element becomes the default motion element for the system unless there is another WITH command inside other scopes.
 
  
In Config.prg or the terminal, the End With keywords are not required. In the task scope, the End With keywords are required. A WITH command used inside the terminal scope does not affect any programs or vice-versa.
 
  
 
|LIMITATIONS=
 
|LIMITATIONS=
The WITH command cannot be set in run time. WITH commands cannot be nested.Each with block must be explicitly created and explicitly terminated before executing another with statement. A subroutine called from within a WITH block does not inherit the default motion element, so the element is not defined within the subroutine, and an error is flagged. A GOTO command is not allowed inside a WITH block; an error is flagged.
+
''With'' commands cannot be nested.
 +
A subroutine called from within a WITH block does not inherit the default motion element, so the element is not defined within the subroutine, and an error is flagged (Local With).
 +
A GOTO command is not allowed inside a WITH block; an error is flagged (Local With).  
  
 
|EXAMPLE=
 
|EXAMPLE=

Revision as of 11:24, 17 August 2017

Language: [[::MC-Basic:WITH|English]]  • [[::MC-Basic:WITH/zh-hans|中文(简体)‎]]

This command sets a Default Motion Element (axis or group). Thereafter, the motion element is operated on without having to explicitly indicate the motion element name.

There are 4 ways to use the With statement:


  1. With - Config.prg - The element who set as Default Motion Element (DME) at the Config.prg file, function as DME for whole system. Therefore the only way to change/stop the DME is to "kill" the Config.prg task, and manually change the defaults.
    In case of using Local With statement - The DME will be the one declared on the local statement, and change back to the "Config.prg With" after the task finished.
  2. Local With - Set up a DME for local task. Unlike the "Config With" - using a local With statement require to use With <element>..........End With method.
    This way of use replace the current DME (that declare on the Config.prg or in the Terminal) with a new one, until the task complete.
  3. Terminal With - This way of use designated for run-time changes. After declaring a DME on the terminal, the chosen element will function as DME as long as the user didn't send an "End With" command via terminal. A With command used inside the terminal scope does not affect any programs or vice-versa.
  4. WithGlobal - The DME which create with the "WithGlobal" command replaced the With - Config.prg without shut down the system, or create a new DME in case that there is no such a thing. For more information - WITHGLOBAL

Syntax

With <element name>

Availability

All versions

Scope

Configuration, Task or Terminal

Limitations

With commands cannot be nested. A subroutine called from within a WITH block does not inherit the default motion element, so the element is not defined within the subroutine, and an error is flagged (Local With). A GOTO command is not allowed inside a WITH block; an error is flagged (Local With).

Examples

A1.VMax=5000

A1.Vord=5000

A1.VCruise=3000

A1.PEMax=10

A1.PESettle=0.01

Move A1 100

Can be simplified using:
With A1
       VMax=5000
       Vord=5000
       VCruise=3000
       PEMax=10
       PESettle=0.01
       Move 100

End With