CS-Lab Support Forum for CNC Community
Help to run this brand-new forum and stay with us.
Ask your questions, we are here to help!
Execute M code before reaching it
Quote from jose-gzm on 10 May 2025, 04:49I would like to know if there is a way to do this in SimCNC:
This is the G-code for plasma cutting a 100 x 100 mm square with an 8 mm lead-in and a 4 mm lead-out.
G92X0.Y0. ( Set current position as X=0, Y=0 )
G21 ( Set units to millimeters )
G91 ( Set to incremental positioning mode , relative movements )
G00X4.Y-0. ( Rapid move 4 mm in X axis, Y axis doesn't move )
G41 ( Enable cutter radius compensation to the left of the toolpath )
M3 ( Turn on the plasma torch )
G01Y8. ( Linear move 8 mm in Y axis )
Y100. ( Linear move another 100 mm in Y axis )
X100. ( Linear move 100 mm in X axis )
Y-100. ( Linear move -100 mm in Y axis )
X-100. ( Linear move -100 mm in X axis )
X-4. ( Linear move -4 mm in X axis, and returns to starting point )
M5 ( Turn off the plasma torch )
G40 ( Cancel cutter radius compensation )
M30 ( End of program )What I would like to do is turn off the torch before the cutting motion ends—in other words, execute the M5 code (which in this case turns off the torch) before the cut motion finishes, perhaps defined by time (e.g., 1 second before) or by distance (e.g., 10 mm before).
I would like to know if there is a way to do this in SimCNC:
This is the G-code for plasma cutting a 100 x 100 mm square with an 8 mm lead-in and a 4 mm lead-out.
G92X0.Y0. ( Set current position as X=0, Y=0 )
G21 ( Set units to millimeters )
G91 ( Set to incremental positioning mode , relative movements )
G00X4.Y-0. ( Rapid move 4 mm in X axis, Y axis doesn't move )
G41 ( Enable cutter radius compensation to the left of the toolpath )
M3 ( Turn on the plasma torch )
G01Y8. ( Linear move 8 mm in Y axis )
Y100. ( Linear move another 100 mm in Y axis )
X100. ( Linear move 100 mm in X axis )
Y-100. ( Linear move -100 mm in Y axis )
X-100. ( Linear move -100 mm in X axis )
X-4. ( Linear move -4 mm in X axis, and returns to starting point )
M5 ( Turn off the plasma torch )
G40 ( Cancel cutter radius compensation )
M30 ( End of program )
What I would like to do is turn off the torch before the cutting motion ends—in other words, execute the M5 code (which in this case turns off the torch) before the cut motion finishes, perhaps defined by time (e.g., 1 second before) or by distance (e.g., 10 mm before).
Uploaded files:Quote from erwan on 10 May 2025, 10:24A small idea — but you'll need to have a linear move right after the M5.
M5 would trigger a script that reads the G-code line immediately following it (which should be a linear move). The script calculates half of the trajectory from that linear move, performs the first half with the torch on, then turns off the torch, and completes the second half of the move.
Then the script returns to the G-code execution, skipping that one linear move line. using d.setGCodeNextLine()
A small idea — but you'll need to have a linear move right after the M5.
M5 would trigger a script that reads the G-code line immediately following it (which should be a linear move). The script calculates half of the trajectory from that linear move, performs the first half with the torch on, then turns off the torch, and completes the second half of the move.
Then the script returns to the G-code execution, skipping that one linear move line. using d.setGCodeNextLine()
Quote from Tim on 16 May 2025, 15:54Is it possible to read the last line before M5 "d.getGCodeLine(current_line - 1)"So that the torch cuts out in the middle of "N0027 X110.0000" ( at X105.00 ) without interrupting the X movement during the torch cuts out.
Is it possible to read the last line before M5 "d.getGCodeLine(current_line - 1)"
So that the torch cuts out in the middle of "N0027 X110.0000" ( at X105.00 ) without interrupting the X movement during the torch cuts out.
Uploaded files:
Quote from CS-Lab Support on 27 May 2025, 13:37I'm afraid that is not possible. Possibly you can experiment with trajectory synced outputs (https://en.cs-lab.eu/simcnc-the-list-of-supported-gcodes-and-mcodes/ - look at m62/m63 commands), but even this would require splitting the segment in the G-code, and putting M63 P.. somewhere in the middle.
I'm afraid that is not possible. Possibly you can experiment with trajectory synced outputs (https://en.cs-lab.eu/simcnc-the-list-of-supported-gcodes-and-mcodes/ - look at m62/m63 commands), but even this would require splitting the segment in the G-code, and putting M63 P.. somewhere in the middle.























