I was able to made some test about the macro loop.
Quite simple macro loop in the end.
It will read the led status of the door and the Idle Led.
If the door is open and the idle led is off it will stop the execution.
Firt I tryed using the
- Code: Select all
exec.Stop();
and then
- Code: Select all
exec.code("M30");
exec.Stop();
It works ok when I press Cycle Start, but there is some problem while using movement provided by the MDI field input, or using jog and probing function.
There is always a small delay before che macro loop check the status and kill the movments.
One workaround should be to put all the joob feedrate and feedrate to 0% while the door is open, but is just seems to be a bad patch...
In the end I wrote this
- Code: Select all
bool lastDoorLed = !AS3.GetLED(37);
double lastFeed = 0;
double lastJogFeed = 0;
while(true)
{
bool doorLed = !AS3.GetLED(37);
bool idleLed = !AS3.GetLED(18);
if(!lastDoorLed && doorLed)
{
//last was closed but now is open. Save feed value and Stop all and feed to zero
string tmp = AS3.Getfield(232);
tmp = tmp.Replace('%',' ');
lastFeed = double.Parse(tmp);
lastJogFeed = double.Parse(AS3jog.Getfield(913));
AS3.Setfield(0,232);
AS3.Validatefield(232);
AS3jog.Setfield(0,913);
AS3jog.Validatefield(913);
exec.Callbutton(130);
exec.Stop();
}
else if(!lastDoorLed && !doorLed)
{
//last door check is cloed and now door check is closed. Do nothing
}
else if(lastDoorLed && !doorLed)
{
//lastOpen and now closed, restore feedrate
AS3.Setfield(lastFeed,232);
AS3.Validatefield(232);
AS3jog.Setfield(lastJogFeed,913);
AS3jog.Validatefield(913);
}
else
{
if(idleLed)
{
exec.Stop();
exec.Callbutton(130);
}
//last open and now open do nothing, just spam stopping
AS3.Setfield(0,232);
AS3.Validatefield(232);
AS3jog.Setfield(0,913);
AS3jog.Validatefield(913);
}
lastDoorLed = doorLed;
Thread.Sleep(40);
}
Not nice but works for testing.
Baically I'm just setting to zero all the movments speed (jog feedrate and feedrate).
I should disable the spindle start too.
It's a little bit tricky...