Post Functions: Difference Between Formulas and Functions
Post Functions: Difference Between Formulas and 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.
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.
! 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
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.
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.
Using upstr
The formula updstr is used to update the target string variable without NC output. For example:
real_result = updstr(string1)
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…
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).
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 )
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 )
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:
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)