Hello Guest it is April 25, 2024, 07:05:23 AM

Author Topic: Mcode Macro works in program but not MDI?  (Read 928 times)

0 Members and 1 Guest are viewing this topic.

Mcode Macro works in program but not MDI?
« on: March 26, 2020, 04:57:11 PM »
I have a macro M100 that I use to control a grinding cycle.  It checks the user input and outfeeds a grinding wheel until the total grind amount is reached.  If I make a program:

Code: [Select]
M100
M30

The macro program runs fine.  But if I just call M100 from MDI, the macro starts but never outfeeds the wheel. The wheel outfeed is done in the plc loop like this:

Code: [Select]
local g_code = ""
g_code = g_code ..string.format("G0 G91 A%.4f\n",cut_amount)
mc.mcCntlGcodeExecute(inst, g_code)

The macro and plc loop both read from and write to Gregister values for this cycle to work.  This used to work properly in a much older version of Mach4. Currently running version 4300

Can anyone give me an idea as to what would cause differing behavior like this?  I would expect M100 to do the exact same thing running in MDI or as a Gcode program?

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Mcode Macro works in program but not MDI?
« Reply #1 on: March 26, 2020, 08:24:14 PM »
It could be an enable function issue in the new screen scripts.  Only a guess though.
Without engineers the world stops
Re: Mcode Macro works in program but not MDI?
« Reply #2 on: March 27, 2020, 08:07:50 AM »
Any suggestions on how I might troubleshoot this? 

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: Mcode Macro works in program but not MDI?
« Reply #3 on: March 27, 2020, 12:09:33 PM »
Is the macro checking any signals before it continues, some signals may only be active in program mode.
Without engineers the world stops

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mcode Macro works in program but not MDI?
« Reply #4 on: March 27, 2020, 04:57:51 PM »
Try changing this:

mc.mcCntlGcodeExecute(inst, g_code)

to

mc.mcCntlGcodeExecuteWait(inst, g_code)

M30 in MDI is basically a no op if you don't have a pallet changer.  The other thing M30 does is rewind the file, but MDI isn't a file and MDI will not rewind.  So I'm thinking that the MDI is just plain ignoring the M30 and the ends process before the G code gets started.  Hence why I'm thinking the Wait variant of the call should be used. 

Try it and see.

Also, I see you are not checking the return code from the API call.  A lot of mysteries are solved by checking the return codes. 

Steve
« Last Edit: March 27, 2020, 05:04:01 PM by smurph »
Re: Mcode Macro works in program but not MDI?
« Reply #5 on: April 08, 2020, 03:37:16 PM »
Sorry for late reply.  Lots of fires to put out lately!

I wrote this code 4 years ago so I am rediscovering how it works now ;D. I found out my code relies on mc.mcCntlIsInCycle(inst) = 1 to function properly.   The PLC script operates a pneumatic axis that reciprocates.  It uses a linear scale to determine when to change direction.  The grinding wheel outfeeds when at the end of the stroke.  I use mc.mcCntlIsInCycle(inst) to ensure outfeed can only happen when the cycle is running.

Running the M100 in MDI mode does not change mc.mcCntlIsInCycle(inst) to a value of 1.  I changed the code to use OSIG_RUNNING_GCODE = 1 and it appears to be functioning properly again  :).

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mcode Macro works in program but not MDI?
« Reply #6 on: April 08, 2020, 06:00:35 PM »
You can also use mc.mcCntlGetState() and test with the mc.MC_STATE_* constants.  Glad you found it and have it running! 

Steve