; This demonstrates doing an M6 remapped to a named oword sub ; ; to activate, incantate as follows in the ini file: ; ; [RS274NGC] ; # remap M6 to a named oword subroutine. ; M6_COMMAND=ocall ; ; parameter #1: the current tool-in-spindle ; parameter #2: the tool number requested in the last T (prepare) command ; parameter #3: pocket of new tool ; ; ; O sub ; (DEBUG, executing M6 O-word sub, tool-in-spindle=#1 prepared=#2 pocket=#3) ; M66 P2 L0 ;(debug, digital-input-02=#5399) # = 0 # = 0 # = 0 ; number of seconds to wait for 'tool-changed' equivalent # = 9999 ; O if [# EQ 0] M5 O endif O if [# NE 0] G0 G53 Z0 O endif O if [# NE 0] G30 O endif ; set analog output pin #2 to signal the pocket number ; iocontrol.tool-number becomes motion.analog-out-02 M68 E2 Q[#2] ;(DEBUG, set current tool number on motion.analog-out-02: #2) ; ; assert the equivalent of the iocontrol.tool-change pin ; which is now motion.digital-out-01 M64 P1 ;(DEBUG, motion.digital-out-01 set high, waiting for motion.digital-in-01) ; wait for the equivalent of the iocontrol.tool-changed pin to go high ; we use motion.digital-in-01 ; M66 P1 L3 Q# ; ; if we waited too long, fail change and abort. ; O if [#5399 EQ -1] (DEBUG, timeout waiting for digital-in-01 to become true - failing change ) O return [-1] O endif ; retract iocontrol.tool-change equivalent ;(DEBUG, deasserting motion.digital-out-01) M65 P1 ; ; test fail-change line from gladevcp M66 P2 L0 ; (debug, digital-input-02=#5399) O if [#5399 EQ 1] (DEBUG, returning -1 to fail change) O return [-1] O else (debug, change ok, returning +1 to commit change) ; a positive return value commits the tool change O return [1] O endif ; ; return a positive value commit the change. ; a negative return value will fail the change and ; abort the interpreter with a message like ; "M6 failed ()" ; O endsub m2