Cancel a macro

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

Re: Cancel a macro

Postby ger21 » Wed Apr 25, 2018 12:52 am

The machines that I've used would timeout in cases like that.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2663
Joined: Sat Sep 03, 2016 2:17 am

Re: Cancel a macro

Postby Dan911 » Wed Apr 25, 2018 3:19 am

Hi Terry,

What I see what's happening is pressing ESC is only exiting what's being executed at time of ESC press but macro continues to end. Adding a messagebox after first wait shows this.

exec.Setoutpin(5,16);
exec.Setoutpin(5,17);
exec.Wait(10000);

MessageBox.Show("Escape key pressed");

exec.Clroutpin(5,16);
exec.Clroutpin(5,17);
exec.Wait(10000);
exec.Setoutpin(5,16);
exec.Setoutpin(5,17);

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

Re: Cancel a macro

Postby cncdrive » Wed Apr 25, 2018 9:12 am

Hi Terry,

Yes, ofcourse what you wrote will be happening, but basicly the same is what I described.
What clears the output is the macro and not the UCCNC.

A simpler code is:
Code: Select all
exec.Setoutpin(5,17);
exec.Wait(10000);
exec.Clroutpin(5,17);


If you press the Stop (ESC) between the output set and clr lines then the wait will be cancelled and the macro will continue with the next line which clears the pin.
You could add a conditional check to only execute the output clear if the macro was not stopped:

Code: Select all
exec.Setoutpin(5,17);
exec.Wait(10000);
if(!exec.Ismacrostopped())
{
exec.Clroutpin(5,17);
}
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: Cancel a macro

Postby dezsoe » Wed Apr 25, 2018 1:13 pm

Yes, because after stop no more movements are allowed, but other things in the macro will be executed. Try this and check status window:

Code: Select all
exec.Setoutpin(5,17);
exec.Wait(10000);
exec.Code("G0 X10");
exec.AddStatusmessage(exec.Ismacrostopped() ? "Stopped!" : "Not stopped");
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Cancel a macro

Postby dezsoe » Wed Apr 25, 2018 5:02 pm

NO, NO!!! If the macro has to stop then use

Code: Select all
if (exec.Ismacrostopped()) return;

after every movement. It works fine.

But sometimes you have to handle things after a stop was pressed, so a stop MUST NOT cancel a macro!
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Cancel a macro

Postby beefy » Wed Apr 25, 2018 9:39 pm

Terry,

you've been using the word "stop" the macro, but I think more appropriate description would be "pause" the macro while you fix things.

I wonder if Cncdrive could add several toggle button functions that do exactly this ??? We'd need several because you would not want all running macros to be paused, just the one you wanted paused.
Therefore in the macro code, you'd have to "activate" a specific pause button at the beginning, so that specific pause button would pause this macro.

Of course in your examples it would mean if you paused at the beginning of a long wait instruction, it would resume and carry on with the long wait.

Balazs / Dezsoe,

is this a ridiculous idea, or can this be accomplished already in a simple way, instead of putting a command after every code line.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: Cancel a macro

Postby beefy » Wed Apr 25, 2018 10:55 pm

OK, but that's left me confused because you talk about leaving all outputs in their state they are at when you STOP / TERMINATE the macro, then afterwards RESUME from where you left off.

I'm obviously missing something. How do you terminate a macro, but then resume it say half way through where it was terminated ??

Or have I completely misunderstood you.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: Cancel a macro

Postby cncdrive » Wed Apr 25, 2018 11:07 pm

Terry,

Cancelling a macro would mean to kill the macro thread which is dangerous according to Microsoft and even in school when you learn programming they always theach to possibly never do that.
The macro is a thread which is started and is running and the only way to really stop it in the middle is to kill it's thread or to let it end it's run and to let it peacefully terminate.
The proper way is to let it terminate and let the programmer handle the possible scenarios of stopping event.
Killing the thread does not even guarantee when the thread will die, it may still live for a while and it may die in the middle of doing something leaving things half-way set is why it is dangerous.
The programmer can handle the different scenarios to let the macro end without issues which he has to handle like I described in my previous post.

I think many problems in Mach3 come from that they killing threads which can make things to go random and unexpected.
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: Cancel a macro

Postby Dan911 » Thu Apr 26, 2018 1:02 am

Hi Terry,

Just reading through this informative thread and I'm also confused on what your after? You posted from start before anyone else it's not good or recommended to kill a thread.

What's wrong with this code??? When escape key pressed motion stops and you can set your port/pins, conditions to what ever you like when macro ends. If I'm missing something I apologize and please explain.

Dan

exec.Setoutpin(5,16);
exec.Setoutpin(5,17);
exec.Wait(10000);
exec.Clroutpin(5,16);
exec.Clroutpin(5,17);
exec.Wait(10000);
exec.Setoutpin(5,16);
exec.Setoutpin(5,17);

if (exec.Ismacrostopped())
{
exec.Clroutpin(5,16);
exec.Clroutpin(5,17);
return;
}
Last edited by Dan911 on Thu Apr 26, 2018 1:16 am, edited 2 times in total.
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Cancel a macro

Postby beefy » Thu Apr 26, 2018 1:03 am

Well the one thing I can say is this thread has been very informative.

Never had anything to do with tool changers (outside of work that is) but I'd thought if I ever make my own I'll go the microcontroller route. That now sounds even more viable after reading this thread.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

PreviousNext

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 14 guests