Macro programming
Macro programming

Run behavior during loading of job file and simulation

4min

Simulation refers to the software mode that is used when no hardware is connected. During the loading of a G-Code file, the interpreter runs the file while generating output for the graphic. During this no actions to the machine are applied, no motion and no I/O, only checks if the g-code is valid and stays within the machine limits.

If there is advanced macro programming, e.g. because the machine has automatic tool change, it is important to take into account that in simulation and render mode no machine actions take place.

Check example that should be always executed

Suppose we have a machine with a 6-tool automatic tool changer. A check is programmed that generates an error if a g-code file is loaded that tries to change the tool to a number that the machine does not have:

if [#5011 > 6] ErrMsg “Please select a tool in the range of 1 to 6” Else ; Code to perform the tool change Endif

It stands to reason that we want this “ErrMsg …” line to be executed always, when running but also in simulation mode and when loading the file.

Check example that should be only executed during the job

sub check_airpresure m56 p5 if [#5399 == 0] errmsg "Error, No Air pressure" else msg "Air Pressure OK" endif endsub

This check on air pressure will not work correctly while loading a g-code file or while the system is in simulation mode, because no actual inputs are read.

sub check_airpresure ; Check only if not rendering and not during simulation if [[#5380 == 0] and [#5397 == 0]] m56 p5 if [#5399 == 0] errmsg "Error, No Air pressure" else msg "Air Pressure OK" endif endif endsub

Here we see the modification to make the on the air pressure sensor input 5 simulation and render proof, the check is only performed when we are not in render or simulation mode, only an extra if statement that checks variable #5380 (contains the value of 1 when simulation mode) and #5397 (contains the value of 1 when rendering) is added.