231
Mach4 General Discussion / Re: Scripting Custom Control Panel
« on: February 02, 2021, 10:52:40 AM »
I made a pendant not a control panel but same thing for button.
Here is how I make my buttons work.
You can do a lot with these and how Lua/Mach4 function.
[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
CycleStart()
end
end,
[mc.ISIG_INPUT1] = function (state)
if (state == 1) then
mc.mcCntlRewindFile(inst)
end
end,
[mc.ISIG_INPUT2] = function (state)
if (state == 1) then
CycleStop()
end
end,
[mc.ISIG_INPUT3] = function (state)
if (state == 1) then
if (Pause == 1) then
mc.mcCntlCycleStart(inst)
Pause = 0
elseif (Pause == 0) then
mc.mcCntlFeedHold(inst)
Pause = 1
end
end
end,
[mc.ISIG_INPUT4] = function (state)
if (state == 0) then
mc.mcCntlEnable(inst, true)
else
mc.mcCntlEnable(inst, false)
end
end,
[mc.ISIG_INPUT20] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
if (state == 1) then
mc.mcRegSetValue(AltRegH, 1)
else
mc.mcRegSetValue(AltRegH, 0)
end
end,
[mc.ISIG_INPUT5] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
GoToWorkZero()
elseif (AltVal == 1) then
SetWorkZero()
end
end
end,
[mc.ISIG_INPUT6] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
ReturnToPosition()
elseif (AltVal == 1) then
RememberPosition()
end
end
end,
[mc.ISIG_INPUT7] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
wait = coroutine.create (RefAllHome)
end
end
end,
[mc.ISIG_INPUT8] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
Surface()
elseif (AltVal == 1) then
MaxDepth()
end
end
end,
[mc.ISIG_INPUT11] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
CutSpeedMinus()
elseif (AltVal == 1) then
CutSpeedPlus()
end
end
end,
[mc.ISIG_INPUT12] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
ExtraDepth()
end
end
end,
[mc.ISIG_INPUT15] = function (state)
if (state == 1) then
SpeedsReset()
end
end,
[mc.ISIG_INPUT16] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
MistOnOff()
elseif (AltVal == 1) then
SpindleOnOff()
end
end
end,
[mc.ISIG_INPUT19] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
JogSpeedMinus()
elseif (AltVal == 1) then
JogSpeedPlus()
end
end
end,
[mc.ISIG_INPUT21] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
local MachHmdreg = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
local MachHmd = mc.mcRegGetValue(MachHmdreg)
if (MachHmd == 0) then
wx.wxMessageBox("Must set Machine Home")
elseif (MachHmd == 1) then
-- mc.mcCntlGcodeExecute(inst, "m6")
mc.mcCntlMdiExecute(inst, 'm6')
end
elseif (AltVal == 1) then
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
local sigOut6 = mc.mcSignalGetState(hsig)
if (sigOut6 == 0) then
mc.mcSignalSetState(hsig, 1)
else
mc.mcSignalSetState(hsig, 0)
end
end
end
end,
[mc.ISIG_INPUT22] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
elseif (AltVal == 1) then
end
end
end,
[mc.ISIG_INPUT25] = function (state)
if (state == 1) then
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is 100(cam), 101(tks) or 102(tko) set tool to 0
if (Tool == 100) or (Tool == 101) or (Tool == 102) then
Tool = 0
end
--if tool is in range add one to tool #
if (Tool <= (ATCMaxTlsVal - 1)) then
Tool = (Tool + 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
end
end,
[mc.ISIG_INPUT26] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
local TKSReg = mc.mcRegGetHandle(inst, 'iRegs0/TKStdOnOff')
local TKSRegVal = mc.mcRegGetValue(TKSReg)
local TKOReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOscOnOff')
local TKORegVal = mc.mcRegGetValue(TKOReg)
local TKSSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
local TKOSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
local TKOscSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
local ATCOnOffReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCOnOff')
local ATCOnOffVal = mc.mcRegGetValue(ATCOnOffReg)
local ATCToolHReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCToolHolder')
local SMReg = mc.mcRegGetHandle(inst, 'iRegs0/SMOnOff')
local SMRegVal = mc.mcRegGetValue(SMReg)
mc.mcRegSetValue(TKSReg, 0)
mc.mcSignalSetState(TKSSigH, 0)
mc.mcRegSetValue(TKOReg, 0)
mc.mcSignalSetState(TKOSigH, 0)
mc.mcSignalSetState(TKOscSigH, 0)
--if atc on change current tool to tool holder tool
if (ATCOnOffVal == 1) then
local CurTool = mc.mcToolGetCurrent(inst)
local ATCToolHVal = mc.mcRegGetValue(ATCToolHReg)
if (CurTool == 100) or (CurTool == 101) or (CurTool == 102) then
mc.mcToolSetCurrent(inst, ATCToolHVal)
mc.mcCntlGcodeExecuteWait(inst, string.format("G43 H" .. tostring(ATCToolHVal)))
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_X, 0.000)
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, 0.000)
end
end
--turn off tang knife mode
mc.mcCntlSetParameter(502, 0)
mc.mcCntlSetLastError(inst, 'TK OFF')
if (SMTempOn == 1) then
mc.mcRegSetValue(SMReg, 1)
SMTempOn = 0
end
--mc.mcRegSetValue(TKSReg, TKSRegVal)
KeyTKSTemp = 0
--mc.mcRegSetValue(TKOReg, TKORegVal)
KeyTKOTemp = 0
end
end
end,
[mc.ISIG_INPUT27] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
KeyTKSTemp = 1
TKSOnOff()
end
end
end,
[mc.ISIG_INPUT28] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
KeyTKOTemp = 1
TKOOnOff()
end
end
end,
[mc.ISIG_INPUT29] = function (state)
if (state == 1) then
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is 100(cam), 101(tks) or 102(tko) set tool to MaxTool
if (Tool == 100) or (Tool == 101) or (Tool == 102) then
Tool = (ATCMaxTlsVal + 1)
end
--if tool is in range subtract one from tool #
if (Tool >= 2) then
Tool = (Tool - 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
end
end,
[mc.ISIG_INPUT30] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
elseif (AltVal == 1) then
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
local sigOut5 = mc.mcSignalGetState(hsig)
if (sigOut5 == 0) then
mc.mcSignalSetState(hsig, 1)
else
mc.mcSignalSetState(hsig, 0)
end
end
end
end,
[mc.ISIG_INPUT31] = function (state)
if (state == 1) then
wait = coroutine.create (RefTKHome)
end
end,
[mc.ISIG_INPUT32] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
local Sig9H = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
local Sig9Val = mc.mcSignalGetState(Sig9H)
if (state == 1) then
if (AltVal == 1) then
if (Sig9Val == 0) then
mc.mcSignalSetState(Sig9H, 1)
--wx.wxMilliSleep(1000)
else
mc.mcSignalSetState(Sig9H, 0)
--wx.wxMilliSleep(1000)
end
end
end
end,
Here is how I make my buttons work.
You can do a lot with these and how Lua/Mach4 function.
[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
CycleStart()
end
end,
[mc.ISIG_INPUT1] = function (state)
if (state == 1) then
mc.mcCntlRewindFile(inst)
end
end,
[mc.ISIG_INPUT2] = function (state)
if (state == 1) then
CycleStop()
end
end,
[mc.ISIG_INPUT3] = function (state)
if (state == 1) then
if (Pause == 1) then
mc.mcCntlCycleStart(inst)
Pause = 0
elseif (Pause == 0) then
mc.mcCntlFeedHold(inst)
Pause = 1
end
end
end,
[mc.ISIG_INPUT4] = function (state)
if (state == 0) then
mc.mcCntlEnable(inst, true)
else
mc.mcCntlEnable(inst, false)
end
end,
[mc.ISIG_INPUT20] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
if (state == 1) then
mc.mcRegSetValue(AltRegH, 1)
else
mc.mcRegSetValue(AltRegH, 0)
end
end,
[mc.ISIG_INPUT5] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
GoToWorkZero()
elseif (AltVal == 1) then
SetWorkZero()
end
end
end,
[mc.ISIG_INPUT6] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
ReturnToPosition()
elseif (AltVal == 1) then
RememberPosition()
end
end
end,
[mc.ISIG_INPUT7] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
wait = coroutine.create (RefAllHome)
end
end
end,
[mc.ISIG_INPUT8] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
Surface()
elseif (AltVal == 1) then
MaxDepth()
end
end
end,
[mc.ISIG_INPUT11] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
CutSpeedMinus()
elseif (AltVal == 1) then
CutSpeedPlus()
end
end
end,
[mc.ISIG_INPUT12] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
ExtraDepth()
end
end
end,
[mc.ISIG_INPUT15] = function (state)
if (state == 1) then
SpeedsReset()
end
end,
[mc.ISIG_INPUT16] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
MistOnOff()
elseif (AltVal == 1) then
SpindleOnOff()
end
end
end,
[mc.ISIG_INPUT19] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
JogSpeedMinus()
elseif (AltVal == 1) then
JogSpeedPlus()
end
end
end,
[mc.ISIG_INPUT21] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
local MachHmdreg = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
local MachHmd = mc.mcRegGetValue(MachHmdreg)
if (MachHmd == 0) then
wx.wxMessageBox("Must set Machine Home")
elseif (MachHmd == 1) then
-- mc.mcCntlGcodeExecute(inst, "m6")
mc.mcCntlMdiExecute(inst, 'm6')
end
elseif (AltVal == 1) then
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
local sigOut6 = mc.mcSignalGetState(hsig)
if (sigOut6 == 0) then
mc.mcSignalSetState(hsig, 1)
else
mc.mcSignalSetState(hsig, 0)
end
end
end
end,
[mc.ISIG_INPUT22] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
elseif (AltVal == 1) then
end
end
end,
[mc.ISIG_INPUT25] = function (state)
if (state == 1) then
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is 100(cam), 101(tks) or 102(tko) set tool to 0
if (Tool == 100) or (Tool == 101) or (Tool == 102) then
Tool = 0
end
--if tool is in range add one to tool #
if (Tool <= (ATCMaxTlsVal - 1)) then
Tool = (Tool + 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
end
end,
[mc.ISIG_INPUT26] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
local TKSReg = mc.mcRegGetHandle(inst, 'iRegs0/TKStdOnOff')
local TKSRegVal = mc.mcRegGetValue(TKSReg)
local TKOReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOscOnOff')
local TKORegVal = mc.mcRegGetValue(TKOReg)
local TKSSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
local TKOSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
local TKOscSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
local ATCOnOffReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCOnOff')
local ATCOnOffVal = mc.mcRegGetValue(ATCOnOffReg)
local ATCToolHReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCToolHolder')
local SMReg = mc.mcRegGetHandle(inst, 'iRegs0/SMOnOff')
local SMRegVal = mc.mcRegGetValue(SMReg)
mc.mcRegSetValue(TKSReg, 0)
mc.mcSignalSetState(TKSSigH, 0)
mc.mcRegSetValue(TKOReg, 0)
mc.mcSignalSetState(TKOSigH, 0)
mc.mcSignalSetState(TKOscSigH, 0)
--if atc on change current tool to tool holder tool
if (ATCOnOffVal == 1) then
local CurTool = mc.mcToolGetCurrent(inst)
local ATCToolHVal = mc.mcRegGetValue(ATCToolHReg)
if (CurTool == 100) or (CurTool == 101) or (CurTool == 102) then
mc.mcToolSetCurrent(inst, ATCToolHVal)
mc.mcCntlGcodeExecuteWait(inst, string.format("G43 H" .. tostring(ATCToolHVal)))
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_X, 0.000)
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, 0.000)
end
end
--turn off tang knife mode
mc.mcCntlSetParameter(502, 0)
mc.mcCntlSetLastError(inst, 'TK OFF')
if (SMTempOn == 1) then
mc.mcRegSetValue(SMReg, 1)
SMTempOn = 0
end
--mc.mcRegSetValue(TKSReg, TKSRegVal)
KeyTKSTemp = 0
--mc.mcRegSetValue(TKOReg, TKORegVal)
KeyTKOTemp = 0
end
end
end,
[mc.ISIG_INPUT27] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
KeyTKSTemp = 1
TKSOnOff()
end
end
end,
[mc.ISIG_INPUT28] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 1) then
KeyTKOTemp = 1
TKOOnOff()
end
end
end,
[mc.ISIG_INPUT29] = function (state)
if (state == 1) then
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is 100(cam), 101(tks) or 102(tko) set tool to MaxTool
if (Tool == 100) or (Tool == 101) or (Tool == 102) then
Tool = (ATCMaxTlsVal + 1)
end
--if tool is in range subtract one from tool #
if (Tool >= 2) then
Tool = (Tool - 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
end
end,
[mc.ISIG_INPUT30] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if (AltVal == 0) then
elseif (AltVal == 1) then
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
local sigOut5 = mc.mcSignalGetState(hsig)
if (sigOut5 == 0) then
mc.mcSignalSetState(hsig, 1)
else
mc.mcSignalSetState(hsig, 0)
end
end
end
end,
[mc.ISIG_INPUT31] = function (state)
if (state == 1) then
wait = coroutine.create (RefTKHome)
end
end,
[mc.ISIG_INPUT32] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
local Sig9H = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
local Sig9Val = mc.mcSignalGetState(Sig9H)
if (state == 1) then
if (AltVal == 1) then
if (Sig9Val == 0) then
mc.mcSignalSetState(Sig9H, 1)
--wx.wxMilliSleep(1000)
else
mc.mcSignalSetState(Sig9H, 0)
--wx.wxMilliSleep(1000)
end
end
end
end,