Break out of a While Loop ??

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Break out of a While Loop ??

Postby Vmax549 » Mon Feb 26, 2018 9:34 pm

Anyone have an idea on how to break out of a while Loop other than shutting down UCCNC and restarting ??

esc does not work
cyclestop does not work
reset does not work

All the loops have a Thread.Sleep(10) So ESC should work BUT it doesn't

Yes I can write an escape function based on a timer(loop count) BUT that is not what I need for these loops.

These are loops waiting on an action. If that action never happens then you are stuck (;-)

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

Re: Break out of a While Loop ??

Postby dezsoe » Mon Feb 26, 2018 10:32 pm

Check the reset LED in the while condition. That makes reset do the job. I have no idea for stop... :)
dezsoe
 
Posts: 496
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Break out of a While Loop ??

Postby beefy » Tue Feb 27, 2018 6:47 am

Why can't you add code in the while() loop, something along the lines of:

if (reset) // that's only pseudo code.
{
break;
}

OR:

if (Cycle Stop)
{
break;
}

Adds a little more overhead to your while() loop but if it's not affecting anything...................
beefy
 
Posts: 186
Joined: Mon Sep 05, 2016 10:34 am

Re: Break out of a While Loop ??

Postby Vmax549 » Tue Feb 27, 2018 12:48 pm

HIya Keith, In this instance I do not want uccnc to reset or cyclestop as it effects teh running of teh program. I am trying to figure out why ESC does not work. I have used esc before and it worked then. Same type loop different results :(

I'll let you know when I figure it out .

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

Re: Break out of a While Loop ??

Postby Battwell » Thu Jul 26, 2018 9:59 am

I know this is an old thread
But I had the same problem.
I’ve just finished a very nice way to do this.
It also looks at feedhold so the macro can be held ( handy for toolchangers etc)
If stop is pressed it makes safe any outputs and exits gracefully.

I was reading your other post re dereks tool changer. I had the same problems which the new code overcomes :-)
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 322
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Break out of a While Loop ??

Postby cncdrive » Thu Jul 26, 2018 10:19 am

To break out of a while loop is simple, all you need to do is properly formulate the condition of the loop, so it will break out when the condition goes false. :)
cncdrive
Site Admin
 
Posts: 2110
Joined: Tue Aug 12, 2014 11:17 pm

Re: Break out of a While Loop ??

Postby Battwell » Thu Jul 26, 2018 10:38 am

yeah thats easy for a programmer to say.
for us non programmers- copy/paste and edit is the real easy way.

here is my test code- which is easily editable and notated so you can see what is happening and why.

//waits and repeats while feedhold is true and stop button not pressed
//otherwise exits when feedhold is switched off- or stop button is pressed
//ps- this took me hours to write! brendon
// this test is used with either flood on or feedhold on- stop escapes it.


int port=3; // output to activate if switch is seen
int pin=3;
int switchled=53; // first switch to be checked - change as required before wait loops for relevant switch number


// dont change below here//
int holdled=217; // * dont change- this is feedhold check*//
bool stopped=(exec.Ismacrostopped());
bool hold= (AS3.GetLED(holdled));// is feedhold active
bool led= (AS3.GetLED(switchled));// flood on? - for testing or. (would be an input led in a program)
//end dont change area//



port=3; // output to activate if switch is seen
pin=3;
switchled=53; // change to led input number to wait for in following loop

//***start of test loop***// change nothing inside the loop
do{
led= (AS3.GetLED(switchled)); // (this will be the switch that while loop is waiting for) *** change led number for while input before test loop start ***
hold= (AS3.GetLED(holdled)); //must be re checked inside the loop
if((!hold) && (!led)) { // (not in feedhold )
exec.Setoutpin(port, pin);} // eg. Open the chuck with pneumatic valve// add anything else required to do here when input becomes valid.
exec.Wait(100);
}while ((hold)||(led)&&(!exec.Ismacrostopped())); //switch or feedhold and not stopped.( add ! before led. eg. (!led) if waiting for switch active)
//***end of test loop***//

exec.Wait(10);
stopped=(exec.Ismacrostopped());
if(exec.Ismacrostopped()){
exec.Clroutpin(port, pin);// if stop has been pressed reverse anything that needs reversing in order!
exec.AddStatusmessage("stopped at close chuck 1 = "+ stopped); // tell operator where stop was pressed
goto Finito;} // exit macro
exec.AddStatusmessage("output set = chuck closed "); // can be omitted- but good for testing.



Finito:// put these lines at end of total program.
// make safe any outputs here
return;
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 322
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Break out of a While Loop ??

Postby Vmax549 » Thu Jul 26, 2018 2:00 pm

It depends on what you mean by break out of a loop.

Did you want to end teh macro ?

DId you you want to exit teh loop and continue teh macro ??

Did you want to be able to skip teh loop when exiting with ESC or stop ?

Normally I use a double loop the first to process teh request and a 2nd inside teh first to be able to {ESC} if needed.

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

Re: Break out of a While Loop ??

Postby Battwell » Thu Jul 26, 2018 3:50 pm

i wanted it to do exactly what the code above does. work- and not get stuck anywhere! :-)
Uc300eth on router and mill
If they say it can't be done- I find a way!
Battwell
 
Posts: 322
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: Battwell and 3 guests