Hello Guest it is July 20, 2025, 12:43:41 PM

Author Topic: Problem with custom M5 macro  (Read 9568 times)

0 Members and 1 Guest are viewing this topic.

Re: Problem with custom M5 macro
« Reply #10 on: August 10, 2023, 03:42:30 PM »
I upgraded mach4 from 4.2.0.4809 to 4.2.0.5125. Still not working.
Re: Problem with custom M5 macro
« Reply #11 on: August 13, 2023, 05:27:49 AM »
I'm getting the same result as you, trying to execute a custom macro within another macro causes it to hang. You will have to turn off the spindle in the m30 using mc.mcSpindleSetDirection like you did in the m6.. it's probably the better way to do it anyway
Re: Problem with custom M5 macro
« Reply #12 on: August 13, 2023, 09:16:41 PM »
Glad to hear it is not only me. Wasn't seeing many responses so I was beginning to think it was something with my installation or setup.

I will probably do a mc.mcSpindleSetDirection for now in my m30 but I would like to know what is causing the issue. I am in contact with Trevor from machsupport so I hope to have a resolution soon.
Re: Problem with custom M5 macro
« Reply #13 on: August 23, 2023, 02:26:32 PM »
I thought I should update this thread in case anyone is interested.

Trevor didn't give me an exact reason why a custom m5 macro doesn't work when used in a mc.mcGCodeExecuteWait beside it wasn't proper to call a macro from within a macro. I ended up replacing them with an m5(). it worked fine that way.

Quote
I can tell you this, calling a macro inside of another macro isn't the way to do it typically as you can avoid it 99% of the time, however, if you are calling another macro within your macro make sure it's not called with a GCODEEXECUTEWAIT(inst, "M5") as I believe you should just call the m5() function that is contained within that macro.

So this changes from:

mc.mcGCODEEXECUTEWAIT(inst, "M5")

to

m5()

All the macros get compiled together so you should have access to all the macro functions within all macros.
For instance, if you make an M5.mcs file with nothing in it and you have a m6000.mcs file as well, you can define the m5() function within the M6000 macro because they all get compiled together.

Offline smurph

*
  • *
  •  1,574 1,574
  • "That there... that's an RV."
Re: Problem with custom M5 macro
« Reply #14 on: August 30, 2023, 03:52:36 AM »
Calling a macro from another macro with mcCntlGcodeExecute/Wait() is not the best practice.  You are writing a script that should call script functions where possible.  So if M5 called mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF), then your M30 script should too INSTEAD of calling mcCntlGcodeExecute/Wait(inst, "M5")  Why?  Because the interpreter is already RUNNING an M code that is backed by a script.  Some M codes are built in (no script) and they will run. 

So what if you M5 does some multiline complex operation and it is hard to edit EVERYTHING to do that operation? Especially if you made changes to it and want to update everything.  This is where code sharing via modules becomes a good idea. 

Steve