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! 

 

Forum Navigation
You need to log in to create posts and topics.

Execute M code before reaching it

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:
  • Square-100-x-100-mm.png

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()

current_line = d.getGCodeCurrentLineNumber()
next_line_text = d.getGCodeLine(current_line + 1)

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:
  • Capture-decran-2025-05-16-a-15.38.12.png

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.

PARTNERS:

 

USA

Germany

Slovenia / Bosnia

Spain

South Africa

UNI-CAM

The Netherlands

Portugal

Greece

  Distrib milionis logo

Hungary

Distrib logot

Bulgaria

Master

Kenya

Proteq Automation

Egypt

Germanelectronix

China

Jun Ma

Serbia

ALCO

Italy

LVL tech r

Denmark

Varntoft Dania

Finland