Hello Guest it is November 29, 2021, 04:26:06 PM

Author Topic: Can i edit or add to a Predefined Macro?  (Read 4102 times)

0 Members and 1 Guest are viewing this topic.

Offline Bx3mE

*
  •  68 68
    • View Profile
Can i edit or add to a Predefined Macro?
« on: December 16, 2016, 10:43:13 AM »
I want to ADD stuff to the M30 Macro. I want it to be working as it works by default but add some code to finish up a GCode run.

All my Cam software end programs with move Tool to Z clearance plane, turn spindle off and (M30) stop execution and set next line marker to the first line.
After this i want to do some more stuff like turn on the coffe mashine to make a nice cup of coffe so i can admire my work in peace and also send an email to my phone telling me coffe is ready in 3 minutes.... :D

How and or where do i do this?

Offline DazTheGas

*
  •  764 764
  • DazTheGas
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #1 on: December 16, 2016, 11:09:31 AM »
Prob best to create another custom m code and then edit your post processor to use that instead of m30

Well thats what I did

DazTheGas
Theres always time for a choccy biccy

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #2 on: December 16, 2016, 11:54:26 AM »
One way i thought of was to Create a signal script:

If cycle_start_has_been_detected and signal "sig_program_end" is detected then cycle_start_has_been_detected = 0 AND EXEC(Custom M Code)


Would that work or would it create problems?

Offline smurph

*
  • *
  •  1,475 1,475
  • "That there... that's an RV."
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #3 on: January 03, 2017, 11:50:16 PM »
You CAN create a M30 macro.  If you do, it will REPLACE the stock M30 functions.  So when you write it, you will need to put any of the original functionality of the stock M30 into the custom M30 macro. 

The stock actions for M30 in mill are:

1. Stop the spindle.
2. Turn off cutter comp.
3. Turn off mist.
4. Turn off flood.
5. End processing (Cycle Stop).
6. Rewind.

Note: #5 and #6 are preformed even if a custom M30 macro exists.  The entire custom M30 macro will be executed and then #5, followed by #6, will be executed. 

Code: [Select]
function m30()
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "This is my m30 macro")
end

if (mc.mcInEditor() == 1) then
    m30()
end

If you used that file, when G code calls M30, it will simply print they message, end processing, rewind, and do NOTHING else.

So, to recap: 
1.  If the m30.mcs macro exists in the macros directory, it will be used in lieu of the stock M30 actions.
2.  If a custom M30 macro is used, it must include all of the functionality you wish as none of the stock M30 actions will be performed otherwise except for Cycle Stop and Rewind.

Steve

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #4 on: January 04, 2017, 08:59:32 AM »
Thank You So it is as easy as writing a M6 Macro :)

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #5 on: January 04, 2017, 09:20:28 AM »
Thank You So it is as easy as writing a M6 Macro :)


Yup, maybe even easier.  :)

Remember, the macro file name and functions inside the macro should all use a lower case m.......... m30 not M30
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Can i edit or add to a Predefined Macro?
« Reply #6 on: January 26, 2017, 04:01:32 PM »
Hi,
I need to customise m03,m04 and m05.

I have written the macros and they run ok in the debugger. If I call them from the MDI line the Mach4 internal functions run and
ignore my customised macros.

Code: [Select]
function m03();
local inst=mc.mcGetInstance();
mc.mcCntlSetLastError(inst,"My m03");
local hcont=mc.mcRegGetHandle(inst,"modbus0/spinCntrl");
mc.mcSpindleSetDirection(inst,1);
mc.mcRegSetValue(hcont,10);
end
if (mc.mcInEditor() == 1) then
    m03()
end

As you can see I'm trying to write to a Modbus register in addition to the normal function. I set the 'Last Error' message just to indicate
whether my script runs or not.

Craig
My wife left with my best friend...
     and I miss him!

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #7 on: January 26, 2017, 05:05:28 PM »
Have you tried naming it m3?

Got a m3 or m03.mcc or .backup thats needs to be deleted?
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Can i edit or add to a Predefined Macro?
« Reply #8 on: January 26, 2017, 05:50:16 PM »
Hi,
thanks, naming m3 worked.

I'm guessing that I'm now calling a distinct macro (m3) whereas the internal function is m03. This is a workaround rather
than a solution, or rather an understanding of whats going on. I'll take whatever I can get!

Thanks again,
Craig
My wife left with my best friend...
     and I miss him!

Offline smurph

*
  • *
  •  1,475 1,475
  • "That there... that's an RV."
    • View Profile
Re: Can i edit or add to a Predefined Macro?
« Reply #9 on: January 26, 2017, 06:18:38 PM »
The macros (and functions inside them) should be lower case and leading zeros dropped.  m03, M03, m3, or M3 is accepted by the interpreter, but it gets low cased and leading zeros dropped shortly there after.  Windows is not case sensitive but LUA is.  Everything ought to be case sensitive.  Everything on the planet, except Windows, IS!!!! 

If you write a custom m3 macro, it replaces the stock actions of m3.  So you must provide all functionality you desire in the custom m3 macro.  See the doc on mc.mcSpindleSetDirectio().

Steve