Reference for simCNC 3.604 · CS-Lab s.c.
This document lists the G-codes recognised by the simCNC G-code interpreter, and the M-codes built into simCNC or installed with a new profile. Codes that are not listed
(for example G95, G96, G97, G51) are not supported: the program
reports the error "Unknown code G" when it is loaded.
Axis words refer to up to 6 machine axes: X Y Z A B C. The number of active axes depends on the
machine configuration.
Program format
- Line numbers (
N10,N20, ...) are optional. If used,Nmust be the first word of the line and a whole number (0 or more), and only oneNper line. %characters (e.g. the first and last line of a program) are ignored.- Comments are written in brackets
( ... )or after a semicolon; .... Use only one bracket comment per line: with two, everything from the first(to the last)is removed, including any G-code between them. - M-codes: most of them (
M3,M5,M6,M30, ...) are Python macros in the simCNC profile and can be adapted to the machine; see M-codes at the end. - Start each program by setting the modes it needs (
G21/G20,G90,G17,G54, ...), so that it does not depend on the state left by a previous program.
Units
Axis words (including arc I J K and R), G92 offsets and G68
centres follow G20/G21. These values are always in the machine base units (mm for
linear axes, degrees for rotary axes), also in inch mode:
G10coordinates- the
Pdiameter ofG41/G42 - the
Ptolerance ofG64 - the
Qpeck depth ofG83(do not mixG83withG20)
In G93 mode the F word is a reciprocal time and has no units (see Feed rate mode).
Motion
| Code | Parameters | Description |
|---|---|---|
G0 | axes | Rapid traverse (positioning move) to the given position. |
G1 | axes | Linear feed move to the given position at the active feed rate (F). |
G2 | axes, I J K or R | Clockwise arc in the active plane (G17/G18/G19). Centre given as I J K offsets from the start point, or as radius R. Motion of the axis perpendicular to the plane gives a helix. |
G3 | axes, I J K or R | As G2, counter-clockwise. |
G32 | axes | Straight move synchronised with the spindle (single-point threading). The lead per revolution is F / commanded rpm, i.e. F = pitch × S. The pitch holds when the spindle slows down under load, but changing S or the spindle override changes the pitch. At least one axis word is required. Needs the spindle-speed and encoder-index (trajectory trigger) signals to be configured, and cutter compensation off. The feed rate override does not apply. |
G53 | axes | Non-modal: the axis words on this line are machine coordinates (work offset, G92, tool offset and G68 rotation are bypassed) for this move only. Must be combined with a motion code, e.g. G53 G0 Z0. |
Units, plane and distance mode
| Code | Parameters | Description |
|---|---|---|
G17 | — | XY plane (arcs, G68 rotation, cutter compensation; canned cycles drill along Z). |
G18 | — | XZ plane (canned cycles drill along Y). |
G19 | — | YZ plane (canned cycles drill along X). |
G20 | — | Units: inches. |
G21 | — | Units: millimetres. |
G90 | — | Absolute distance mode. |
G91 | — | Incremental distance mode. |
Work coordinate systems and offsets
| Code | Parameters | Description |
|---|---|---|
G54…G59 | — | Select work offset 1–6. |
G59.1…G59.250 | — | Select extended work offset 7–256. |
G10 | L2 P<1-256> [axes] | Sets the origin of work offset P (1 = G54 … 6 = G59, 7–256 = G59.1…G59.250) to the given machine coordinates, only for the axes given. L2 and P must be the first two words after G10, followed by at least one axis word. Values in base units (G20 not applied). |
G92 | axes | Sets an offset so that the given axis words become the current position. Only the axes given are changed. Activates the G92 offset. |
G92.1 | — | Cancels the G92 offset and resets it to zero. |
G92.2 | — | Cancels the G92 offset but keeps its value. |
G92.3 | — | Re-activates the stored G92 offset. |
Tool length offset and cutter compensation
| Code | Parameters | Description |
|---|---|---|
G40 | — | Cancels cutter radius compensation. |
G41 | D or P (optional) | Cutter radius compensation, tool left of the path. D<n> takes the diameter from tool table entry n; P<diameter> gives it directly. Without either, the previously selected diameter is used. |
G42 | D or P (optional) | As G41, tool right of the path. |
G43 | H | Activates the tool length offset of tool H (0–255). |
G49 | — | Cancels the tool length offset. |
Using cutter compensation
G41 D5 (compensate left, diameter of tool table entry 5) G42 D5 (same, right of the path) G41 P8.0 (compensate left, diameter 8.0 given here) G41 (compensate left, diameter selected earlier) G40 (off)
- With
D5the diameter used is the diameter of tool table entry 5 minus its diameter wear; half of it is the path offset. Dis modal: it stays selected for laterG41/G42until anotherDor aPreplaces it, and it is kept after a restart.T<n>does not select the compensation diameter, onlyDdoes.- A tool table entry with diameter 0 means no compensation, without a warning.
- A line with only
D5is allowed; it selects the entry without switching compensation on. - Use
DorP, not both. On one line (G41 D3 P6)Pwins.D<n>switches back from aPdiameter to the tool table. Dtakes a whole number 0–255 (no#parameter). A number beyond the tool count is ignored and the previous entry stays selected.- Compensation must be off (
G40) for canned cycles (G81/G82/G83), forG28/G30and forG32; otherwise the error "Compensation has to be off for this segment" is reported.
Coordinate system rotation
| Code | Parameters | Description |
|---|---|---|
G68 | X Y Z (centre), R (angle), optional | Rotates the coordinate system in the active plane by R degrees (−360…360) around the given centre. An omitted X/Y/Z is 0 (not the current position). Without R the previous angle is kept; in G91 mode R is added to the current rotation. |
G69 | — | Cancels the G68 rotation. |
Canned (drilling) cycles
Drilling runs along the axis perpendicular to the active plane (Z for G17, Y for G18,
X for G19). R, P and Q are modal and reused by later cycle lines.
A cycle line without axis words only updates these values and does not move. A/B/C
words on a cycle line are ignored.
| Code | Parameters | Description |
|---|---|---|
G80 | — | Cancels the active canned cycle. |
G81 | axes, R, K | Drilling: rapid to the hole position, rapid to the R plane, feed to depth, rapid retract (G98/G99). K repeats the cycle n times (with G91: a row of equally spaced holes). |
G82 | axes, R, P, K | As G81, with a dwell of P milliseconds at the bottom. |
G83 | axes, R, Q, P, K | Peck drilling: feeds in steps of Q, retracts to the R plane after each peck, rapids back to a clearance above the previous depth (peck tolerance in the machine settings). Optional dwell P [ms] at the bottom of each peck. Q must be greater than 0 and is in base units (not converted by G20). |
G98 | — | Retract to the starting level after each cycle. |
G99 | — | Retract to the R plane after each cycle. |
Homing and reference points
| Code | Parameters | Description |
|---|---|---|
G28 | axes (optional) | Rapid through an optional intermediate point to reference point 1. With axis words only those axes move to the reference point; without, all axes do. |
G28.1 | P<axis> (optional) | Homing (drive to the home switches). Without P: all axes set to home with "home all". With P: only that axis. P counts from zero (P0 = X). |
G30 | axes (optional) | As G28, to reference point 2. |
G30.1 | — | Homing of all axes set to home with "home all" (as G28.1 without P). |
Probing
| Code | Parameters | Description |
|---|---|---|
G31 | axes | Straight probing move with probe input 0; stops when the probe triggers. At least one axis word is required. |
G31.1 | axes | As G31, probe input 1. |
G31.2 | axes | As G31, probe input 2. |
G31.3 | axes | As G31, probe input 3. |
Feed rate mode (beta)
G94 (default): F is a feed rate in units per minute. G93: inverse time,
F is the reciprocal of the move duration - the move takes 1/F minutes. CAM systems use
this for simultaneous multi-axis moves.
G93 G1 X10 F2 ; 10 mm in 1/2 minute = 30 s G1 X20 F0.5 ; 10 mm in 2 minutes G1 A90 F1 ; 90 degrees in 1 minute G94 ; back to units per minute G1 X0 F500
- In
G93mode everyG1/G2/G3line needs anF; otherwise "F is required in G93 mode". G20/G21do not change aG93F.G0is not affected (rapid speed in both modes).- The feed rate override still applies (50 % doubles the move time).
- Canned cycles cannot be used in
G93("G93 is not allowed with canned cycles").G32ignores the feed rate mode. - Loading a G-code file resets the mode to
G94. - With cutter compensation, or where very short segments are optimised away, the real move time can differ slightly from
1/F.
Dwell, path control and miscellaneous
| Code | Parameters | Description |
|---|---|---|
G4 | P (required) | Dwell for P milliseconds (at least 1). |
G64 | P (required) | Maximum path deviation when blending corners. P ≥ 0, in base units (G20 not applied). |
G50 | — | Accepted for compatibility, no effect. |
G93 | — | (beta) Inverse time feed rate mode, see above. |
G94 | — | (beta) Units per minute feed rate mode (default). |
M-codes
Built into simCNC
These M-codes are handled by simCNC itself, not by macros.
| Code | Parameters | Description |
|---|---|---|
M47 | — | Jumps back to the first line of the program and runs it again (repeats the program until it is stopped). |
M62 | P<0-3> (required) | Switches the trajectory-synchronised output P on exactly at this point of the path, without stopping the motion. Outputs 0–3 are assigned in the special I/O configuration (trajectory sync outputs). |
M63 | P<0-3> (required) | As M62, switches the output off. |
M98 | P<n> (required), L<repeats> | Calls subprogram O<n>, L times (default 1, at least 1). Subprograms can be nested up to 10 levels. In 3.604 use a plain number for L: L#100 takes the stored value of parameter #100, not one assigned earlier in the program. Not available in MDI. |
M99 | — | Ends the subprogram and returns to the line after the calling M98. |
O<n> | — | Subprogram label (start of subprogram n). |
G90 G0 X0 Y0 M98 P100 L3 (run subprogram 100 three times) M30 O100 G91 G1 X10 F500 Y10 G90 M99
Macros (Python scripts)
Any other M<n> runs the script m<n>.py from the scripts folder of the
active profile. The scripts can be edited, and new M-codes can be added by creating a new script (e.g. m100.py
for M100). An M-code macro takes no parameters on its line ("M code has wrong arguments").
A new profile is created with these default macros:
| Code | Script | Default action |
|---|---|---|
M0 | m0.py | Program stop. Motion stops; Start continues from the next line. |
M1 | m1.py | Optional stop. The default script does the same as M0. |
M2 | m2.py | Program end. |
M3 | m3.py | Spindle on, clockwise (speed from S). |
M4 | m4.py | Spindle on, counter-clockwise. |
M5 | m5.py | Spindle off. |
M6 | m6.py | Tool change: the tool selected with T<n> (0–255) becomes the current tool and tool offset number. The default script does not move the machine; adapt it to the machine's tool changer. |
M7 | m7.py | Mist coolant on. |
M8 | m8.py | Flood coolant on. |
M9 | m9.py | Mist and flood coolant off. |
M30 | m30.py | Program end and rewind to the first line. |
M150 | m150.py | AutoLeveling correction off. |
M151 | m151.py | AutoLeveling correction on. |
CS-Lab s.c. · www.cs-lab.eu · simCNC postprocessors: en.cs-lab.eu – postprocessors
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article