- Code: Select all
bool LEDprevstate = AS3.GetLED(54);
double Zup = -20;
while(loop)
{
loop = exec.looprun[loopnumber]; //To update the loop variable, because this internal loop does not reach the end of the macro, so the loop can be stopped and does not have to be killed to get stopped
bool LEDcurrstate = AS3.GetLED(54); //Get the Cycle start LED current value
if(LEDcurrstate != LEDprevstate && !LEDcurrstate) //If the Cyclestart LED state changes and if it changed to off then do some action...
{
exec.macrostop = false; //The Stop button sets the macrostop variable, so this has to be reset, because otherwise movement will not execute.
exec.Code("G53 G0 Z" + Zup); //Execute the movement
}
LEDprevstate = LEDcurrstate; //Set the current LED state to the previous one
Thread.Sleep(50); //Sleep some time so the loop will not overload the CPU
}
Yep, there is a trick why it probably did not work for you Terry and honestly yesterday when I wrote this advice I did not think about this, only when I've coded the macro.
So, the issue is that this thing have to be triggered on the stop button, but the stop button is the button used to stop motion.
The problem about this is that the stop button has to stop motion, but in this case the macro still has to execute motion, and that motion also has to be stopable with the stop button.
When the stop button is pressed then an internal variable is reset to stop the movements and so the macro executer will not accept more movements, because then the macros can still continue the run,
but should not add more motion to the buffer if the user requested a stop.
The trick for the macroloop is to set that internal variable of the UCCNC (as in the above code) ater the stop button is pressed, so the software will accept the movement.
Just FYI, the same variable is also set when a Cycle is started and when a MDI code is executed and is reset when a Stop or reset it executed, so the macros will know when it is allowed and when not to make movements.
In general macroloops are not adviced to generate motion, but they could, just it is a little tricky...