Prevent one macro from starting while another runs ??

If you have a question about the software please ask it here.

Re: Prevent one macro from starting while another runs ??

Postby Dan911 » Sat May 05, 2018 1:02 pm

Couldn't you just Setvar() on start and finish of macro and the other check with Getvar() ?
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Prevent one macro from starting while another runs ??

Postby Dan911 » Sat May 05, 2018 7:46 pm

Vmax549 wrote:Yes that would be setting a flag.

Are there any internal functions like IsMacroRunning() ???

(;-) TP


There is no such function from what I can see YET...LOL

But if there was wouldn't that be just using an internal flag? I would think setting your own with different methods to a specific macro to synchronize with another would be just as powerful.

myvariable = exec.Getvar(600)

While(myvariable == 1)
{
Wait(100)
if(exec.Getvar(600)==2){break;}
}

//When other macro finishes sets var to 2 and this code continues. If it don't work feel free to beat me up :shock:
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Prevent one macro from starting while another runs ??

Postby Dan911 » Sat May 05, 2018 10:12 pm

I misunderstood your question, I thought your were referring to synchronizing by stopping the macro to start until other completes. Similar to and Manual or Auto reset event for threads.

Good point! Will 2 macro's run at same time? They are threads and we know macro loops do.

The difference with...

if(IsmacroRunning())
{
exec.AddStatusmessage("Another macro is Running");
return;
}

The macro will return and not run, the example I showed it should wait for the macro to complete and than run. If 2 macro's can't run at same time than it's useless, will have to do some testing.

Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Prevent one macro from starting while another runs ??

Postby cncdrive » Sat May 05, 2018 10:32 pm

More that one macro can run in parallel with macroloops.
When macros run via MDI or g-code then only 1 macro can run in parallel one time.
When a macro is called via MDI or g-code file and if another macro is called from that macro like for example exec.Code("M20000"); then there is still sequential execution when the caller macro waits until the called macro returns and then the caller continues execution after the call line.
The tricky part can be that when passing motion commands via the exec.Code then that command is passed along to the motion control API and then the .Code function returns and so the macro continues and if the user wants the macro to wait for that to finish then a while ismoving can be added. In this case there is still sequential execution of the macro lines, but the motion will execute in parallel which can be waited out if needed with the while ismoving.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Prevent one macro from starting while another runs ??

Postby cncdrive » Sat May 05, 2018 10:36 pm

I've attached 2 simple macros to show the sequential execution.
M300 should be called via MDI and it prints "1" into the status field, then it calls the M301 macro and that prints "2" and waits one second and the M301 macro ends and returns and then the first macro prints "3".
Attachments
M301.txt
(51 Bytes) Downloaded 580 times
M300.txt
(80 Bytes) Downloaded 605 times
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Prevent one macro from starting while another runs ??

Postby Dan911 » Sat May 05, 2018 10:53 pm

Thanks Balazs for the very useful info for me, and I'm sure many others.

I assumed( :oops: ) this thread was referring to Terry's complicated ATC macro's he was working on that enabled ports/pins in a needed sequence. My Bad.

Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Prevent one macro from starting while another runs ??

Postby cncdrive » Sun May 06, 2018 12:00 am

Hi Dan,

I'm gald if my explanation helped.
The same applies to other commands like changing outputs. There is always sequential execution of the lines.
I just wrote the examples with printing text into the status field, because it is easy to observe the sequence with this code, because the order of the print shows the order of the code execution.

There is only a bit difference from fully sequential code execution is when there is a motion command like exec.Code("G0 X0");, then it still sequentially executes that line of code, but the Code function returns as soon as the code is interpreted and the motion command is written into the motion buffer and so the Ismoving bit is set. So, then the user can decide if he wants the macro to wait for the motion to stop or if he wants to execute more commands while the motion is still ongoing. E.g. printing some values on the screen.
A while ismoving loop can be placed in the macro after the motion command to wait for the motion to end and only then go on with executing the next line of code.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Prevent one macro from starting while another runs ??

Postby Derek » Sun May 06, 2018 1:06 am

I'm pretty sure 2 macros can run at the same time if the second one is triggered via external button. At least that is what I experienced when I pushed the tool out button in the middle of a M6 being executed.
Derek
 
Posts: 341
Joined: Mon Sep 05, 2016 9:57 am

Re: Prevent one macro from starting while another runs ??

Postby cncdrive » Sun May 06, 2018 1:58 am

Yes, they can. I forgot to include the button macro calls in my description, I did not think about them, so I did not add them...
Where more then one can't start and run in parallel is the MDI and g-code program calls, because those are one-one threads which one instance can run one time. (on purpose)

And when a macro calls another macro then no new thread is started, but a direct invoke is made to execute the other macro, so they are always kept in syncron in sequential execution.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Prevent one macro from starting while another runs ??

Postby cncdrive » Sun May 06, 2018 4:20 am

OK, but how would you check if a macro is running or not? Check by macronumber? Or how?
A macro could run by several sources, it could run via the MDI, via g-code, via button call, via plugin.
Macros could even run in several instances if put into more than one slots of macroloops.
So, I think that just providing a flag to check if e.g. macro number 300 is running or not is not a solution because of this.
Or we should provide a flag for button presses? I mean if a macro call button press is still running a macro (by number)?
I don't clearly understand what you want to do and for what problem is a solution needed for, so it is hard to figure it out.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 43 guests