CNC4PC Pendant for Mach4 with C22M1

Used software: Mach4 4.2.0.4612, PLUGINS ESS V275

Used hardware: C82 R4 and C22M1 R1.

 

STEP 1: On many systems, MS Windows can recognize the USB drivers, but if not, you can download them from here: https://www.cnc4pc.com/pub/media/productattachments/files/Driver_FT232_USB_UART.zip 

STEP 2: Connect the C22M1 to the USB port, Right Click on the USB Serial port, Select Update Driver Software.

 

STEP 3: 

STEP 4: 

 

 

STEP 5: Configure/Control/Plugins

STEP 6: Configure/Plugins/Modbus

 

 

STEP 7: CONFIGURING THE CONTROL SOFTWARE: To configure use the following sample configuration screen:   

           

 

STEP 8: Add Modbus Function  

 

STEP 9: To configure Encoder use the following sample configuration screen: 

   

 

Mach4 configure

STEP 10 : Configure/Controller/Input Signal

STEP 11 : Configure/Controler/Output Signal

 

STEP 12 : Configure/Controler/MPGs

STEP 13 : You can download, install, and use this screen:

https://www.cnc4pc.com/pub/media/productattachments/files/wx6_mpg.zip 

Or you can edit the screen manually by adding the Lua code as explained below.

 

STEP 13: Copy the following code at the end of the screen script  

--------------------------------------
-- 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)

 

STEP 14 : Copy on PLC First Run  

 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

 

STEP 15: Copy to end of PLC Run

 

--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

 

STEP 16: Exit and save the screen and it will be ready.