ABOUT G-CODE PROGRAMMING LANGUAGE
A G-code program is made up of one or more lines of code. Each line of code is called a block, and can include commands to the machine. Blocks are collected into a file, which makes a program.
A block is normally made up of an optional line number at the beginning, followed by one or more words, which groups the elements together into a single statement.
A word is a letter followed by a number (or, something that evaluates to a number). A word can either give a command or provide an argument to a command.
A program is one or more blocks, each separated by a line break. Blocks in a program are executed either:
- Sequentially (from the top of the program to the bottom)
- Until an end command (M02 or M30) is encountered
EXAMPLE: G01 X3 is a valid line of code with two words: G01 is a command: the machine should move in a straight line at the programmed feed rate. X3 provides an argument value: the value of X should be 3 at the end of the move.
Most commands start with either G (general) or M (miscellaneous) — G-codes and M-codes.
There are two commands (M02 and M30) that end a program. A program can end before the end of a file. If there are lines in a file after the end of a program, they’re not meant to be executed in the normal flow (they’re generally parts of subroutines).
You can add comments or messages to lines of G-code to help clarify the intention of the programmer: to embed a comment in a line, use parentheses; to add a comment to the end of a line, use a semicolon.
NOTE: The semicolon is not treated as the start of a comment when it’s enclosed in parentheses.
Comments can appear between words, but they can’t be between words and their corresponding parameter.
EXAMPLE: S100 (set speed) F200 (feed) is okay, but S (speed) 100F (feed) is not.
If the comment occurs on a line with M00 or M01, and contains a file name with a .jpg or .png extension, PathPilot displays the image in the Tool Path display when the program reaches the M00 or M01 break.