CNC4PC Pendant for Mach4 with C22M1
Used software: Mach4 4.2.0.4612, PLUGINS ESS V275
Used hardware: C82 R4 and C22M1 R1.
Mach4 configure
--------------------------------------
-- CNC4PC Pendant --
--------------------------------------
-- These simply run the CNC4PCPendant function if their state changes.
SigLib = {
[mc.ISIG_INPUT10] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT11] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT12] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT13] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT14] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT15] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT16] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT17] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT18] = function (state)
CNC4PCPendant()
end,
[mc.ISIG_INPUT19] = function (state)
CNC4PCPendant()
end
}
---------------------------------------------------------------
-- CNC4PC Pendant function.
---------------------------------------------------------------
function CNC4PCPendant()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10) -- Is mapped to Port 2 Pin 4 *X Selection
local XSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11) -- Is mapped to Port 2 Pin 5 *Y Selection
local YSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12) -- Is mapped to Port 2 Pin 6 *Z Selection
local ZSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13) -- Is mapped to Port 2 Pin 7 *A Selection
local ASelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14) -- Is mapped to Port 2 Pin 8 *.001 Selection
local Step001, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15) -- Is mapped to Port 2 Pin 9 *.010 Selection
local Step010, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16) -- Is mapped to Port 2 Pin 10 *.100 Selection
local Step100, rc = mc.mcSignalGetState(hSig)
local inst = mc.mcGetInstance()
local hregEncoderInit = mc.mcRegGetHandle(inst, "C22M1/Encoder0")
local EncoderInit = mc.mcRegGetValue(hregEncoderInit) --get value from pendant Encoder Register
local Init_EncoderPos = EncoderInit
last_EncoderPos = Init_EncoderPos
--This section for moving selected axis based on MPG register changes
--local inst = mc.mcGetInstance()
local inst = mc.mcGetInstance()
local hregEncoder = mc.mcRegGetHandle(inst, "C22M1/Encoder0")
local Encoder = mc.mcRegGetValue(hregEncoder) --get value from pendant Encoder Register
local inc_pos = (last_EncoderPos - Encoder); --Calculate the inc position of the axis
mc.mcMpgMoveCounts(inst, 0, inc_pos) --move the number of counts
last_EncoderPos = Encoder