10
« on: October 26, 2015, 07:16:04 PM »
I've a script with some dialog boxes that show up to remind the operator when certain maintenance should be performed. I used to have this in the startup, but I've relegated it to a button. For whatever reason when this is run Mach4 will NOT terminate properly when closed, you have to use the task manager. I upgraded to the newest Mach4 today 10/26/15 with hopes it would correct the issue but it doesn't.
Are there any script monkeys out there that might spot what I'm doing wrong here, I've gone through it and tried different permutations of this code. It's really quite simple, it's reading values from the profile that are written by other jobs that have run and prompting the operator to take care of whatever needs taken care of.
Thanks!
Again.. this currently run within a button:
local MyInstance = mc.mcGetInstance()
local DailyMaintenance={}
DailyMaintenance = wx.wxDialog (wx.NULL, wx.wxID_ANY, "DailyMaintenance", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxCAPTION )
DailyMaintenance:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
local bSizer2 = wx.wxBoxSizer( wx.wxVERTICAL )
bSizer2:SetMinSize( wx.wxSize( 500,-1 ) )
CheckHoses = wx.wxCheckBox( DailyMaintenance, wx.wxID_ANY, "Check Hoses, fittings and valves for wear or damage.", wx.wxPoint( -1,-1 ), wx.wxDefaultSize, 0 )
bSizer2:Add( CheckHoses, 0, wx.wxALL, 5 )
CheckwaterTrap = wx.wxCheckBox( DailyMaintenance, wx.wxID_ANY, "Ensure water trap is clear, and drain if necessary.", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
bSizer2:Add( CheckwaterTrap, 0, wx.wxALL, 5 )
Checkdebris = wx.wxCheckBox( DailyMaintenance, wx.wxID_ANY, "Wipe any excessive debris from ballscrews and guideways", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
bSizer2:Add( Checkdebris, 0, wx.wxALL, 5 )
local m_sdbSizer2 = wx.wxStdDialogButtonSizer()
local m_sdbSizer2OK = wx.wxButton( DailyMaintenance, wx.wxID_OK, "" )
m_sdbSizer2:AddButton( m_sdbSizer2OK )
local m_sdbSizer2Cancel = wx.wxButton( DailyMaintenance, wx.wxID_CANCEL, "" )
m_sdbSizer2:AddButton( m_sdbSizer2Cancel )
m_sdbSizer2:Realize();
bSizer2:Add( m_sdbSizer2, 1, wx.wxEXPAND, 5 )
DailyMaintenance:SetSizer( bSizer2 )
DailyMaintenance:Layout()
bSizer2:Fit( DailyMaintenance )
DailyMaintenance:Centre( wx.wxBOTH )
-- Connect Events
m_sdbSizer2Cancel:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
DailyMaintenance:Destroy()
end )
m_sdbSizer2OK:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
local a= CheckwaterTrap:GetValue()
local b = CheckHoses:GetValue()
local c = Checkdebris:GetValue()
if ( a and b and c ) == true then
mc.mcProfileWriteString(MyInstance , "DrumMaker", "DailyMaint", tostring(os.time()))
DailyMaintenance:Destroy()
else
wx.wxMessageBox("You must mark all tasks as being completed to proceed")
end
end )
-- create WeeklyMaintance
local WeeklyMaintance={}
WeeklyMaintance = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Weekly Maintance", wx.wxDefaultPosition, wx.wxSize( 500,110 ), wx.wxCAPTION )
WeeklyMaintance:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
local bSizer4 = wx.wxBoxSizer( wx.wxVERTICAL )
bSizer4:SetMinSize( wx.wxSize( 500,-1 ) )
local CheckWeeklyGrease = wx.wxCheckBox( WeeklyMaintance, wx.wxID_ANY, "Apply single shot of grease to each guideway grease fitting", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
bSizer4:Add( CheckWeeklyGrease, 0, wx.wxALL, 5 )
local CheckWeeklyGreaseBall = wx.wxCheckBox( WeeklyMaintance, wx.wxID_ANY, "Apply single shot of grease to each ball nut", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
bSizer4:Add( CheckWeeklyGreaseBall, 0, wx.wxALL, 5 )
local m_sdbSizer3 = wx.wxStdDialogButtonSizer()
local m_sdbSizer3OK = wx.wxButton( WeeklyMaintance, wx.wxID_OK, "" )
m_sdbSizer3:AddButton( m_sdbSizer3OK )
local m_sdbSizer3Cancel = wx.wxButton( WeeklyMaintance, wx.wxID_CANCEL, "" )
m_sdbSizer3:AddButton( m_sdbSizer3Cancel )
m_sdbSizer3:Realize();
bSizer4:Add( m_sdbSizer3, 1, wx.wxEXPAND, 5 )
WeeklyMaintance:SetSizer( bSizer4 )
WeeklyMaintance:Layout()
WeeklyMaintance:Centre( wx.wxBOTH )
-- Connect Events
m_sdbSizer3Cancel:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
WeeklyMaintance:Destroy()
end )
m_sdbSizer3OK:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
local a= CheckWeeklyGrease:GetValue()
local b = CheckWeeklyGreaseBall:GetValue()
if ( a and b ) == true then
mc.mcProfileWriteString(MyInstance , "DrumMaker", "WeeklyMaint", tostring(os.time()))
WeeklyMaintance:Destroy()
else
wx.wxMessageBox("You must mark all tasks as being completed to proceed")
end
end )
-- create MonthlyMaintenance
local MonthlyMaintenance={}
MonthlyMaintenance = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Monthly Maintenance", wx.wxDefaultPosition, wx.wxSize( 500,-1 ), wx.wxCAPTION )
MonthlyMaintenance:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
local bSizer3 = wx.wxBoxSizer( wx.wxVERTICAL )
bSizer3:SetMinSize( wx.wxSize( 500,-1 ) )
local CheckInspect = wx.wxCheckBox( MonthlyMaintenance, wx.wxID_ANY, "Closely inspect guideways and rails for excessive buildup of grease and debris", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
bSizer3:Add( CheckInspect, 0, wx.wxALL, 5 )
local m_sdbSizer3 = wx.wxStdDialogButtonSizer()
local m_sdbSizer3OK = wx.wxButton( MonthlyMaintenance, wx.wxID_OK, "" )
m_sdbSizer3:AddButton( m_sdbSizer3OK )
local m_sdbSizer3Cancel = wx.wxButton( MonthlyMaintenance, wx.wxID_CANCEL, "" )
m_sdbSizer3:AddButton( m_sdbSizer3Cancel )
m_sdbSizer3:Realize();
bSizer3:Add( m_sdbSizer3, 1, wx.wxEXPAND, 5 )
MonthlyMaintenance:SetSizer( bSizer3 )
MonthlyMaintenance:Layout()
MonthlyMaintenance:Centre( wx.wxBOTH )
-- Connect Events
m_sdbSizer3Cancel:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
MonthlyMaintenance:Destroy()
end )
m_sdbSizer3OK:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
local a= CheckInspect:GetValue()
if (a) then
mc.mcProfileWriteString(MyInstance , "DrumMaker", "MonthlyMaint", tostring(os.time()))
MonthlyMaintenance:Destroy()
else
wx.wxMessageBox("You must mark all tasks as being completed to proceed")
end
end )
-- create StartUpVerify
local StartUpVerify={}
StartUpVerify = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Starting up CNC machine", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxCAPTION + wx.wxSTAY_ON_TOP )
StartUpVerify:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
local bSizer8 = wx.wxBoxSizer( wx.wxVERTICAL )
local gSizer2 = wx.wxGridSizer( 1, 2, 0, 0 )
local m_staticText13 = wx.wxStaticText( StartUpVerify, wx.wxID_ANY, "What tool number is presently in the spindle?", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
m_staticText13:Wrap( -1 )
gSizer2:Add( m_staticText13, 0, wx.wxALL, 5 )
local MyToolNumber = wx.wxTextCtrl( StartUpVerify, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
gSizer2:Add( MyToolNumber, 0, wx.wxALL, 5 )
bSizer8:Add( gSizer2, 1, wx.wxEXPAND, 5 )
local StartupOK = wx.wxStdDialogButtonSizer()
local StartupOKOK = wx.wxButton( StartUpVerify, wx.wxID_OK, "" )
StartupOK:AddButton( StartupOKOK )
StartupOK:Realize();
bSizer8:Add( StartupOK, 1, wx.wxEXPAND, 5 )
StartUpVerify:SetSizer( bSizer8 )
StartUpVerify:Layout()
bSizer8:Fit( StartUpVerify )
StartUpVerify:Centre( wx.wxBOTH )
-- Connect Events
StartupOKOK:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
local CurrentTool = mc.mcToolGetCurrent(MyInstance)
local EnteredTool = tonumber(MyToolNumber:GetValue())
if CurrentTool == EnteredTool then
StartUpVerify:Destroy()
else
wx.wxMessageBox("This is not the expected tool!\n\nThe system is expecting tool "..tostring(CurrentTool).."!\nMake sure tool number "..tostring(CurrentTool).." is in the spindle before enabling!","ERROR")
StartUpVerify:Destroy()
end
end )
local MyInstance = mc.mcGetInstance()
local CurrentTime=os.time()
local FirstUsed = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","FirstUsed","0")))
local LastUsed = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","LastUsed","0")))
local DrumCount = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","DrumCount","0")))
local TimeUsed = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","TimeUsed","0")))
local DailyMaint = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","DailyMaint","0")))
local WeeklyMaint = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","WeeklyMaint","0")))
local MonthlyMaint = tonumber((mc.mcProfileGetString(MyInstance,"DrumMaker","MonthlyMaint","0")))
local LastUsedDate=os.date("*t",LastUsed)
local TodayDate = os.date("*t")
local RunDayCheck = not (os.date("%x",TodayDay)== os.date("%x",DailyMaint))
local RunWeeklyCheck = ((TimeUsed - WeeklyMaint) > 144000 )
local RunMonthlyCheck = ((CurrentTime - MonthlyMaint) > 3456000)
local RunIdleCheck = ((CurrentTime - LastUsed) > 3456000)
mc.mcProfileWriteString(MyInstance , "DrumMaker", "RunWarmUp", "N")
mc.mcProfileWriteString(MyInstance , "DrumMaker", "RunBreakIn", "N")
if RunDayCheck then
DailyMaintenance:ShowModal()
end
if RunWeeklyCheck then
WeeklyMaintance:ShowModal()
mc.mcProfileWriteString(MyInstance , "DrumMaker", "WeeklyMaint", tostring(TimeUsed))
end
if RunMonthlyCheck then
MonthlyMaintenance:ShowModal()
end
StartUpVerify:ShowModal()