If you start LinuxCNC and look in the sample configs:
sim/axis/remap/manual-toolchange-with-tool-length-switch
You will find a simulated config that does what you want.
You should just need to copy the nc_subroutines and python folders from that configuration to your configuration and then add the relevant section to your INI file:
Code:
[RS274NGC]
...
SUBROUTINE_PATH = nc_subroutines:../../nc_files/remap_lib/common_nc_subs
...
ON_ABORT_COMMAND=O <on_abort> call
#
# ------ remapping toolchange - related codes ----------------------
#
# see python/remap.py for the prolog and epilog handlers
# see nc_files/remap-subroutines for the NGC procedures
#
# the prepare_min.ngc and change_min.ngc are templates - fill in as needed
REMAP=M6 modalgroup=6 prolog=change_prolog ngc=manual_change epilog=change_epilog
(edit} And connect your tool-length switch to motion.probe-input