Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: beezerlm 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:
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:
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?
-
It could be an enable function issue in the new screen scripts. Only a guess though.
-
Any suggestions on how I might troubleshoot this?
-
Is the macro checking any signals before it continues, some signals may only be active in program mode.
-
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
-
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 :).
-
You can also use mc.mcCntlGetState() and test with the mc.MC_STATE_* constants. Glad you found it and have it running!
Steve