double startPosX = 0;
double startPosY = 0;
double probingBackDistance = 1;
double maxProbeLenght = 10;
double probeAvstandMellanProbning = 0.25;

//exec.Code("M40"); //Starta digitizing
//exec.Code("G90 G0 X" + startPosX + " Y" + (startPosY + probingBackDistance));

while(exec.IsMoving()){}

/*
current 10
max 10
10 - 10 = 0

*/
while(true)
{	
	double currentPos = exec.GetYpos();
	double probelenght = currentPos - maxProbeLenght;
	AS3.Additemtolist("Probelength = " + probelenght,2);
	exec.Code("G90 G31 Y" + probelenght + " F300");
	while(exec.IsMoving()){}
	
	double currentPos2 = exec.GetYpos() - 0.2;
	AS3.Additemtolist("Slutposprobning = " + currentPos2,2);
	if ((currentPos2) <= probelenght)
	{
		MessageBox.Show("Probning maxlangd overskriden");
		return;
	}
	//double currentPosForBakMove = AS3.Getfielddouble(227); //226 = X, 227 = Y
	//Double bakmove = currentPosForBakMove + probingBackDistance;
	exec.Code("G91 G0 X" + probeAvstandMellanProbning + " Y" + probingBackDistance);
	while(exec.IsMoving()){}
	
	if (AS3.GetLED(37)) {break;}
	if(exec.Ismacrostopped()){return;}
	

}
return;
exec.Code("G91 G0 X-" + probingBackDistance);
while(exec.IsMoving()){}

while(true)
{
	double currentPos = AS3.Getfielddouble(226); //226 = X, 227 = Y
	exec.Code("G90 G31 X" + (currentPos + maxProbeLenght) + " F300");
	while(exec.IsMoving()){}
	exec.Code("G91 G0 X-" + probingBackDistance + " Y" + probeAvstandMellanProbning);
	while(exec.IsMoving()){}
	if (AS3.GetLED(37)) {break;}
	if(exec.Ismacrostopped()){return;}
}

exec.Code("G91 G0 Y-" + probingBackDistance);
while(exec.IsMoving()){}

while(true)
{	
	double currentPos = AS3.Getfielddouble(227); //226 = X, 227 = Y
	exec.Code("G90 G31 Y" + (currentPos + maxProbeLenght) + " F300");
	while(exec.IsMoving()){}
	exec.Code("G91 G0 X-" + probeAvstandMellanProbning + " Y-" + probingBackDistance);
	while(exec.IsMoving()){}
	if (AS3.GetLED(37)) {break;}
	if(exec.Ismacrostopped()){return;}
	
}

//exec.Code("M41"); //Avsluta digitizing