I had the same issue. I took the above code and modified it to the following and now it works great, thanks for the help!
' Program to automatically zero the Z-axis using a contact plate of known thickness positioned
' on top of the X-Y plane at the Z zero position. Cutting tool acts as a probe.
' Program moves the Z-axis downward at plunge speed defined by parameter "ProbeFeed" until
' the tool touches the contact plate. At this point, the Z-DRO is set to zero, adjusted for
' the thickness of the contact plate. Z-axis then retracts to the starting position.
' Last updated: 10/13/09
' Define fixed parameters
ProbeDist = "-1.0" 'Set the maximum distance to move the Z-axis before probe touches contact plate.
ProbeFeed = "10" 'Set the plunge speed for the probe
PlateThickness = 0.040
' Obtain current state values so that they can be restored upon completion.
CurrentFeed = GetOemDRO(818) ' Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) ' Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) ' Get the current G0/G1 state
If MsgBox("Ready to auto-detect z zero" & Chr(13) & Chr(13) & "Auto-height pad in place?",1) =1 Then
If GetOemLed (825)=1 Then ' Check to see if the probe is already grounded or faulty
MsgBox("Touch-Plate is grounded, check connection and try again")
Code "Z-Plate is grounded, check connection and try again" 'this goes in the status bar if aplicable
Else
StartingPoint = GetOemDRO(85) - GetOemDRO(832) ' Get starting Z position in work coordinates
Code "F" &ProbeFeed ' Set the probe plunge speed
Code "G91 G31Z" &ProbeDist ' Probing move using incremental move mode.
While IsMoving() ' Wait while it happens
Wend
ZProbePos = GetVar(2002) ' Get the axact point the probe was hit
If Val(ProbeDist)+Val(StartingPoint) >= Val(ZProbePos) Then ' No contact was made during plunge
Code "G90 G0 Z" & StartingPoint ' Go back to that point. Always a very small amount of overrun.
While IsMoving ()
Wend
Else
Call SetDro (2, PlateThickness) ' Set the Z axis DRO to whatever is set as plate thickness
Sleep 500 ' For some reason unknown to me,need this pause or retract goes to wrong place
Code "G90 G0 Z0.25" '&Retract .25 inches up ' Retract to original position
While IsMoving ()
Wend
Code "(Z axis zeroed)" ' Puts this message in the status bar
End If
End If
End If
' Reset the machine state
Code "F" &CurrentFeed ' Returns to prior feed rate
If CurrentAbsInc = 0 Then Code "G91" ' If G91 was in effect before then return to it
If CurrentGMode = 0 Then Code "G0" ' If G0 was in effect before then return to it
Exit Sub