NOT really a good idea to use mainstrem Mcodes to do odd things. ANY CAM programs would have difficulty writing programs unless you modified the post to suit the odd functions
M3 turns on the spindle CW
M4 turns on spindle CCW
M5 turns the spindle off
M7 M8 turns on coolant or vacume or dust collector
M9 turns them off
It would be best to create user Mcodes to do the odd things.
M100-M200 would be a good place to start.
There are seperate functions for things like enable drives,enable machine,etc
Just a thought, (;-) TP