G-code
Special features

M-code function override and user M-code functions

2min

The system allows M functions in the range of M1 to M999 This means there are many M-Functions that can be user-defined. The user can create his own M-Function by creating a subroutine for it in the macro file e.g:

sub m100 ;Machine-specific code here Msg "custom M100" M54 P1 ;switch on AUX output 1 endsub

So if the G-Code file performs M100, the subroutine will be called. Parameters are possible with syntax such as M100 S100. In the subroutine the parameter can be accessed using variable #19 (#1 .. #26 accesses parameter A through Z), S corresponds to no. 19 as in, the 19th letter in the English alphabet. It is possible to override existing M functions as well. As an example, additional action can be made during the M3 command (tool on) .

If the machine's spindle has an output that signals that the target speed has been reached, the machine can wait for that output, as an example:

sub m3 msg "my customized m3" m3 s#19 ;Inside overridden subroutine this executes the standard M3 m56 P1 L2 Q60 ;Wait max. 60 seconds for AUX input 1 to change to low endsub

When an M-command is called from inside the subroutine that also overrides the same M-command, then the overridden subroutine is not called recursively, but the standard M3 implementation is executed instead. There are some limitations to using the M Function override feature:

  • There must be no other statements on the same line i.e. N2000 M3 S1000 is valid. N2000 M3 M8 G1X100 is invalid
  • The variables #1 through #26 will be used to hold parameter values and will be overwritten when M-Function subroutines are used. Take this into account and do not use variables #1..#26 in your macro program if you use this functionality. Variables #1 through #26 correspond to the letter of the English alphabet, #1 will get the value of parameter A, and #26 will get the value of parameter Z.