Hello Guest it is May 14, 2021, 03:34:54 AM

Author Topic: mcCntlGcodeExecuteWait Inside a macro  (Read 1140 times)

0 Members and 1 Guest are viewing this topic.

mcCntlGcodeExecuteWait Inside a macro
« on: April 22, 2017, 09:16:42 AM »
So unless I'm mistaken, this doesn't work.  I'm noticing that when inside a macro, it doesn't "wait".  I think I have a plane to address this bit was hoping y'all could tell me if I'm headed down the right path.  Here's what the macro looks like...

Collect some data
Build a block of GCode
Execute GCode
----------------------------------------
Do some other stuff inside the macro
----------------------------------------
Build another block of GCode
Execute GCode
End macro

So here's the plan...

Run this as a function in a coroutine.  Call it co1...
---Collect some data
---Build a block of GCode
---Execute GCode

Run this as another function in a coroutine.  Call it co2...
---Build another block of GCode
---Execute GCode

Then basically....

Coroutine.resume(co1)
While coroutine.status(co1) == 'Running' do
  Set error message
End

Do other stuff within the macro

Coroutine.resume(co2)
While coroutine.status(co2) == 'Running' do
  Set error message
End

Last block of GCode should be done.  Exit the macro and move to next line in the program.

So my only concern is where to put the 2 function.  If mcCntlGcodeExecuteWait won't work inside a macro, then they will have to be elsewhere.  Seems that even for the couroutine to work, it will need to wait for the Gcode within to execute before returning.  So how about a module?  Will mcCntlGcodeExecuteWait work inside a module?

How about using mcCntlIsStill() instead of coroutines?



Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: mcCntlGcodeExecuteWait Inside a macro
« Reply #1 on: April 23, 2017, 03:37:17 AM »
I have mcCntlGcodeExecuteWait working in many macros, normaly an error in a macro will cause the macro to not be compiled at runtime, this in turn will mean that the m code will be skipped during operation.

DazTheGas
Theres always time for a choccy biccy
Re: mcCntlGcodeExecuteWait Inside a macro
« Reply #2 on: April 25, 2017, 01:15:03 PM »
I think the issue was in one particular macro.  I wrote some test macros with some motion commands and they all executed fine with no timing issues.  I couldn't pinpoint the issue with the macro because it worked in the editor but failed when run.  When it failed it just went to the next line which made me think it was just blowing past the mcCntlGcodeExecuteWait().  I re-wrote the macro and it worked.

I did figure out that using a combination of mcCntlMdiExecute() and mcCntlGcodeExecuteWait() can cause strange behaviour. I've seen a total crash and I've seen where the code seems to function, but it doesn't update the screen (DRO's and toolpath display) while it's doing it.  For instance using mcCntlGcodeExecuteWait() in the macro, then calling the macro from a button using mcCntlGcodeExecuteWait(inst, 'M3000') caused a crash.  Calling the same macro using mcCntlMdiExecute(inst, 'M3000') works if there is no other code or if this is the last line of code, otherwise it blows past the mcCntlMdiExecute() and on to the next line.  

If I take the code out of the macro, using mcCntlGcodeExecuteWait(), and drop it in a button script, it seems to work, but the screen doesn't update while the code is running.  It updates after the button script is done.  It's just a matter of figuring out what works with what.  
Re: mcCntlGcodeExecuteWait Inside a macro
« Reply #3 on: September 20, 2017, 01:12:42 PM »
I have the same issue where I can compile and step through the lua code it works fine in debug mode. When I try to run my M file from MDI or in a gcode line it ignores it. If I copy and paste the code to a button, without the function title and debug snip at the end, it operates correctly but does not update the screen till it is finished. I really need the screen dro's updated while it is running. Is there a function I can drop in my lua code that will update the screen on demand?