//------------------ versione 2.1 -------------------------------------------
double SafeZ = -5;
while (AS3.Getbuttonstate (128))
{
	if (exec.GetZpos()<-1 && !callCycleStart)
	{
		int counter = 0;

		for (int i =0; i<10; i++)
		{
			if (AS3.GetLED (13))
			{
			}
else			
			{
				counter ++;
				exec.AddStatusmessage (Convert.ToString (counter));
			}
		}

		if (counter > 5)
		{
			if (!callCycleStart)
			{				
				exec.Callbutton (130);
					new Thread(delegate () {
    				MoveZUp ();
				}).Start();			

				callCycleStart = true;


				
			}
			
		}
	}
}

callCycleStart = false;

#Events

static bool callCycleStart = false;


private void MoveZUp ()
{
	while (AS3.GetLED (54));
	Thread.Sleep (50);
	//MessageBox.Show ("Punta rotta");
		exec.Callbutton (20500);
	MessageBox.Show ("PUNTA ROTTA, sostituire utensile, accendere il mandrino e premere CYCLE START.", "ATTENZIONE!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);



}