Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

learning MP language, is it based on other programming languages?


Recommended Posts

I am half way through vol 1 of MP post reference documentation.  While catching on there seems to be a great deal of the basics I am not understanding. This documentation seems to me to be written for advanced users.  I tool a generic programming class in college and learn Adobe's Flash when it was popular but that has been a few years ago, and I have forgot much of that.   I am looking for a source to help me learn the basics of this language.  Is the MP language based on something else with more information such as C+ or Java, etc., or even CNC macro B?  How did you learn this work?  If not, I will likely just post here with specific questions.

 

Thanks,

Steve

Link to comment
Share on other sites

The MP Language is a Scripting Language that is most similar to Standard C.

 

The first thing you should do is make sure you are opening the PST file with the Mastercam Code Expert text editor. This is because the MCE editor has "auto-complete" functionality for all of the pre-defined variables, functions, and strings.

 

I've taught many Post Classes in the past, but haven't done one for a while. There aren't many sources for MP Post courses these days.

 

The MP Language is simple, but powerful. There are only two data types: Strings and Numeric Variables (double values).

 

The Post is setup by default to read the NCI data (generic tool path and tool data), and it does this by reading through the NCI file, parsing two lines at a time. The first line (NCI Gcode) tells MP what the data on the next line represents. It also calls an "entry" post block, based on the value of the NCI Gcode.

 

There are Two Processing Loops that run on the NCI data. The first "pre-read" loop is used to capture things like Tool Data, to build a Tool List. After the Pre-Read is complete, the PST will read the NCI again in an "output loop" where data is written to the NC file.

 

What are you having trouble with understanding?

  • Like 2
Link to comment
Share on other sites

The MP Language is a Scripting Language that is most similar to Standard C.

 

The first thing you should do is make sure you are opening the PST file with the Mastercam Code Expert text editor. This is because the MCE editor has "auto-complete" functionality for all of the pre-defined variables, functions, and strings.

 

I've taught many Post Classes in the past, but haven't done one for a while. There aren't many sources for MP Post courses these days.

 

The MP Language is simple, but powerful. There are only two data types: Strings and Numeric Variables (double values).

 

The Post is setup by default to read the NCI data (generic tool path and tool data), and it does this by reading through the NCI file, parsing two lines at a time. The first line (NCI Gcode) tells MP what the data on the next line represents. It also calls an "entry" post block, based on the value of the NCI Gcode.

 

There are Two Processing Loops that run on the NCI data. The first "pre-read" loop is used to capture things like Tool Data, to build a Tool List. After the Pre-Read is complete, the PST will read the NCI again in an "output loop" where data is written to the NC file.

 

What are you having trouble with understanding?

 

 

Wow, I've been messing with posts for years. If fact, Colin, you have helped me with some particular difficult issues. But I never knew the MCE editor has auto-complete fuction for the posts. I've always used other editors. I'll have to give that a whirl. Thanks.

  • Like 1
Link to comment
Share on other sites

When I started I had a very limited knowledge of the "Basic" computer programing language and a little graphing calculator programing experience.  Between looking for examples in existing posts and reading on this site I was able to get to the point were I can handle most of the edits I need.  It can be very frustrating at first.  My post editing results in a lot of trial and error.  Make sure you have a backup of your post and thoroughly test any changes you make.  I have sometimes fixed one problem only to break something somewhere else.  Sometime I don't even find the new problem until I use a tool path I don't normally use months later.  I now keep a backup and a note with each change I make in case I have a problem later on.  Without this site I couldn't have done half of what I have done.  Most edits people need have been discussed on here already or something similar that might point you in the right direction.  I still have a long way to go to do some of the stuff guys on here talk about.   I try to read through most of the topics because I never know when I will learn something new.

Link to comment
Share on other sites

I want to say that I have come here only after doing much homework, watching every video on the subject.  Including the ones Colin has starred in. When  reading the MP docs I dont completely understand what I am reading.  If I had some perspective I would get much more out of my reading.  I plane to take the coursed Eapprentice provides in the near future.

 

For example, what is this excerpt from a Fanuc Mill 3x doing here.  I understand some of the individual components but how do they work together?  Which is a function, a variable, and a string? Why do some lines start with a P and some dont.

 

if mi1$ <= one, #Work coordinate system
        [
        absinc$ = one
        pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$
        pfbld, n$, *sg28ref, "X0.", "Y0.", e$
        pfbld, n$, sg92, *xh$, *yh$, *zh$, e$
        absinc$ = sav_absinc
        ]

 

Things I think I know here:

pfbld = force block delete? Why or how does this work

n$ = output block number to nc file

e$ = end of block

 

More questions come.
 

Link to comment
Share on other sites

I want to say that I have come here only after doing much homework, watching every video on the subject.  Including the ones Colin has starred in. When  reading the MP docs I dont completely understand what I am reading.  If I had some perspective I would get much more out of my reading.  I plane to take the coursed Eapprentice provides in the near future.

 

For example, what is this excerpt from a Fanuc Mill 3x doing here.  I understand some of the individual components but how do they work together?  Which is a function, a variable, and a string? Why do some lines start with a P and some dont.

 

if mi1$ <= one, #Work coordinate system

        [

        absinc$ = one

        pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$

        pfbld, n$, *sg28ref, "X0.", "Y0.", e$

        pfbld, n$, sg92, *xh$, *yh$, *zh$, e$

        absinc$ = sav_absinc

        ]

 

Things I think I know here:

pfbld = force block delete? Why or how does this work

n$ = output block number to nc file

e$ = end of block

 

More questions come.

 

 

The lines are variables expressions. It will go back and look up that part of the post and see what needs to be considered. If all conditions are meet then the output will happen if not then it will sort through what other conditions need to be answered or completed to then output the needed code. 

Link to comment
Share on other sites

I cover all of these details in my Eapprentice classes, but I can provide a brief summary here that will hopefully help you get "big picture" understanding of how the MP Language works. I created my classes specifically to cover all these things. To be fair, I did work for about 3 years at CNC Software and learned probably 60% or more of what I know now because of that experience. I knew the basics before I started working there, but gained an amazing amount of knowledge about Mastercam in general, and posts specifically while working there.

 

With a Generic Mastercam Post, there is logic that is setup to read data from the NCI file, and based on that data, it outputs your NC file. I know that probably sounds like "yeah, I already knew that, that doesn't help!", but it is important to state because it is at the heart of how MP.DLL processes the data.

 

When the NCI file is read 2 lines at a time, every single NCI G-code calls some sort of "entry post block". These "postblocks" or "subroutines" exist in one of two places: inside your PST file script itself, or inside MP DLL. Based on the NCI G-code, the post will call an "Entry" post block. Every NCI Gcode has one and only one "entry" point into the instruction list.

 

When the posting process first "starts up", MP opens your PST file. It scans through the PST lines and it creates Variable Definitions (locations in memory with an "address" (where is it) and default value (what is stored).

 

MP only has two data types: String variables and Numeric Variables. That's it. Many modern computer languages have many different data types (data structures) which determine the type of data they hold, and what operations you can perform on them. MP is "old school" in that it only holds String Data or Numeric Data. (Technically, that isn't true now, as MP has been enhanced recently, but that would just complicate this overview, so ignore this for now.)

 

With Numeric Variables, MP actually reserves two blocks of memory to store numeric values. It creates a "current" block, and a "previous" block. This means that every numeric variable holds the current and the previous value of the variable.

 

This is important, because it relates to Modality. With Numeric Variables in MP, you set the "current" value. When that variable is entered as a Parameter on a Post Line, MP looks to see if the current value is different from the previous. If the value is different, it triggers MP to write the variable to the NC output, and it then "updates" the variable. This means it copies the value that was just output to the "previous" value of the variable. Why? Because of Modality. This means the "current" value and the "previous" value now match. If the same variable is encountered on a different post line, MP will check the values and if they are identical, the variable will be "passed over" and not output.

 

Every single NCI line that contains motion has XYZ values included on the NCI data line. Modality determines if we need to output all the values on each line, or if the we only output the values that changed. Modality is a the heart of how the post functions, and can be used to control the "modal" output of String values as well. Normally, String Variables are always output when they are encountered on an output line. You do not need to force string variables. MP has a special mechanism called the String Select Function that works with a String Select Table that lets you create a list of string values. The function will output a given string from the string list, based on the modality of a numeric variable.

 

So that's kind of a quick overview of Strings and Numeric Variables and related functions. Strings output normally. Numeric Variables output based on modality, and there is a mechanism that exists for tying the strings to the modality of a numeric variable.

 

MP is organized into blocks or chunks of "script" code. The thing that "identifies" a Post Block is the name of that post block, which typically starts with "p" and only "p". (A Lathe or Mill-Turn post might have "m" or "l" as the starting block characters to indicate "mill" or "lathe" processing.)

 

The thing that identifies the start of the block is that the 'p', 'l', or 'm' character starts in the first column of text in the editor. MP is a "column dependent language". If something starts in the first column (a string, numeric, function, postblock), it is the "definition" of that "thing". That line starting in the first column identifies the item to MP, and during parsing MP "creates" something in memory based on that definition.

 

So starting the post block "psof$" in the first column identifies it as the beginning of a block of code. The only thing that "ends" a post block is a new definition, which always starts in the first column. So typically in the case of "post blocks", the next post block name is what ends the preceding block of code.

  • Like 7
Link to comment
Share on other sites

 TIn the MP Language, Post Blocks are "subroutines" that function very similar to a "G65" call in Macro B. Post Blocks are chunks of code that are executed,  based on the Trigger or "Call" to that block. This process always starts with the "entry" block, which is always triggered by a specific NCI Gcode line. You have to have an "entry" to kick of the subroutine script, and that is based on the processing order of the NCI data.

 

All of the "Entry" post blocks are "pre-defined". This means they are actually defined inside the MP.DLL file, and are initialized prior to the reading of the PST file. (The PST values can override the MP default values, since the PST file is read 2nd). Along with pre-defined post blocks, MP has pre-defined string variables and pre-defined numeric variables as well.

 

All pre-defined variables and blocks end with a Dollar Sign ($). This indicates that the values is automatically recognized by MP, and that MP is what creates it. If you use the Mastercam Code Expert editor (MCE), you get "auto-highlighting" of the pre-defined variables and blocks. That means if you type in the name of a pre-defined variable, and you spell it correctly, it will turn Blue automatically (in the case of a numeric variable), Purple in the case of a String, and Red in the case of a pre-defined Post Block. (depending on your Mastercam and MCE version, you may get "auto-complete" as well).

 

Post Blocks are made up of Post Lines. Post Lines are always indented by at least 1 space. This is what tells MP that it is a "post line" and not a new definition. The standard indenting inside the Mastercam Generic Posts is 6 spaces before the start of every line. They do this to make it clear to the developer that it is a post line, and not a post block.

 

Each Post Line is made up of Parameters. These parameters are separated by commas. You do not need a space between commas, but you should put them in for readability.

 

Here are two post blocks, each with a single post line:

pbld            #Canned text - block delete
      if bld, '/'

pfbld           #Force - block delete
      "/"

These are the "pbld" (block delete) post blocks and the "pfbld" (force block delete) post blocks.

 

They are defined somewhere down below the code example that you posts. The other thing you might notice about these blocks is that they are "User Defined". This means the post developer created them, and they are not pre-defined by MP.

 

All User Defined Post Blocks must be called from somewhere inside a pre-defined Post Block. This is essentially "by definition", since MP needs an Entry Post Block to start any kind of NC output processing.

  • Like 3
Link to comment
Share on other sites

So there are basically three types of Post Blocks: Pre-Defined (MP creates them), User Defined (you create them in the post, and you call them by placing the 'post block name' as a Parameter (by itself) on a Post Line.), and Implied Post Blocks.

 

An Implied Post Block is created typically to allow "multiple actions" to follow the result of a single "Logic Test". An implied Post Block is simply Post Lines, consisting of Parameters, surrounded by Square Brackets [ ].

 

The example you posts is an Implied Post Block from the Start of File Entry Post Block. Let's examine it:

      if mi1$ <= one, #G92 Local Work coordinate system
        [
        absinc$ = one
        pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$
        pfbld, n$, *sg28ref, "X0.", "Y0.", e$
        pfbld, n$, sg92, *xh$, *yh$, *zh$, e$
        absinc$ = sav_absinc
        ]

The first line starts with some Boolean Logic that tests the value of the Numeric Variable mi1$. This variable (mi1$) stands for Miscellaneous Integer Number 1. It's value is manipulated by the programmer in the Operation inside Mastercam. Every single Tool Path inside Mastercam contains a set of Miscellaneous Integers and Real Numbers (10 integers, 10 decimal numbers).

 

These variables are set a the Operation Level, and act as a Tool for you, the Post Developer, to pass data to the PST file. They do this by being written on the NCI 1011 and 1012 Gcode lines. These values are stored in variables by MP, and allow you to use them with Boolean Logic to make decisions inside the PST file. This would typically happen at the Tool Change event, which starts every Operation. The first Tool Change in the File is the NCI Gcode 1001, and calls 'psof$'. The next Tool Change is either a NCI Gcode 1000 (tool is the same tool as last op, otherwise known as a "Null Tool Change"), or the value is NCI Gcode 1002, which represents an "Actual" tool change, and we call a different block.

  • Like 2
Link to comment
Share on other sites

So, to get back to your sample, we are testing the value of mi1$, and based on if that test is "True", we are executing each line of an Implied Post Block:

      if mi1$ <= one, #G92 Local Work coordinate system
        [
        absinc$ = one
        pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$
        pfbld, n$, *sg28ref, "X0.", "Y0.", e$
        pfbld, n$, sg92, *xh$, *yh$, *zh$, e$
        absinc$ = sav_absinc
        ]

The first line is:

 

"if mi1$ <= one, #G92 Local Work coordinate system"

This line of code tests the value of 'mi1$' to see if it is "less than, or equal to" the value of the variable "one". (The variable "one" is defined as a constant value of '1' at the top of the post)

 

MP normally only allows "one line" of processing after the Boolean test results. By using an "implied post block", surrounded by Square Brackets, we can execute multiple "actions" if the results of that statement are true.

 

The second line is: [. This is the start of the implied post block. It, and all the lines that follow until the end of the block, are typically indented 2 or more spaces to give a structure to the code. This spacing isn't required, but greatly recommended as it helps with readability of the code when making edits.

 

The 3rd line is: absinc$ = one. This is an assignment formula. We are setting the value of the variable absinc$ to '1'. The 'absinc$' variable is used as the Selector Variable in a String Select Function for outputting either Absolute (G90) or Incremental (G91) codes. It does this because we need a mechanism to control output. 'absinc$' does more than this though. Based on the value of that variable, we are controlling the output of Absolute or Incremental coordinates for Motion as well. (X, Y, Z, I, J, K, and so on). Here, we are using the String Select function because there are multiple lines where we want "G91" output, and there is an existing mechanism inside MP to do this for us. Rather than entering "G91" on an output line, as a string, we want to control the output to the NC file using the existing mechanism that is made to do this job for us.

 

The third line is: pfbld, n$, sgabsinc, *sg28ref, "Z0.", e$. This is a Post Line with multiple "Output Parameters". These are each evaluated from left to right, one at a time. This is important, because one of the things you are allows to do is call another subroutine. This is known as "calling a post block". The first Parameter on the line is (pfbld). This is a Post Block Call, and we "jump" to the 'pfbld' post block. I showed those blocks up above. So MP jumps to the 'pfbld' post block, and evaluates the post lines and Parameters. The post can even call another "jump" from there, and go do more processing. The end result of a "jump" is a "return". Once we evaluate all the Parameters and post block calls, we return to the same point from where the calling began, and process the next Parameter. In this case, 'pfbld' is "force block delete", which forces out the forward Slash character (/). Then we return from that Call, and move to the next Parameter.

 

The 2nd Parameter on the line is n$. This is the Sequence Number. This is a special pre-defined variable. Its job is to output a Sequence Number, depending on if Sequence Numbers are enabled. This is controlled (set) inside the Control Definition File. If the switch is turned on, you get a N Block. If the switch is off, MP ignores the parameter and moves on to the next parameter on the line.

 

The 3rd Parameter is *sgabsinc. This is a call to a String Select Function. The String Select Table and Function Definition look like this:

# Select incremental or absolute G code 
sg90    : "G90"      #Absolute code
sg91    : "G91"      #Incremental code
sgabsinc : ""        #Target string  

fstrsel sg90 absinc$ sgabsinc 2 -1

When 'sgabsinc' is encountered as a Parameter on a Post Line, it calls this function. The function looks at the value of absinc$, and based on the Modality , it picks a String from the String List, using the value of absinc$ as the index to the String List.

 

The value in this case has been set by us to '1', and the String List is a Zero-Based index. Meaning '0' calls the first item in the list, '1' calls the 2nd, '2' the third, and so forth. In our case, this particular String List has only 2 strings. There is a Target Variable, which is a String, that gets its value changed constantly, based on the modality of the Selector Variable. So 'sgabsinc' could output either "G90" or "G91", at many different places in the post, as it is used on many different Post Lines.

 

 

The 4th Parameter on the line is: *sg28ref. (in this case the Asterisk (*) variable modifier "forces" the output) This is the Reference Return String Select, and based on the value of mi3$, it will output either "G28" or "G30". This is controlled by the user in the Miscellaneous Integers. So if you change the value of mi3$ in your operation, the post will change the output for that particular String Select Parameter.

 

 

The 5th Parameter is "Z0.". This is a Literal String, which means the output is just forces to the NC output line.

 

The last Parameter is e$ and this is the end of every line of NC output code line. Without a e$, the line does not break in the NC code file. Even if you write two lines of output parameters, the line will continue as a single line of NC code until you encounter a e$.

 

There are two additional Output Post Lines:

        pfbld, n$, *sg28ref, "X0.", "Y0.", e$
        pfbld, n$, sg92, *xh$, *yh$, *zh$, e$

 

Both of these lines are evaluated, from left to right, and the same process happens. You get output of the forced (*) variables always. The String Select functions are either forced, or are dependent on Modality. (sg92 for example, is not forced. It may, or may not output depending on modality)

 

Finally, the last line of code is Variable Assignment, that restores the value of absinc$ to the saved value. This allows you to "force" the ABS/INC mode inside the Implied post block, so you are guaranteed to get Incremental output, but not effect the ABS/INC mode outside of this block. (ABS/INC is set by mi2$ in the Misc. Ints.)

 

After that, the last line is a Close Bracket (]), which ends the implied post block.

 

 

Happy coding,

 

Colin

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...