Ch. 22 - Branching by Using Flow Control - PCDMIS
Ch. 22 - Branching by Using Flow Control - PCDMIS
Ch. 22 - Branching by Using Flow Control - PCDMIS
Introduction
Suppose you have a part with many features, but you just want to measure a few
features over and over to get a comprehensive statistical set of data for those
features. Suppose you want to jump to a particular part in your part program
dependent on a response from the user. You can accomplish tasks such as these, and
many others, by using flow control commands. By setting up conditions for certain
commands, you can control the flow of your part program.
This chapter will provide you with the information you need to accomplish such
tasks. It explains the syntax conditional statements, loops, and subroutines. It also
provides many code samples.
Note: When looping or branching occurs in the code samples, indentation has been
used for clarity to show statements assigned to a certain condition. In the actual Edit
window code, you won't see any indentation.
control pair type command into the Edit window, simply type the command, or
choose a command from this submenu.
If / End If
The If / End If menu option allows you to add a conditional block to the part
program. The items between the IF and the END IF commands will only execute if
the expression for the IF command evaluates to true (nonzero). Otherwise, flow of
execution will jump to the first command after the END/IF command.
The Edit window command line for a IF / END IF statement reads:
IF/expression
END_IF/
To insert the If / End If commands:
1. Place the cursor in the desired location of the Edit window.
2. Select If / End If from the menu bar. The IF / END IF statement
will appear in the Edit window.
next command following the END ELSE IF command. If any of the IF / ELSE if
expressions above the current block evaluate to true, all subsequent ELSE IF / END
ELSE IF blocks in this sequence will be skipped.
The Edit window command line for a ELSE IF / END ELSE IF statement
reads:
ELSE_IF/expression
END_ELSE_IF/
To insert the ELSE IF / END ELSE IF commands:
1. Place the cursor in the desired location of the Edit window, after an
existing IF/END IF statement or ELSE IF/END ELSE IF
statement.
2. Select Else If / End Else If from the menu bar. The ELSE IF /
END ELSE IF statement will appear in the Edit window.
Note: This type of block is only valid when positioned after an IF / END IF or
ELSE IF / END ELSE IF block. Invalidly positioned control pairs are shown in red
text in the Edit window.
PNT2=FEAT/POINT,RECT
…
…
ENDMEAS/
IF/PNT2.X<6.9 OR PNT2.X>7.1
COMMENT/OPER,"The measured X value of PNT2: " + PNT2.X
+ " is out of tolerance."
END_IF/
ELSE_IF/PNT2.Y<3.3 OR PNT2.Y>3.5
COMMENT/OPER,"The measured Y value for PNT2: " +
PNT2.Y + " is out of tolerance."
END_ELSEIF/
ELSE_IF/PNT2.Z<.9 OR PNT2.Z>1.1
COMMENT/OPER,"The measured Z value for PNT2: "
+ PNT2.Z + " is out of tolerance."
END_ELSEIF/
Explanation of Sample Code
This code first tests the X value of the point. If the condition evaluates to false, then
the code tests for the Y value. If the condition for the Y value evaluates to false, then
it tests for the Z value.
If any of these conditions evaluates to true, PC-DMIS displays the comment
associated with it and skips the remaining conditional statements.
IF/PNT2.X<6.9 OR PNT2.X>7.1
This line is the expression. It tests to see if the measured X value is less
than 6.9 or greater than 7.1. If it exceeds either of these boundaries it
executes the first comment.
END_IF
This line ends the execution of commands inside the IF / END IF block
…
ENDMEAS/
ENDELSE
Explanation of Sample Code
C1=COMMENT/YESNO
This line takes and stores the YES or NO response from the user.
IF/C1.INPUT=="YES"
This line is the expression. It tests to see if the input of comment 1 is a
YES. If it's a YES then the IF statement is TRUE and continues
executing the statements after the IF statement, in this case it measures
the PNT1 feature. If NO it moves to the END_IF statement.
END_IF
This line ends the execution of commands inside the IF / END IF block
of code. Any command following this line is where PC-DMIS will go
to if the user clicks No at the comment.
ELSE
If the above IF / END IF block evaluates to false then command lines
falling after this line and before the ENDELSE line will be executed. In
this case, PNT2 gets executed.
ENDELSE
This line ends the execution of commands inside the ELSE /
ENDELSE block of code.
…
ENDMEAS/
ASSIGN/COUNT = COUNT + 1
COMMENT/OPER,"Measured " + COUNT + " out of " + C1.INPUT +
" times."
END_WHILE/
Explanation of Sample Code
C1=COMMENT/INPUT
This line takes and stores the integer input from the user into the
variable C1.INPUT.
ASSIGN/COUNT = 0
This line initializes COUNT, a user-defined variable, and gives it an
initial value of 0. The code uses this variable to count the number of
times PC-DMIS measures the feature inside the loop.
WHILE/COUNT < C1.INPUT
This line is the expression. It tests to if the value of COUNT (initially set
to 0) is less than the integer selected by the user. If this tests true, then
the statements in following WHILE/ and before END_WHILE/ are
executed
ASSIGN/COUNT = COUNT + 1
This line increments the COUNT variable by one so that it eventually
exits the loop when it fails the condition test.
COMMENT/OPER,"Measured " + COUNT + " out of " + C1.INPUT
+ " times."
This line displays a message showing the number of times, out of the
total, that the loop is running.
END_WHILE
This line ends the execution of commands inside the WHILE / END
WHILE block as long as the condition is false. Other wise when PC-
DMIS encounters this command it loops back to the WHILE statement.
Do / Until
The Do / Until menu option allows you to add a conditional loop to the part
program. The items between the DO and the UNTIL commands will continue to
execute in a loop until the expression of the UNTIL command evaluates to TRUE
(nonzero). The DO/ UNTIL commands can be added anywhere in the part program.
The expression is tested at the end of each loop.
The Edit window command line for a DO / UNTIL statement reads:
DO/
UNTIL/ expression
To insert DO / UNTIL commands:
1. Place the cursor in the desired location of the Edit window.
2. Select Do / Until from the menu bar. The DO / UNTIL statements
will appear in the Edit window.
topic, except that PC-DMIS tests for the condition at the end of the loop instead of at
the beginning.
SELECT/C1.INPUT
This line of code takes a number or string value (in this case a number)
typed by the user and determines which CASE/END_CASE block will
execute from the input. Notice that SELECT / END_SELECT pair
surrounds the entire list of code. All CASE / END_CASE and
DEFAULT CASE / END_DEFAULT CASE pairs must reside within
these two lines.
END_SELECT
This marks the end of the code held inside the SELECT / END
SELECT pair.
CASE1 through CASE5
Depending on the value of C1.INPUT, one of the CASE code blocks
executes. For example, if C1.INPUT evaluates to 1, the CASE 1
block of code executes, measuring CIR1. If it evaluates to 2, then the
CASE 2 block of code executes, measuring CIR2, and so forth.
END_CASE
These lines end the specific case blocks of code.
DEFAULT CASE
If the value of the C1.INPUT doesn’t match any of the defined CASE
statements (if the value isn’t a number one through five) then the
DEFAULT CASE code block executes. In this case it displays a
message letting you know that you are exiting the loop.
Notice how the DO / UNTIL loop surrounds the entire code sample. This allows the
user to continue to choose from the menu created from the COMMENT/INPUT line
until the user selects a character not recognized by the CASE statements.
previous CASE / END CASE blocks within the corresponding SELECT / END
SELECT block evaluated to false. Only one DEFAULT CASE / END DEFAULT
CASE block is allowed within a SELECT/ END SELECT block. The DEFAULT
CASE / END DEFAULT CASE block must be located after all CASE / END CASE
blocks within the SELECT / END SELECT block.
The Edit window command line for a DEFAULT CASE / END DEFAULT
CASE statement reads:
DEFAULT CASE/
END_DEFAULT_CASE/
To insert DEFAULT CASE/ END DEFAULT CASE commands:
1. Place the cursor in the desired location of the Edit window noting
positional limitations as stated above.
2. Select Default Case / End Default Case from the menu bar.
The DEFAULT CASE / END DEFAULT CASE statements will
appear in the Edit window.
The Looping menu option allows you to repeat the part program (or portions of the
part program) with or without any of the offsets. The LOOP command can be added
anywhere in the part program, although this function is most useful at the beginning
and end of the program.
To Use Looping:
1. Select Looping from the menu bar. The Looping Parameters
dialog box will appear.
2. Make any necessary changes to the boxes.
3. Select parameters as needed (i.e. Number of Parts, Start Number,
Skip Number, offsets in XY or Z, Angle).
4. Place the cursor in a location in the Edit window where you want
to begin the loop.
5. Select the OK button.
The Edit window command line for looping reads:
VARNAME = LOOP/START, ID = Y/N, NUMBER = 0, START = 1,
SKIP = ,
OFFSET: XAXIS = 0, YAXIS = 0, ZAXIS = 0, ANGLE = 0
Note: To complete the looping procedure, you must have an End Loop command
inside the Edit window. PC-DMIS will loop Edit window commands that the
LOOP/START and LOOP/END commands encompass. See "End Loop" on page 22-
12 for more information.
Variable ID
The Variable ID box allows you to define the variable name used to track the loop's
current iteration (or current loop within the number of specified loops). During the
part program's execution, this variable will be equal to the current iteration number
of the loop.
XYZ Axis
These boxes sets up the x (y or z) offset between parts, or patterns on the same part.
The first offset is based on the part's origin.
Angle
The Angle box sets up the angular offset between parts, or patterns on the same part.
The first offset is based on the part's origin.
Number of Parts
The Number of Parts box tells PC-DMIS the number of parts that the fixture holds
(or patterns on the part) in the x (y or z) direction. PC-DMIS will also ask for the
starting part (pattern) number.
Example: You have 10 parts in the x (y or z) direction, and you want to start with
position number 5. Enter 10 (ten) for the total number of parts and 5 (five) for the
starting position.
Start Number
The Start Number box tells PC-DMIS the starting position number in a series of
parts.
Example: You have 10 parts, and you want to start with position number 5, you
would enter 10 for the total number of parts and 5 for the starting position.
Skip Number
The Skip Number box repeats a part program the indicated number of times,
allowing you to skip a specified increment.
Example: You can set the parameter to skip every third increment of the loop. If the
number three is indicated, PC-DMIS will measure the first and second part and then
skip to the fourth part.
Loop Ids
If this option is selected, PC-DMIS increments the feature ID's (within the loop) to
coincide with the loop increment.
Example: CIR1 will become CIR1[1] on the first loop, CIR1[2] on the second loop,
and so on.
End Loop
The End Loop button completes the looping process. The command LOOP/START
must be followed by the command LOOP/END in the Edit window.
Creating Labels
The Label option opens the Edit Label Name dialog box which allows you to
create a name identification that can be used with a GOTO or IF statement.
PC-DMIS will allow you to create the ID using up to fifteen characters. The ID will
be displayed using all capital letters.
The Edit window command line for the Label option reads:
ID = LABEL/
To create a label:
1. Select the location in the Edit window.
2. Select Label from the menu bar.
3. Type the ID for the label in the New Label Name box.
4. Click the OK button.
5. The label ID will appear in the next possible location in the Edit
window.
Jumping to a Label
The Goto option will bring up the GoTo dialog box which allows you to create
GOTO statements within your part program. When the program is executed and PC-
DMIS encounters a GOTO statement, it will move to the location of the label
identification.
The Edit window command line for GOTO reads:
GOTO/label_ID
To create a GOTO Statement in the Edit window:
1. Select Goto from the submenu.
2. Select the label you want to use from the Current Labels box.
3. Click the OK button.
The Goto dialog box also allows you to create new label ID’s that can then be
attached to a GOTO statement. To do this:
1. Select Goto from the submenu.
2. Type the name of the label you will create in the Goto Label box.
The GOTO/label command is entered in the Edit window.
Note: If a label is created within the GoTo dialog box, you must create the label
identification using the Label menu option prior to executing the part program.
Goto Label
The GoTo Label box allows you to type in an existing label that the part program
will GOTO.
Current Labels
The Current Labels box contains a listing of existing labels which you can select
with the mouse.
The If Goto option will allow you to create IF GOTO statements within your part
program. When the part program is executed and PC-DMIS encounters an IF
statement, it will GOTO the location of the label identification if the specified
expression evaluates to a non-zero value. See the "Using Expressions and Variables"
chapter for information on creating expressions.
The Edit window command line for an IF_GOTO statement reads:
IF_GOTO/expression, GOTO=Label
Expression
The Expression button brings up the expression builder. With the expression
builder you can create a variety of different expressions that you may need within
your part program. See the "Using Expressions and Variables" chapter for
information on using expressions.
Label
The Label box allows you to type in the Label that PC-DMIS will use for the GOTO
command. The Label button brings up the Goto dialog box. From this dialog box
you can choose the label to be used. The label will appear in the Label box. See
"Jumping to a Label" on page 22-14.
The On Error command can be used to tell PC-DMIS what action to take in the case
that a CMM Error occurs.
PC-DMIS tracks two kinds of error conditions: Unexpected Probe Hit and Missed
Probe Hit. For each of these error conditions, three possible actions can be taken:
1) Jump to a label
2) Set a variable's value to one
3) Do nothing
By default, all part programs start with the action for both types of errors set to the
third option (Do nothing). The action mode for each error type can be changed
throughout the program.
The Edit window command line for the ON ERROR option reads:
ONERROR/UNEXPECTED_HIT, mode ID
or,
ONERROR/PROBE_MISS, mode ID
To use the ON ERROR command:
1. Select Utilities | On Error. The On Error dialog box will
appear.
2. Select either Unexpected Probe Hit or Missed Probe Hit
from the Error Type drop-down list.
3. Select one of the following Error Mode options to define what
action should take place:
Off Does nothing.
Error Type
The Error Type drop-down window allows you to choose one of these Error Types:
• Unexpected Probe Hit
• Missed Probe Hit
Off
When the CMM has an error, choosing the Off option commands PC-DMIS to do
nothing.
Goto Label
When the CMM has an error, choosing the Goto Label option commands the part
program to jump to a defined label
Set Variable
When the CMM has an error, choosing the Set Variable option commands the part
program to set a variable's value to one.
Supported Interfaces
Not all interfaces support the ON ERROR command. Consult the following table to
see if your interface is supported.
• If your interface is listed, a small block box indicates what error type is
supported by that interface.
• If your interface isn't listed, then it's not able to use the ON ERROR
command.
Supported Unexpected Missed Probe
Interfaces Probe Hit Hit
B&S Standard ■ ■
Dea ■
Elm ■ ■
Federal/Renault ■ ■
Johansson ■ ■
Leitz ■ ■
LK Direct (aka ■ ■
LKRS232)
LK Driver ■ ■
Metrolog ■ ■
Mititoyo Bright ■ ■
Mitutoyo ■ ■
Mora ■ ■
Omnitech ■ ■
Renishaw ■ ■
Sharpe ■ ■
Sheffield ■ ■
Wenzel ■ ■
Zeiss ■ ■
Note: You can also delete arguments by using the Delete Arg button in the
Subroutine Creation dialog box.
Subroutine Name
In the Name box, type in the name of the subroutine you are creating.
The Number of Arguments list shows the arguments for the subroutine you are
creating. To edit the argument simply double click on the argument you want to
change. The Argument Edit dialog box will open.
Add Arg
The Add Arg button allows you to add new arguments to your subroutine. Simply
click on this button and the Add Argument dialog box appears:
The Delete Arg button allows you to delete arguments from your subroutine.
Simply, select the argument from the list, and click the Delete Arg button.
Values Box
The Values box contains a list of the values of each argument associated with the
subroutine. To change these values, simply double click on the value you wish to
change and the Edit Argument dialog box will appear.
Delete Arg
This button will allow you to delete the arguments from the Values Box. Simply
select the value displayed and click the Delete Arg button. The argument associated
with that value is then deleted.
Note: You can also delete arguments by using the Delete Arg button in the
Subroutine Creation dialog box
Argument Name
In the Name box you enter the name for the argument you are creating or editing.
Argument Value
In the Value box you enter the value of the argument. Valid values are:
• Numeric
• Variable
• Text String
Argument Description
In the Description box you can enter a description of the argument. This
description will appear next to the argument in the Edit window.
Ending a Subroutine
The End Sub menu option ends a subroutine by placing an "ENDSUB/" command
in the Edit window.
To place this command:
1. Place your cursor in the desired spot of the Edit window.
2. From the submenu, select End Sub.
The "ENDSUB/" command will appear in the Edit window.
Calling a Subroutine
The Callsub menu command will call an already existing subroutine from the
current part program into a different location, or from a different part program into
the current part program.
To call a subroutine:
1. Select the Call Sub option from the submenu. The Call
Subroutine dialog box opens.
2. Click the Select Subroutine button. The Select Subroutine
dialog box opens.
Note: In your CALLSUB command you should keep a set of pointers to all of the
objects made for the subroutine so that you can easily refer to them afterwards using
the subroutine's ID. For more information on pointers, see "Pointers" in the "Using
Expressions and Variables" chapter.
The Call Subroutine dialog box also allows you to add, edit, or delete arguments
to the called subroutine.
The Name box contains the name of the subroutine you have selected after using the
Select Subroutine button.
The File box contains the directory pathway to the subroutine file you have called.
Select Subroutine
The Select Subroutine button brings up the Select Subroutine dialog box.
The Select Subroutine dialog box allows you to call previously created
subroutines by searching in the user directory or the current directory.
PNT1=FEAT/POINT,RECT
…
…
ENDMEAS/
C1=COMMENT/YESNO,Do you want to change the theoretical
values for PNT1?
IF/C1.INPUT=="YES"
CS1=CALLSUB/CHANGETHEO,:,
END_IF/
COMMENT/OPER,The XYZ theoretical and actual values for
PNT1 are:
,"Theo X= " + PNT1.TX
,"Theo Y= " + PNT1.TY
,"Theo Z= " + PNT1.TZ
,- - - - - - - - - - -
,"Actl X= " + PNT1.X
,"Actl Y= " + PNT1.Y
,"Actl Z= " + PNT1.Z
PROGRAM/END
SUBROUTINE/CHANGETHEO,
POINT1 = {PNT1} : ,
=
DIMINFO/;DIMID,FEATID;HEADINGS,GRAPH
AXIS;MEAS,NOM,TOL,DEV,MAXMIN,OUTTOL, , ,
C2=COMMENT/INPUT,Type the new X theo value for PNT 1.
,"It's current value is: " + PNT1.TX
ASSIGN/PNT1.TX = C2.INPUT
C3=COMMENT/INPUT,Type the new Y theo value for PNT 1.
,"It's current value is: " + PNT1.TY
ASSIGN/PNT1.TY = C3.INPUT
C4=COMMENT/INPUT,Type the new Z theo value for PNT 1.
,"It's current value is: " + PNT1.TZ
ASSIGN/PNT1.TZ = C4.INPUT
ENDSUB/
Explanation of Sample Code
C1=COMMENT/YESNO
This line takes and stores the YES or NO response from the user.
IF/C1.INPUT=="YES"
This line is the expression. It tests to see if the input of comment 1 is a
YES. If it's a YES then the IF statement is TRUE and continues
executing the statements after the IF statement, in this case it measures
the PNT1 feature. If NO it moves to the END_IF statement.
CS1=CALLSUB/CHANGETHEO,:,
This line calls the subroutine named CHANGETHEO. The flow of the
part program now jumps to the SUBROUTINE/CHANGETHEO line.
SUBROUTINE/CHANGETHEO
This line initializes the CHANGETHEO subroutine. Program flow
continues with the execution of code between this line and the
ENDSUB/ line.
POINT1 = {PNT1} : ,
This is the only argument of the subroutine. It allows the subroutine to
access information from the PNT1 feature.
C2=COMMENT/INPUT, C3=COMMENT/INPUT,
C4=COMMENT/INPUT
These input comments all take the new theoretical X, Y, and Z values
from the user and store them in C2.INPUT, C3.INPUT, and C4.INPUT
respectively.
ASSIGN/PNT1.TX = C2.INPUT
This line takes the theoretical X value from C2.INPUT and assigns it to
the PNT1.TX variable. PNT1.TX is a PC-DMIS variable that holds
the theoretical X value (denoted by TX) for the point with the ID label
of PNT1.
ASSIGN/PNT1.TY = C3.INPUT
This line takes the theoretical Y value from C3.INPUT and assigns it to
the PNT1.TY variable. PNT1.TY is a PC-DMIS variable that holds
the theoretical Y value (denoted by TY) for the point with the ID label
of PNT1.
ASSIGN/PNT1.TZ = C4.INPUT
This line takes the theoretical Z value from C4.INPUT and assigns it to
the PNT1.TZ variable. PNT1.TZ is a PC-DMIS variable that holds
the theoretical Z value (denoted by TZ) for the point with the ID label
of PNT1.
ENDSUB/
This line ends the subroutine, and program flow returns to the line
immediately following the subroutine call. In this case the END_IF/
statement.
The program flow then continues with the next operator comment
which displays the theoretical and actual X, Y, and Z values, and then
the part program ends with the PROGRAM/END command.