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.

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: 2093
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: 449
Joined: Mon Sep 05, 2016 10:34 am

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.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
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: 4887
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.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

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.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: No registered users and 9 guests