Here is what I use.
You need to make a couple of registers also.
In PLC
-------------------------------------------------------
-- Cycle time label update
-------------------------------------------------------
--Requires a static text box named "CycleTime" on the screen
if (machEnabled == 1) then
local running = mc.mcCntlIsInCycle(inst)
if (running == 1) then
local cycletime = mc.mcCntlGetRunTime(inst, time)
scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
--run time
local hRun = mc.mcRegGetHandle(inst, 'iRegs0/RunningTime')
RunTime = cycletime
mc.mcRegSetValue(hRun, RunTime)
end
end
In PLC First Run section
---------------------------------------------------------
--Pop up message for maintenance
--Keep at bottom
---------------------------------------------------------
local MaintReg = mc.mcRegGetHandle(inst, 'iRegs0/MaintTime')
local MaintRegVal = mc.mcRegGetValue(MaintReg)
if (MaintRegVal >= 144000) then
mc.mcRegSetValue(MaintReg, 0.0)
wx.wxMessageBox("Please perform maintenance")
end
In the Cycle Start function in Screen Load Script
--Set time on Maintenance timer
local hMaint = mc.mcRegGetHandle(inst, 'iRegs0/MaintTime')
local MaintTime = mc.mcRegGetValue(hMaint)
local hRunning = mc.mcRegGetHandle(inst, 'iRegs0/RunningTime')
local RunningTime = mc.mcRegGetValue(hRunning)
MaintTime = (MaintTime + RunningTime)
mc.mcRegSetValue(hMaint, MaintTime)
mc.mcRegSetValue(hRunning, 0.0)