0% found this document useful (0 votes)
56 views

Post Functions: Difference Between Formulas and Functions

This chapter describes functions in the MP post processing language. Functions support features like numeric formatting, string selection, lookup tables, buffer files, and user prompts. Functions are declared in the post customization file and called via formulas or commands. Key functions include fstrsel for string selection based on a numeric variable, flktbl for lookup tables, and fq for user prompts.

Uploaded by

Minh Phương
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Post Functions: Difference Between Formulas and Functions

This chapter describes functions in the MP post processing language. Functions support features like numeric formatting, string selection, lookup tables, buffer files, and user prompts. Functions are declared in the post customization file and called via formulas or commands. Key functions include fstrsel for string selection based on a numeric variable, flktbl for lookup tables, and fq for user prompts.

Uploaded by

Minh Phương
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Volume 1 Chapter 11 Post Functions

11 Post Functions

This chapter describes the functions in the MP language. Functions are unique mechanisms in the MP
language that support the numeric variable format definition and assignment, string select feature, look
up table features, buffer files, user prompt feature, and tape leader/trailer generation. These function
mechanisms rely on a declaration in the post customization file for the feature, for example, defining a
look up table or buffer file, and a math formula or a command variable as the method to call the feature.

Difference between formulas and functions


Formulas refer to math operators and math formulas. Functions are the unique mechanisms in the MP
language that support the string select feature, look up table features, buffer files, and the user prompt
feature. These function mechanisms rely on a declaration in the post customization file for the feature
and a formula as the calling method.
See Formulas for more information.

MP post functions
These are the post functions in the MP language. Because the functions are diverse and some are
complex, not all the functions are described in detail in this chapter. Refer to the chapter that is
referenced in this list for more detail on a specific function.
! delay – The function stops processing for the time entered in seconds. The minimum time
accepted is a millisecond. See Volume 2, Graphics Functions for information.
! fs, fs2 - The format statement is a general definition of the numeric format for the numeric
variables. See Volume 3, Numeric Variables for information on this function.
! fmt - The format assignment defines a prefix string, the format statement to associate to the
numeric variable, and a suffix string. See Volume 3, Numeric Variables for information on this
function.
! fnewsub – The function supports renaming a subprogram with nested subprograms for Version
9. See Volume 2, How Subprograms Work for information on subprograms.
! fstrsel - The string select function allows the post processor to assign a string variable from a
list of string variables to a target string variable based on the value of a numeric variable
selector used in this selection function.
! flktbl - Lookup tables are two-column tables that associate a value in one column with a value
or variable in the matching column and returns a the value from the matching column. The
formulas used to access lookup tables are: flook, frange, and finc.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 11-1


Chapter 11 Post Functions Volume 1

! fq – The user prompt function allows you to display prompts or questions in the Mastercam
prompt area at the bottom of the Mastercam application screen. The return value can be used in
the post customization file. See How Prompt Questions Work for information on this function.
! fbuf - Buffer files are files that you can use with the MP language as a place to store and
retrieve data. See Volume 2, How Buffer Files Work for information on this function.
! fprmtbl – The NC parameters read from the NCI file or operation parameter file are not
assigned variable names but must be assigned to numeric and string variables with the
Parameter table function. See Volume 3, Parameter Information for information on this
function.
! fleader – The tape leader and trailer is not truly a function but behaves more like a command
variable. It has remained part of the post functions because of earlier design implementation.
! force – This function forces the variable to output on the next output call. Modality is reapplied
from the format (fmt) statement.

fnewsub function
The fnewsub function was added to support renaming a subprogram with nested subprograms for
Version 9. V9 nested subprograms (where sub_level is initialized to 3 or 4) use the current nesting level
to control the subprogram naming. V8-type subprograms (where sub_level is initialized to 1 or 2) use
the command words newsub, newaux and newext to close a subprogram and reopen it with a different
name. V8-type subprograms were able to use the existing post subfile structure in MP, and this
mechanism remains fully functional even with nested subprograms enabled.
V9 nested subprograms are not able to use the existing subfile structure because the nesting levels are
not limited. To allow the same functionality, the fnewsub function was added. The first argument is a
string variable with the complete path and file name. The second argument is the nested level that you
want to rename the output file. The return value is 1 if successful, or 0 if it fails. The numeric variable
subfile is used to determine if the file is opened new (subfile = 1) or the contents are appended (subfile =
2).
snewname "c:\mcam9\mill\nc\newname.nc"
postblock #A postblock
subfile = 1
result = fnewsub (snewname, 2)

The above closes the output file for the subprogram level two (subprogram levels are returned in the
variable sub_level) and reopens it as new with the file name (c:\mcam9\mill\nc\newname.nc).
With the subfile structure, the code would be:
snewname "newname"
postblock #A postblock
auxprg = 1
snameaux = snewname
newaux

11-2 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 1 Chapter 11 Post Functions

String select function (fstrel)


The string select function (fstrel) allows the post executable to choose a character string from a list of
string variables for assignment to a specific string label. The selection is based on the value of a
numeric variable selector. This permits the string variable’s assigned character string to change based
on the selection process described here. Normally, this function results in output to the NC file.

String select tables


A string select table is created in the post customization file for each string select function that is
needed. You may add as many of the string select tables as you want. The structure consists of an
implied array of string variable initializations. The implied array is simply an ordered list of the
initializations. The start index in the implied array is 0. Immediately after the implied string array, the
string variable that is to be the target (the string variable to be reassigned) of the selection process is
declared. Next, the actual function declaration fstrsel is made.
The string select function declaration must be started in the first column of the post customization file.
All the elements must be included in the declaration. The function declaration for fstrsel is assembled
with the following elements:

String Select Function (fstrsel) description


fs2 1 2 3 4 5 6

Legend Description Syntax


fstrsel String Select Function declaration fstrsel
1 space (required)
2 Label of the string variable at the start of the 0 - 30
implied array
3 space (required)
4 Label of numeric variable selector +
5 space (required)
6 Label of the string variable that is the target 0 - 30

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 11-3


Chapter 11 Post Functions Volume 1

For example, a string select table can be used to output a different M code based on the value of the
coolant variable. The following code illustrates this example.

# Coolant M code selection

sm09 M9 # Coolant Off


sm08 M8 # Coolant Flood
sm08_1 M8 # Coolant Mist
sm08_2 M8 # Coolant Tool
scoolant # Target variable for string

fstrsel sm09 coolant scoolant

plin # Linear line move - at feedrate


n, sgcode, x, y, z, fr, scoolant, e

In the example, the string select function, fstrsel, marks the string variable scoolant as the target of a
string select function. It also associates the string variable sm09 as the beginning of the implied array
(table) to make selections from, and associates the numeric variable selector coolant as the index
position in the implied array to make the selection. Each time the target string variable scoolant is
encountered on a postline, the post executable performs the following steps:
1. Get the value of the of the numeric variable selector coolant.
2. Go to the start of the implied string array sm09.
3. Select the string variable in the implied string array from base zero, then index to the value
taken from the numeric variable coolant.
4. Copy the selected string variable contents to the target string variable scoolant.
5. Output the target string variable using the modality of the numeric variable selector coolant.
Update the numeric variable coolant as if it had been output to maintain modality.

For the example above:


! If the numeric variable selector coolant equals 0, the post executable will copy the first
(index 0) string variable character string “M09” to target string variable scoolant and
output M09.
! If coolant equals 1, then the post executable will copy the second (index 1) string variable
character string “M08” to target string variable scoolant and output M08.
The logic above applies to all string select functions.

Using upstr
The formula updstr is used to update the target string variable without NC output. For example:
real_result = updstr(string1)

See Formulas for more information.

11-4 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 1 Chapter 11 Post Functions

Lookup table function flktbl


The lookup table function flktbl defines a lookup table for the formula calls flook, frange and finc.
The columns of a lookup table can consist of integers or real numbers.
Note: You should use buffer files for very large tables.
See Volume 2, How Buffer Files Work for more information on creating buffer files.

Table definition
A lookup table follows the structure as shown here. It is entered into the post customization file as:
flktbl table number number of table entries
code 1 match 1
code 2 match 2

where:
flktbl Lookup table declaration
table number Table number from 1 to 32000
number of table entries Number of items in table
code 1 First code in table (output)
match 1 First lookup value (the match closest to an input value ) in table
code 2 Second code in table
match 2 Second match in table
Additional code/match pairs…

Table formulas flook, frange, and finc


These formulas allow you to access lookup tables.
target = command ( number , value )

target Variable to assign returned value to


command flook, frange, or finc command
number Table number from 1 to 32000
value Variable or numeric value to compare table items to
See Formulas for more information.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 11-5


Chapter 11 Post Functions Volume 1

flook
The flook formula looks up the closest match to a given value in column 2 and returns a code value
from column 1. The following example shows a sample lookup table to look up machine codes sscode
for a range of spindle speeds (ss).

flktbl 1 12 # Define table number one with twelve items.


58 64 # Variable sscode = 58, if ss < 64, = 64, or closer to 64 than 90.
59 90 # Variable sscode = 59, if ss is closer to 90 than 64 or 112.
63 112 # Variable sscode = 63, if ss is closer to 112 than 90 or 180.
64 180 # Variable sscode = 64, if ss is closer to 180 than 112 or 224.
65 224 # Variable sscode = 65, if ss is closer to 224 than 180 or 356.
66 356 # Variable sscode = 66, if ss is closer to 356 than 224 or 450.
67 450 # Variable sscode = 67, if ss is closer to 450 than 356 or 710.
73 710 # Variable sscode = 73, if ss is closer to 710 than 450 or 900.
74 900 # Variable sscode = 74, if ss is closer to 900 than 710 or 1400.
75 1400 # Variable sscode = 75, if ss is closer to 1400 than 900 or 1800.
76 1800 # Variable sscode = 76, if ss is closer to 1800 than 1400 or 2800.
77 2800 # Variable sscode = 77, if ss is > 2800.

Note that the logic for the above table returns an sscode value of 77 if ss is closer to 2800 than 1800,
and also returns the same value if ss is greater than 2800.
When placed on a postline, the following formula causes the post processor to return a code from the
table #1 (shown above) based on the current ss value:
sscode = flook( 1, ss )

! If ss is 24, then sscode will be 58.


! If ss is 425, then sscode will be 67.
! If ss is 700, then sscode will be 73.
! If ss is 1150, then sscode will be 74 because 1150 is closer to the lower match value.
! If ss is 5000, then sscode will be 77.

frange
You can use the frange function on the lookup table from the previous example to return the greatest
match from column 2 that is less than or equal to a given value, and return the corresponding code from
column 1.
For example, when the following formula is placed on a postline, it causes the post processor to return a
range code from the table #1 based on the current ss value:
sscode = frange( 1, ss )

! If ss is 24, then sscode will be 58.

11-6 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 1 Chapter 11 Post Functions

! If ss is 425, then sscode will be 66.


! If ss is 700, then sscode will be 67.
! If ss is 1150, then sscode will be 74.
! If ss is 5000, then sscode will be 77.

finc
finc increments the output column of a lookup table. It looks up the closest match in column 2 to a
value and incrementally increases the code in column 1. This makes it possible to keep count of the
number of times a tool is used. The incremented count is returned. The count may also be accessed by
flook or frange.
1. Set up the lookup table:
flktbl 1 99 # Lookup table for tool usage (99 entries)
0 1 # Tool number
0 2
0 3
2. Set up a user-defined variable, incorporating the finc function:
ntimesused = finc( 1, t ) # Increment count for number of times "t" is used.

Fleader command/function
The post function fleader will output a series of a selected character to the NC output. This function is
intended to provide the tape leader and tape trailer when punching paper tape. This function behaves
like a command variable. It is left over from an early design implementation and has remained
(incorrectly) as a post function.
The function operates by using the function label fleader as a trigger on an output postline. When the
function label is encountered, an internal routine in the post executable is called. The routine takes the
values in the numeric variables ldrcode and ncldr and processes a program “while” loop that continues
for the value of ncldr. On each iteration of the “while” loop, the ASCII decimal equivalent of the value
of ldrcode is output to the NC file.
To have a different length trailer or character, the variables ldrcode and ncldr must be reassigned locally
in the postblock and before the trigger label fleader.
Normally, fleader is placed in the beginning of the postblock pheader and at the and of the postblock
peof. For example:

ncldr : 25 # Number of leader characters


ldrcode : 10 # Leader character decimal. equiv.

pheader #Call before start of file


#Top of NC program...
fleader
"%", e

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 11-7


Chapter 11 Post Functions Volume 1
*progno, e
"(PROGRAM NAME - ", progname, ")", e
"(DATE, Day-Month-Year - ", date, " TIME, Hr:Min - ", time, ")"

peof #End of file for non-zero tool


n, "M30", e
"%", e
ncldr = 27
ldrcode = 50
fleader

Force function
The force function has been added in Version 9. It allows forcing the variable to be output on the next
output call. Modality is reapplied from the format (fmt) statement.
The following output calls reset this flag: normal output, forced output (*), and dependent output (`).
Because this function takes two arguments, a range of variables can be forced to output.
The first argument is the lower index position in the variable database. The second argument is
the higher index in the variable database. If multiple variables are specified, the variables MUST have
been defined in an “ordered-list” fashion.
Example 1: result = force(x ,z)

Forces output of x, y, z on the next output call.


Example 2: result = force(x, x)

Forces out only x on next output call.


The selector variable of a string select table can be set to force, and the string output is then forced on
the next output.
Example 3: result = force(gcode, gcode)

sgcode # G-code will be forced to output

Note: Strings cannot be directly forced with this function.

11-8 Mastercam Version 9 MP Post Processor Reference Guide June 2002

You might also like