I posted everything above in the text file
but here is just the PLC script
local inst = mc.mcGetInstance();
local rc = 0;
testcount = testcount + 1
machState, rc = mc.mcCntlGetState(inst);
local inCycle = mc.mcCntlIsInCycle(inst);
--mc.mcCntlSetLastError(inst, 'machWasEnabled = ' .. tostring (machWasEnabled) .. 'machEnabled = ' .. tostring(machEnabled));
if ((machWasEnabled == 0) and (machEnabled == 1)) then
--mc.mcCntlSetLastError(inst, 'Enable!');
scr.SetProperty('btnEnable', 'Label', 'Disable');
scr.SetProperty('btnEnable', 'Bg Color', '#FF0000');
--Enable controls!
elseif ((machWasEnabled == 1) and (machEnabled == 0)) then
--mc.mcCntlSetLastError(inst, 'Disable!');
scr.SetProperty('btnEnable', 'Label', 'Enable');
scr.SetProperty('btnEnable', 'Bg Color', '');
--Diaable controls!
scr.SetProperty('CycleStart', 'Enabled', '0');
enableBlink = 0;
enableBlinkCount = 0;
end
--Blink the enable button.
if (machEnabled == 0) then
enableBlinkCount = enableBlinkCount + 1;
--mc.mcCntlSetLastError(inst, 'enableBlinkCount = ' .. tostring(enableBlinkCount));
if (enableBlinkCount == 10) then
enableBlink = not enableBlink;
--mc.mcCntlSetLastError(inst, 'enableBlink = ' .. tostring(enableBlink));
if (enableBlink == true) then
scr.SetProperty('btnEnable', 'Bg Color', '#00FF00');
elseif(enableBlink == false) then
scr.SetProperty('btnEnable', 'Bg Color', '');
end
enableBlinkCount = 0;
end
end
if ((machState ~= machStateOld) or (machEnable ~= machWasEnabled)) then
local enaCycleStart = ((machState == mc.MC_STATE_IDLE) or (machState == mc.MC_STATE_HOLD)
or (machState == mc.MC_STATE_FRUN_PROBE_FH)
or (machState == mc.MC_STATE_FRUN_THREAD_FH)
or (machState == mc.MC_STATE_FRUN_MACROH)
or (machState == mc.MC_STATE_MRUN_FH)
or (machState == mc.MC_STATE_FRUN_FH)
or (machState == mc.MC_STATE_MRUN_PROBE_FH)
or (machState == mc.MC_STATE_MRUN_THREAD_FH)
or (machState == mc.MC_STATE_MRUN_MACROH)
or (machState == mc.MC_STATE_FRUN_SINGLE_BLOCK))
enaCycleStart = (enaCycleStart and (machEnabled == 1))
local enaStop = (machState ~= mc.MC_STATE_IDLE) and (machEnabled == 1) and (machState ~= mc.MC_STATE_JOG)
local enaFeedHold = (machState ~= mc.MC_STATE_IDLE) and (machEnabled == 1) and (machState ~= mc.MC_STATE_JOG)
local enaReset = (machEnabled == 1) and (machState == mc.MC_STATE_IDLE)
local enaJog = ((machState == mc.MC_STATE_IDLE) or (machState == mc.MC_STATE_HOLD)
or (machState == mc.MC_STATE_FRUN_PROBE_FH)
or (machState == mc.MC_STATE_JOG)
or (machState == mc.MC_STATE_FRUN_THREAD_FH)
or (machState == mc.MC_STATE_FRUN_MACROH)
or (machState == mc.MC_STATE_FRUN_MACROH_JOG)
or (machState == mc.MC_STATE_MRUN_FH)
or (machState == mc.MC_STATE_FRUN_FH)
or (machState == mc.MC_STATE_MRUN_PROBE_FH)
or (machState == mc.MC_STATE_MRUN_THREAD_FH)
or (machState == mc.MC_STATE_FRUN_FH_JOG)
or (machState == mc.MC_STATE_MRUN_MACROH)
or (machState == mc.MC_STATE_MRUN_MACROH_JOG))
enaJog = (enaJog and (machEnabled == 1))
if (enaCycleStart) then
scr.SetProperty('btnCycleStart', 'Enabled', '1');
else
scr.SetProperty('btnCycleStart', 'Enabled', '0');
end
if (enaStop) then
scr.SetProperty('btnStop', 'Enabled', '1');
else
scr.SetProperty('btnStop', 'Enabled', '0');
end
if (enaFeedHold) then
scr.SetProperty('btnFeedHold', 'Enabled', '1');
else
scr.SetProperty('btnFeedHold', 'Enabled', '0');
end
if (enaReset) then
scr.SetProperty('btnReset', 'Enabled', '1');
else
scr.SetProperty('btnReset', 'Enabled', '0');
end
-- if (enaJog) then
-- scr.SetProperty('pnlJog', 'Enabled', '1');
-- JogEnable();
-- else
-- scr.SetProperty('pnlJog', 'Enabled', '0');
-- end
end
if (machEnabled ~= machWasEnabled) then
scr.SetProperty('btnRefAll', 'Enabled', tostring(machEnabled));
scr.SetProperty('btnRefAll2', 'Enabled', tostring(machEnabled));
scr.SetProperty('btnGotoZero', 'Enabled', tostring(machEnabled));
scr.SetProperty('tabJogging', 'Enabled', tostring(machEnabled));
if (machEnabled == 1) then
AxisEnable();
end
end
SigLib = {
--Enable
[mc.OSIG_MACHINE_ENABLED] = function (state)
machEnabled = state;
end,
--HeadUp
[mc.ISIG_INPUT1] = function (on_off)--mc.ISIG_INPUT1
if( on_off==1 ) then
-- On
else
-- Off
end
end,
--HeadDn
[mc.ISIG_INPUT2] = function (state)--mc.ISIG_INPUT2
if( state == 1 ) then
-- On
else
-- Off Call A function here if you wanted
end
end,
[mc.ISIG_INPUT3] = function (state)--mc.ISIG_INPUT3 --Used as an enable button
if( state == 1 ) then
local inst= mc.mcGetInstance();
local reg = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
state = mc.mcSignalGetState(reg);
if(state == 1)then
state = 0
else
state = 1
end
mc.mcCntlEnable(inst, state);
end
end,
[mc.ISIG_INPUT4] = function (state)--mc.ISIG_INPUT2 button to do feed hold
if( state == 1 ) then
local inst= mc.mcGetInstance();
mc.mcCntlFeedHold(inst)
end
end,
[mc.ISIG_INPUT5] = function (state)--mc.ISIG_INPUT2
if( state == 1 ) then
CycleStart() --Run my cycle start function
end
end
}
--local CurrentLine = scr.GetProperty('droCurrent', 'Value', mc.mcCntlGetGcodeLineNbr);
local TotalLines = mc.mcCntlGetGcodeLineCount(inst);
local GcodeCurrentLine = mc.mcCntlGetGcodeLineNbr(inst);
local GcodePercent = (GcodeCurrentLine/TotalLines) * 100;
--scr.SetProperty('droCurrent', 'Value', tostring(CurrentLine));
scr.SetProperty('droTotal', 'Value', tostring(TotalLines+1));
scr.SetProperty('droPercent', 'Value', tostring(GcodePercent));
local Xval = mc.mcAxisGetPos(inst,0);
local Yval = mc.mcAxisGetPos(inst,1);
local Zval = mc.mcAxisGetPos(inst,2);
getAngle(Xval,Yval);
scr.SetProperty('droXY', 'Value', tostring(angle));
getAngle(Xval,Zval);
scr.SetProperty('droXZ', 'Value', tostring(angle));
getAngle(Yval,Zval);
scr.SetProperty('droYZ', 'Value', tostring(angle));
getHypot(Xval,Yval);
scr.SetProperty('droXYhyp', 'Value', tostring(Hyp));
getHypot(Xval,Zval);
scr.SetProperty('droXZhyp', 'Value', tostring(Hyp));
getHypot(Yval,Zval);
scr.SetProperty('droYZhyp', 'Value', tostring(Hyp));
--This is the last thing we do. So keep it at the end of the script!
machStateOld = machState;
machWasEnabled = machEnabled;