dooembutton (1003)
sleep(300)
Activatesignal (OUTPUT6)
Code "g90 g53 g0 x2.2655 y10.7739"
While IsMoving ()
Wend
If getOemled (28)=0 Then
	Dooembutton (136)
	End If

If GetOemLed (825)<>0 Then 'Check to see if the probe is already grounded or faulty
	Call ProbeGrounded()
	Exit Sub
Else
        CurrentToolDiameter = GetOemDRO(43) 'gets the current tool diameter
	toolnew = CurrentToolDiameter /2
	Code "g54 g1 f10 z1.0"
	While IsMoving ()
	Wend
	Code "G91 x" &toolnew
	While IsMoving ()
	Wend
	DeActivateSignal(OUTPUT5)
sleep(1000)
Spin = 300

 If Spin < 450 Then
   Call gear
   End If

 

	Code "G4 P2" ' this delay gives me time to get from computer to hold probe in place
	Code "G90 G31 Z-2 F5" 'probing move, can set the feed rate here as well as how far to move
	'Code "G31 Z-1.0 F5" 'Z goes down a max of 1.0 at 5IPM
	
	While IsMoving() 'wait while it happens
	Wend
	Code "g91 g1 f20 z.1"
	Code "G90 G31 Z-2 F5"
	While IsMoving ()
	Wend
	Z_Offset = GetOEMDRO ( 49 )
	Axis_Pos = GetOEMDRO(85)
	Tool_Offset = Axis_Pos - Z_Offset  
	Call setOEMDRO(42, Tool_Offset)
	Code "g91 g1 f20 z.1"
	While IsMoving ()
	Wend
	
Rem Probe Left

    	toolz = GetOEMDRO(1500)+.100
	code "g91 x1.0"
	code "g91 z"&-toolz
    	Code "g91 G31 f5 X-2"
	While IsMoving ()
	Wend
	code "g91 f20 x.1"
	code "g91 f5 g31 x-.2"
    	While IsMoving() 'wait for the move to finish
    	Wend
    	XPos1 = GetVar(2000) 'get the probe touch location
	code "g91 f20 x.1"
	While IsMoving ()
	Wend
    	Code "G91 G1 f4 Z"&toolz
	While IsMoving ()
	Wend
    

Rem Probe Right
	toolclear = CurrentToolDiameter+1.0

    	code "g91 f20 x"&-toolclear
	While IsMoving ()
	Wend
	code "g91 z"&-toolz
	While IsMoving ()
	Wend

    	Code "g91 G31 f5 X2"
	While IsMoving ()
	Wend
	code "g91 f20 x-.1"
	code "g91 f5 g31 x.2"
    	While IsMoving() 'wait for the move to finish
    	Wend
    XPos2 = GetVar(2000)
	code "g91 f20 x-.1"
    	Code "G91 G0 Z"&toolz
   	While IsMoving ()
   	 Wend
  	newdia= (XPos1 - XPos2)-.500
	Call setOEMDRO(43, newdia)
    	Code "g90 g54 G0 Z3.0" 'put the Z retract height you want here
	While IsMoving ()
	Wend
	Code "g90 M5"
	DeactivateSignal (output6)
	doOembutton (136)
End If


Sub gear
   
   pulley = getOemdro(56)
 If pulley = 1 Then
   Call lowgear
   End If
 If pulley = 2 Then
   Call gearchange
   End If
   End Sub



Sub gearchange

  
  setpulley (1)
  Dim Msg, Style, Title, Help, Ctxt, Response,MyString
Msg = "Please Change To Low Gear " 
Style = vbYesNo + vbCritical + vbDefaultButton2   ' Define buttons 
Style = 0 + 48 + 0   ' Define buttons. 
Title = "Gear Change Requested"   ' Define title 
Help = "DEMO.HLP"   ' Define Help file 
Ctxt = 1000   ' Define topic       
 'context.        
 ' Display message. 
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
 If Response = vbOk Then   ' User chose Ok    
MyString = "Ok"   ' Perform some action 
End If

  Call Lowgear
  End Sub
   


Sub LowGear
 
   DoSpinCW()
   Message "Low gear active"
   
 End Sub

   

Sub ProbeGrounded()
	Code "(Probe plate is grounded, check connection and try again)"
End Sub   

 
   

    

