------------------------------------------------------- -- Screen Load Script ------------------------------------------------------- pageId = 0 screenId = 0 testcount = 0 machState = 0 machStateOld = -1 machEnabled = 0 machWasEnabled = 0 inst = mc.mcGetInstance() --------------------------------------------------------------- -- Signal Library --------------------------------------------------------------- SigLib = { [mc.OSIG_MACHINE_ENABLED] = function (state) machEnabled = state; scr.SetProperty('btnRefAll', 'Enabled', tostring(state)); scr.SetProperty('btnRefAll2', 'Enabled', tostring(state)); scr.SetProperty('btnGotoZero', 'Enabled', tostring(state)); scr.SetProperty('tabJogging', 'Enabled', tostring(state)); if (state == 1) then AxisEnable(); end end, --Enable Console Switches, uses mach inputs 0 through 31 from modbus [mc.ISIG_INPUT0] = function (on_off) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcCntlEnable (inst, 1) end end, [mc.ISIG_INPUT1] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcAxisHomeAll(inst, 1) else mc.mcAxisHomeAll(inst, 0) end end, [mc.ISIG_INPUT2] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then; mc.mcCntlCycleStart (inst, 1); --mc.mcCntlMdiExecute (inst, 1); end end, [mc.ISIG_INPUT3] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcCntlFeedHold (inst, 1) end end, [mc.ISIG_INPUT4] = function (state) end, [mc.ISIG_INPUT5] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcCntlSetSingleBlock (inst, 1) else mc.mcCntlSetSingleBlock (inst, 0) end end, [mc.ISIG_INPUT6] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT6); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcCntlSetOptionalStop (inst, 1) else mc.mcCntlSetOptionalStop (inst, 0) end end, [mc.ISIG_INPUT7] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT7); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcCntlSetBlockDelete (inst, 1, true) else mc.mcCntlSetBlockDelete (inst, 1, false) end end, [mc.ISIG_INPUT8] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT8); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcSpindleSetDirection (inst, 1) end end, [mc.ISIG_INPUT9] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT9); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcSpindleSetDirection (inst, 0) end end, [mc.ISIG_INPUT10] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcSpindleSetDirection (inst, -1) end end, [mc.ISIG_INPUT11] = function (state) --used in mach input list for limit override end, [mc.ISIG_INPUT12] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcSpindleSetRange (inst, 0) end end, [mc.ISIG_INPUT13] = function (state) hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13); SigState = mc.mcSignalGetState(hsig); if SigState == 1 then mc.mcSpindleSetRange (inst, 1) end end, [mc.ISIG_INPUT14] = function (state) --Jog switch pin14 end, [mc.ISIG_INPUT15] = function (state) --Jog switch pin15 end, [mc.ISIG_INPUT16] = function (state) --hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16); --SigState = mc.mcSignalGetState(hsig); --if SigState == 1 then --OSIG_COOLANTON --end end, [mc.ISIG_INPUT17] = function (state) --Jog switch pin17 end, [mc.ISIG_INPUT18] = function (state) RRO() --Rapid Rate switch pin 18 end, [mc.ISIG_INPUT19] = function (state) RRO() --Rapid Rate switch pin 19 --hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT19); --SigState = mc.mcSignalGetState(hsig); --if SigState == 1 then --mc.mcCntlSetRRO (inst, 0) --end end, [mc.ISIG_INPUT20] = function (state) RRO() --Rapid Rate switch pin 20 end, [mc.ISIG_INPUT21] = function (state) end, [mc.ISIG_INPUT22] = function (state) end, [mc.ISIG_INPUT23] = function (state) end, [mc.ISIG_INPUT24] = function (state) end, [mc.ISIG_INPUT25] = function (state) end, [mc.ISIG_INPUT26] = function (state) --hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT26); --SigState = mc.mcSignalGetState(hsig); --if SigState == 1 then --OSIG_MISTTON --end end, [mc.ISIG_INPUT27] = function (state) end, [mc.ISIG_INPUT28] = function (state) end, [mc.ISIG_INPUT29] = function (state) end, [mc.ISIG_INPUT30] = function (state) end, [mc.ISIG_INPUT31] = function (state) end, [mc.OSIG_JOG_CONT] = function (state) if( state == 1) then scr.SetProperty('labJogMode', 'Label', 'Continuous'); scr.SetProperty('txtJogInc', 'Bg Color', '#C0C0C0');--Light Grey scr.SetProperty('txtJogInc', 'Fg Color', '#808080');--Dark Grey end end, [mc.OSIG_JOG_INC] = function (state) if( state == 1) then scr.SetProperty('labJogMode', 'Label', 'Incremental'); scr.SetProperty('txtJogInc', 'Bg Color', '#FFFFFF');--White scr.SetProperty('txtJogInc', 'Fg Color', '#000000');--Black end end, [mc.OSIG_JOG_MPG] = function (state) if( state == 1) then scr.SetProperty('labJogMode', 'Label', ''); scr.SetProperty('txtJogInc', 'Bg Color', '#C0C0C0');--Light Grey scr.SetProperty('txtJogInc', 'Fg Color', '#808080');--Dark Grey --add the bits to grey jog buttons becasue buttons can't be MPGs end end, --M6 messagebox [mc.OSIG_TOOL_CHANGE] = function (state) if( state == 1) then mm.ToolChangeMsg("A tool change has been requested via M6. Change your tool then press Cycle Start to continue!", "Tool Change Active!") end end } --Set Jogtype and jog increment from console switch local Input14 = 0 --Clear local Input14 local Input15 = 0 --Clear local Input15 local Input17 = 0 --Clear local Input17 local hSig = 0 --Clear local hSig hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14) Input14 = mc.mcSignalGetState(hSig) hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15) Input15 = mc.mcSignalGetState(hSig) hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17) Input17 = mc.mcSignalGetState(hSig) if ((Input14 == 1) and (Input15 == 1) and (Input17 == 1)) then local inst = mc.mcGetInstance(); --Jog Cont mc.mcJogSetType(inst, mc.X_AXIS, mc.MC_JOG_TYPE_VEL) mc.mcJogSetType(inst, mc.Y_AXIS, mc.MC_JOG_TYPE_VEL) mc.mcJogSetType(inst, mc.Z_AXIS, mc.MC_JOG_TYPE_VEL) mc.mcJogSetType(inst, mc.A_AXIS, mc.MC_JOG_TYPE_VEL) end if ((Input14 == 0) and (Input15 == 1) and (Input17 == 1)) then local inst = mc.mcGetInstance(); --Jog Incr mc.mcJogSetType(inst, mc.X_AXIS, mc.MC_JOG_TYPE_INC) mc.mcJogSetType(inst, mc.Y_AXIS, mc.MC_JOG_TYPE_INC) mc.mcJogSetType(inst, mc.Z_AXIS, mc.MC_JOG_TYPE_INC) mc.mcJogSetType(inst, mc.A_AXIS, mc.MC_JOG_TYPE_INC) end if ((Input14 == 1) and (Input15 == 1) and (Input17 == 0)) then local inst = mc.mcGetInstance() mc.mcJogSetInc(inst, 0, 0.0001) end if ((Input14 == 0) and (Input15 == 1) and (Input17 == 0)) then local inst = mc.mcGetInstance() mc.mcJogSetInc(inst, 0, 0.001) end if ((Input14 == 1) and (Input15 == 0) and (Input17 == 1)) then local inst = mc.mcGetInstance() mc.mcJogSetInc(inst, 0, 0.01) end if ((Input14 == 0) and (Input15 == 0) and (Input17 == 1)) then local inst = mc.mcGetInstance() mc.mcJogSetInc(inst, 0, 0.1) end if ((Input14 == 1) and (Input15 == 0) and (Input17 == 0)) then local inst = mc.mcGetInstance() mc.mcJogSetInc(inst, 0, 1.000) end function RRO() --Set Rapid Over Ride Value, 0%, 25%, 50% and 100% local Input18 = 0 --Clear local Input18 local Input19 = 0 --Clear local Input19 local Input20 = 0 --Clear local Input20 local hSig = 0 --Clear local hSig --local inst = mc.mcGetInstance() local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18) Input18 = mc.mcSignalGetState(hSig) --Get state of input 18 local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT19) Input19 = mc.mcSignalGetState(hSig) --Get state of input 19 local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) Input20 = mc.mcSignalGetState(hSig) --Get state of input 20 if ((Input18 == 0) and (Input19 == 1) and (Input20 == 0)) then mc.mcCntlSetRRO(inst, 100.0) --Set RRO to 100% elseif ((Input18 == 1) and (Input19 == 0) and (Input20 == 1)) then mc.mcCntlSetRRO(inst, 50.0) --Set RRO to 50% elseif ((Input18 == 0) and (Input19 == 0) and (Input20 == 1)) then mc.mcCntlSetRRO(inst, 25.0) --Set RRO to 25% elseif ((Input18 == 1) and (Input19 == 0) and (Input20 == 0)) then mc.mcCntlSetRRO(inst, 0.0) --Set RRO to 0% end end --------------------------------------------------------------- -- Keyboard Disable() function. --------------------------------------------------------------- function KeyboardDisable() local iReg = mc.mcIoGetHandle (inst, "Keyboard/EnableKeyboardJog") if (iReg ~= nil) then local val = mc.mcIoGetState(iReg); --wx.wxMessageBox("Show me your Val == " .. tostring(val)) if (val == 1) then mc.mcIoSetState(iReg, 0); scr.SetProperty('btnKeyboardJog', 'Bg Color', ''); scr.SetProperty('btnKeyboardJog', 'Label', 'Keyboard\nInputs Enable'); else mc.mcIoSetState(iReg, 1); scr.SetProperty('btnKeyboardJog', 'Bg Color', '#00FF00'); scr.SetProperty('btnKeyboardJog', 'Label', 'Keyboard\nInputs Disable'); end end end --------------------------------------------------------------- -- Remember Position function. --------------------------------------------------------------- function RememberPosition() local pos = mc.mcAxisGetMachinePos(inst, 0) -- Get current X (0) Machine Coordinates mc.mcProfileWriteString(inst, "RememberPos", "X", string.format (pos)) --Create a register and write the machine coordinates to it local pos = mc.mcAxisGetMachinePos(inst, 1) -- Get current Y (1) Machine Coordinates mc.mcProfileWriteString(inst, "RememberPos", "Y", string.format (pos)) --Create a register and write the machine coordinates to it local pos = mc.mcAxisGetMachinePos(inst, 2) -- Get current Z (2) Machine Coordinates mc.mcProfileWriteString(inst, "RememberPos", "Z", string.format (pos)) --Create a register and write the machine coordinates to it end --------------------------------------------------------------- -- Return to Position function. --------------------------------------------------------------- function ReturnToPosition() local xval = mc.mcProfileGetString(inst, "RememberPos", "X", "NotFound") -- Get the register Value local yval = mc.mcProfileGetString(inst, "RememberPos", "Y", "NotFound") -- Get the register Value local zval = mc.mcProfileGetString(inst, "RememberPos", "Z", "NotFound") -- Get the register Value if(xval == "NotFound")then -- check to see if the register is found wx.wxMessageBox('Register xval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box elseif (yval == "NotFound")then -- check to see if the register is found wx.wxMessageBox('Register yval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box elseif (zval == "NotFound")then -- check to see if the register is found wx.wxMessageBox('Register zval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box else mc.mcCntlMdiExecute(inst, "G00 G53 Z0.0000 \n G00 G53 X" .. xval .. "\n G00 G53 Y" .. yval .. "\n G00 G53 Z" .. zval) end end --------------------------------------------------------------- -- Spin CW function. --------------------------------------------------------------- function SpinCW() local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON); local sigState = mc.mcSignalGetState(sigh); if (sigState == 1) then mc.mcSpindleSetDirection(inst, 0); else mc.mcSpindleSetDirection(inst, 1); end end --------------------------------------------------------------- -- Spin CCW function. --------------------------------------------------------------- function SpinCCW() local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON); local sigState = mc.mcSignalGetState(sigh); if (sigState == 1) then mc.mcSpindleSetDirection(inst, 0); else mc.mcSpindleSetDirection(inst, -1); end end --------------------------------------------------------------- -- Open Docs function. --------------------------------------------------------------- function OpenDocs() local major, minor = wx.wxGetOsVersion() local dir = mc.mcCntlGetMachDir(inst); local cmd = "explorer.exe /open," .. dir .. "\\Docs\\" if(minor <= 5) then -- Xp we don't need the /open cmd = "explorer.exe ," .. dir .. "\\Docs\\" end wx.wxExecute(cmd); end --------------------------------------------------------------- -- Cycle Stop function. --------------------------------------------------------------- function CycleStop() mc.mcCntlCycleStop(inst); mc.mcSpindleSetDirection(inst, 0); mc.mcCntlSetLastError("Cycle Stopped"); end --------------------------------------------------------------- -- Button Jog Mode Toggle() function. --------------------------------------------------------------- function ButtonJogModeToggle() local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT); local jogcont = mc.mcSignalGetState(cont) local inc = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_INC); local joginc = mc.mcSignalGetState(inc) local mpg = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_MPG); local jogmpg = mc.mcSignalGetState(mpg) if (jogcont == 1) then mc.mcSignalSetState(cont, 0) mc.mcSignalSetState(inc, 1) mc.mcSignalSetState(mpg, 0) else mc.mcSignalSetState(cont, 1) mc.mcSignalSetState(inc, 0) mc.mcSignalSetState(mpg, 0) end end --------------------------------------------------------------- -- Ref All Home() function. --------------------------------------------------------------- function RefAllHome() mc.mcAxisDerefAll(inst); --Just to turn off all ref leds mc.mcAxisHomeAll(inst); end --------------------------------------------------------------- -- Go To Work Zero() function. --------------------------------------------------------------- function GoToWorkZero() mc.mcCntlMdiExecute(inst, "G00 X0 Y0 A0")--Without Z moves --mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")--With Z moves end --------------------------------------------------------------- -- Cycle Start() function. --------------------------------------------------------------- function CycleStart() local rc; local tab, rc = scr.GetProperty("MainTabs", "Current Tab") local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab") local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab") --wx.wxMessageBox("tab == " .. tostring(tab) ) --See if we have to do an MDI command if ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1) or (tonumber(tab) == 2 and tonumber(tabG_Mditwo) == 1 )) then local state = mc.mcCntlGetState(inst); if (state == mc.MC_STATE_MRUN_MACROH) then mc.mcCntlCycleStart(inst); mc.mcCntlSetLastError(inst, "Do Cycle Start"); else if (tonumber(tab) == 0) then scr.ExecMdi('mdi1'); mc.mcCntlSetLastError(inst, "Do MDI 1"); else scr.ExecMdi('mdi2'); mc.mcCntlSetLastError(inst, "Do MDI 2"); end end elseif tonumber(tab) > 2 then --No G Code or MDI panel is displayed so Do Nothing mc.mcCntlSetLastError(inst, "Nothing to Start"); --wx.wxMessageBox("Nothing to Start") else --Do CycleStart mc.mcCntlSetLastError(inst, "Do Cycle Start"); mc.mcCntlCycleStart(inst); --wx.wxMessageBox("Do Cycle Start") end end --------------------------------------------------------------- -- --------------------------------------------------------------- if (inst == 0) then --------------------------------------------------------------- -- Set Button Jog Mode to Cont. --------------------------------------------------------------- local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT); local jogcont = mc.mcSignalGetState(cont) mc.mcSignalSetState(cont, 1) --------------------------------------------------------------- -- Load modules --------------------------------------------------------------- local profile = mc.mcProfileGetName(inst) local path = mc.mcCntlGetMachDir(inst) package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;" --package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" --Master module package.loaded.MasterModule = nil mm = require "mcMasterModule" --Probing module package.loaded.Probing = nil prb = require "mcProbing" --mc.mcCntlSetLastError(inst, "Probe Version " .. prb.Version()); --AutoTool module package.loaded.AutoTool = nil at = require "mcAutoTool" ------------------------------------------------------------ --------------------------------------------------------------- -- Load modules --------------------------------------------------------------- function GetFixOffsetVars() local FixOffset = mc.mcCntlGetPoundVar(inst, 4014) FixOffset = FixOffset * 10 local PoundVarX = 5221 if (FixOffset < 7) then PoundVarX = 5221 + ((FixOffset - 1) * 20) else PoundVarX = 7001 + ((FixOffset - 7) * 20) end PoundVarY = PoundVarX + 1 PoundVarZ = PoundVarX + 2 return PoundVarX, PoundVarY, PoundVarZ end ------------------------------------------------------------ function IsAxisEnabled(axis) local inst = mc.mcGetInstance(); local ena = mc.mcAxisIsEnabled(inst, axis); -- mc.mcCntlSetLastError(0, 'in IsAxisEnable() ena = ' .. tostring(ena)); return tostring(ena); end function AxisEnable() local inst = mc.mcGetInstance(); local ena ena = IsAxisEnabled(0); scr.SetProperty('xPos', 'Enabled', ena); scr.SetProperty('xNeg', 'Enabled', ena); scr.SetProperty('btnZeroX', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroX2', 'Enabled', tostring(ena)); scr.SetProperty('btnRefX', 'Enabled', tostring(ena)); ena = IsAxisEnabled(1); scr.SetProperty('yPos', 'Enabled', tostring(ena)); scr.SetProperty('yNeg', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroY', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroY2', 'Enabled', tostring(ena)); scr.SetProperty('btnRefY', 'Enabled', tostring(ena)); ena = IsAxisEnabled(2); scr.SetProperty('zPos', 'Enabled', tostring(ena)); scr.SetProperty('zNeg', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroZ', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroZ2', 'Enabled', tostring(ena)); scr.SetProperty('btnRefZ', 'Enabled', tostring(ena)); ena = IsAxisEnabled(3); scr.SetProperty('aPos', 'Enabled', tostring(ena)); scr.SetProperty('aNeg', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroA', 'Enabled', tostring(ena)); scr.SetProperty('btnZeroA2', 'Enabled', tostring(ena)); scr.SetProperty('btnRefA', 'Enabled', tostring(ena)); end scr.SetProperty('btnEnable', 'Label', 'Enable'); AxisEnable(); end