CNC Simulator Pro

user guide

11.14. Subroutine and subprograms call (all machines)

The simulator has the capability to execute both subroutines and subprograms. Subroutines are typically included within the same CNC program file as the calling mother program, while subprograms are stored separately in their own files.
By allowing for the execution of both subroutines and subprograms, the simulator offers flexibility in programming options. Subroutines can be useful for streamlining the code within a single file and making it more modular, while subprograms can be used for more complex or extensive tasks that require dedicated files.
This separation of subprograms into distinct files can help with organization and maintenance, as it allows programmers to easily manage and update the code for each subprogram individually. Additionally, this approach can facilitate code reuse across multiple CNC program files.
Overall, the simulator's ability to handle both subroutines and subprograms provides users with a powerful toolset for CNC programming and can help to increase efficiency and productivity.

General rules:


Some examples:

Single call to the subroutine, no repeats
M98 P1000
M17 (or M99)
Standard call to the subroutine, repeating 4 times
M98 P1000 L4
Call to the subroutine on block N555, repeating 2 times
N100 M98 P555 L2
N555 ….
N565 M17 (or M99)
Call to subroutine with repeats in the P address
M98 P51001 (Call O1001 five times)
M17 (or M99)
Calling subprograms
If a subroutine within the same program is missing, the simulator will look for a separate program on disk.
M98 O1099 L2
If there is no O1099 or N1099 in the program, the block above will call subprogram O1099.cnc
Filename syntax
M98 “DrillHoles.cnc” L2
The block above will look for subprogram DrillHoles.cnc in the same folder as the main program or in the user-defined CNC programs folder.
Please remember to end all subprograms with either M17 or M99 for execution to continue in the main program.