222
« on: December 27, 2018, 06:11:57 PM »
Here's some code for you! You'll need to setup your inputs in your device settings and Mach4 settings then code like this goes in the Screen Start script in the Signal Library section. I included ALL of mine, but it should give you a clue where to start. There's coolant/mist, spindle on, setting speed to 1000 (Mach4 doesn't remember the last speed when shut down so this is a work around for me trying to start the spindle with no speed set!!!) It's commented so you should be able to figure some stuff out for the basics.
Tom
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
machEnabled = state;
ButtonEnable()
end,
-- PoKeys pin 9, Mach4 Input 0
-- Physical Cycle Start Button
[mc.ISIG_INPUT0] = function (state)
if (state == 0) then
CycleStart()
end
end,
-- PoKeys pin 10, Mach4 Input 1
-- Physical Feed Hold Button
[mc.ISIG_INPUT1] = function (state)
if (state == 1) then
mc.mcCntlFeedHold (0)
end
end,
-- PoKeys pin 11, Mach4 Input 2
-- Physical Stop Button
[mc.ISIG_INPUT2] = function (state)
if (state == 1) then
CycleStop()
end
end,
--PMDX-108 Port 2 Pin 6 Mach4 Input 10
--HLFB_X ERROR
[mc.ISIG_INPUT10]= function(state)
if (state==1) then
mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "HLFB_X Servo Error")
end
end,
--PMDX-108 Port 2 Pin 7 Mach4 Input 11
--HLFB_Y ERROR
[mc.ISIG_INPUT11]= function(state)
if (state==1) then
mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "HLFB_Y Servo Error")
end
end,
--PMDX-108 Port 2 Pin 8 Mach4 Input 12
--HLFB_A ERROR
[mc.ISIG_INPUT12]= function(state)
if (state==1) then
mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "HLFB_A Servo Error")
end
end,
--PMDX-108 Port 2 Pin 9 Mach4 Input 13
--HLFB_Z ERROR
[mc.ISIG_INPUT13]= function(state)
if (state==1) then
mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "HLFB_Z Servo Error")
end
end,
----------Mach4 Input 17 PoKeys Pin 17-----
----------Toggle Coolant M8----------------
[mc.ISIG_INPUT17] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 0) then
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,1)
mc.mcCntlSetLastError(inst, "Coolant On")
else
local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
mc.mcSignalSetState(OSigCool,0)
mc.mcCntlSetLastError(inst, "Coolant Off")
end
end
end,
----------Mach4 Input 14 PoKeys Pin 14--
----------Toggle Mist M7----------------
[mc.ISIG_INPUT14] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 0) then
local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
mc.mcSignalSetState(OSigMist,1)
mc.mcCntlSetLastError(inst, "Mist On")
else
local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
mc.mcSignalSetState(OSigMist,0)
mc.mcCntlSetLastError(inst, "Mist Off")
end
end
end,
------------Mach4 Input 8 PoKeys Pin 8----------------
------------Toggle SpinCW-----------------------------
[mc.ISIG_INPUT8] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then
mc.mcSpindleSetDirection(inst, 0);
else
SpinCW()
end
end
end,
------------Mach4 Input 7 PoKeys Pin 7------------
------------Set S1000-----------------------------
[mc.ISIG_INPUT7] = function (state)
if (state == 1) then
mc.mcCntlGcodeExecuteWait(inst, "S1000");
mc.mcCntlSetLastError(inst, 'Speed Set to 1000')
else
--mc.mcCntlFeedHold (0)
end
end,
--sample input use that was originally in here!!
[mc.ISIG_INPUT60] = function (state)
-- if (state == 1) then
-- CycleStart()
-- --else
-- --mc.mcCntlFeedHold (0)
-- end
end,