Page 1 of 1

Re: Break out of a While Loop ??

PostPosted: Mon Feb 26, 2018 10:32 pm
by dezsoe
Check the reset LED in the while condition. That makes reset do the job. I have no idea for stop... :)

Re: Break out of a While Loop ??

PostPosted: Tue Feb 27, 2018 6:47 am
by beefy
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...................

Re: Break out of a While Loop ??

PostPosted: Thu Jul 26, 2018 9:59 am
by Battwell
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 :-)

Re: Break out of a While Loop ??

PostPosted: Thu Jul 26, 2018 10:19 am
by cncdrive
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. :)

Re: Break out of a While Loop ??

PostPosted: Thu Jul 26, 2018 10:38 am
by Battwell
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;

Re: Break out of a While Loop ??

PostPosted: Thu Jul 26, 2018 3:50 pm
by Battwell
i wanted it to do exactly what the code above does. work- and not get stuck anywhere! :-)