For some reason Mach3 G31 is not working as intended. This seems to be true when using G31 in a macro but I have it working when I run a GCoce program. I was fighting a strange problem for a while, the program would appear to work correctly for a hand held touchpad, but not for a rigidly mounted touchpad. My problem had to do with my system configuration.
The problem was that Mach3 stops moving and reads the Z distance into location 2002 when the probe makes contact and then breaks contact instead of when contact is made. In other words it was triggering on the positive going edge of a negative pulse if that makes sense. For a handheld touchpad it would make and break contact quite easily, but a rigid touchpad would only make contact, and if driven further the probe makes better contact, hence no positive edge.
First let me describr how I have my system configured. I am using a Galil DMC-1750 Optima motion controller with the Galil 4.6 plugin to interface Mach3 to the Optima controller. This is connected to servo motor amplifiers driving servo motors on 4 axes. The Optima board contains a powerful processor that handles all limit switches, timing, pulse generation, moves, acceleration, etc. All the PC needs to do is translate Gcode into a text code Galil can understand and display the encoder positions. This eliminates the problems with Windows and anemic PC's. In fact I am running my system with Windows 2000 on an ancient PC, largely because it has an ISA bus slot for the Optima board. The PC is so old it will not accept Windows XP or newer.
In the Optima board there exists a high speed latch circuit that applies a 5 volt signal through a 10K resistor to my touchpad. When a G31 is initiated, the Galil plugin arms the latch, and when the moving grounded probe makes contact it senses either a positive or negative edge, depending on configuration. When the edge is detected the Optima board reads the encoder position and reports this to Mach3 through the Galil plugin, storing the value in Var Address 2002.

Both Mach3 and the Optima board have configuration routines, that need to be done separately.. I had the Optima board set for active high and Mach3 set for active low which explained the edge trigger problem. Now I have the Optima board set for Active Low. For some reason I need to configure Mach3 Probe Active High and assign it to Com 1 pin 27 to function with the Galil Plugin.

This seems to cause problems with using Macros for Auto Tool Zero. When running a macro with Active High configuration, the Digitize LED is off before the probe touches the pad, but the probe never moves negative toward the pad. It just sets zero in the starting location and completes the macro as if it actually worked.
Setting Probe to Active low turns op the Digitize LED prior to prior to movement, and the macro fails on this line of code
If GetOemLED (825) = 0 Then
since the value returned is not zero. Changing the command to
If GetOemLED (825) <> 0 Then
dies not work, it causes a strange error.

Running from GCode like a normal program does work with Probe Active High using this code. It does require some operator intervention to zero the Z axis before and after touching the pad. I do not know how to send a GCode command to perform that task. I start with my end mill (the probe) about 1/2 inch above my vice jaws. The touchpad is close to the same height as the vice jaws, and after running the Auto Zero Tool Z program, I run a simple macro set up on the Auto Zero Tool button to compensate for this small error of about 0.010".

%
(Auto Zero Tool Z)

G20 G40 G49 G54 G80 G90 G91.1
G1 X 8.5 Y -1.5;move to touch pad

(zero Z DRO, Click cycle start to continue)
M0

G31 Z-1 F4

#100=#2002;get exact contact point
G1 Z [#100] F.1

(zero Z DRO, Click cycle start to continue)
M0
Z1 F20;raise tool
M30
%

Macro on Auto Tool Zero button

Message "(Compensating for Z-Height)"

Call SetDRO (2, 0.490) 'Probe is at Z=0.500, set actual value here
Sleep 200 'Pause to allow DRO to update