M Function override and user M-functions
The system allows M functions in the range of M1..M999. This means there are many un-used M-functions. The user can create his own M-Function by creating a subroutine for it in the macro.cnc.
For example:
sub m100 ;Do your stuff here Msg “my M100” M54 p1; switch on AUX output 1 endsub
So if the g-code file performs M100, the subroutine will be called. Also parameters in the form M100 S100 is possible. In the subroutine the parameter can be accessed using #19 (#1 .. #26 accesses parameter A..Z), S is number 19 in the alphabet. This creates further possibilities: It is possible to override existing M functions as well. Suppose you want additional function for M3 which is spindle on standard. If you spindle has an output speed-reached, you can wait for it like this:
sub m3 msg "my customized m3" m3 s#19 ;The real m3, inside sub routine this m3 will execute the real m3 m56 P1 L2 Q60 ; Wait max. 1 minute for input 1 to become low endsub
When you are inside your m3 subroutine and perform an m3, then the subroutine is not called, but the default m3 is called instead. There are some limitations on using the M Function override:
• There must be nothing else on the G-code line as the M-Function, e.g.
N2000 M3 S1000 is OK.
N2000 M3 M8 G1X100 is NOT OK!
• The user parameters 1-26 will be used as parameter and will be overwritten when M-Function subroutines are used. Take this into account and do not use #1..#26 in your program if you use this functionality. Variable 1-26 match with the letter of the alphabet, #1 will get the value of parameter A, #26 will get the value of parameter Z.