Prevent one macro from starting while another runs ??

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

Prevent one macro from starting while another runs ??

Postby Vmax549 » Sat May 05, 2018 12:28 pm

What would be a good way to prevent a macro from starting while another is running ??

I have come up with using flags.

Any other options ?

(;-) TP
Vmax549
 
Posts: 1102
Joined: Sun Nov 22, 2015 3:25 am
Location: USA

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: 373
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

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

Postby Vmax549 » Sat May 05, 2018 5:40 pm

Yes that would be setting a flag.

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

(;-) TP
Vmax549
 
Posts: 1102
Joined: Sun Nov 22, 2015 3:25 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: 373
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

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

Postby Vmax549 » Sat May 05, 2018 9:35 pm

YEs it is a flag BUT it is not one that you have to continually manipulate in the scripting.

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

That would simply prevent you from starting another macro when one is already running

Now teh question would be DOES teh return in teh second macro also effect teh first macro as well???

With 2 macros running how does {ESC}/{STOP} work in that case ?? Does it cancel BOTH macros or just one?

SO MANY questions (;-)

(;-) TP

(;-) TP
Vmax549
 
Posts: 1102
Joined: Sun Nov 22, 2015 3:25 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: 373
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: 2105
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 16 times
M300.txt
(80 Bytes) Downloaded 16 times
cncdrive
Site Admin
 
Posts: 2105
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: 373
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: 2105
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 2 guests

cron