Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: donb9261 on March 18, 2015, 02:10:25 PM
-
I am somewhat confused as to how to implement a timer in Lua.
For my lube cycle (way lube pump) I need an on time and off time. Once the off time is exceeded turn on outputxx. When on time exceeded turn off outputxx. I tried the wxMilliSleep but it locks down the control during the timing and since this is a timing loop the control continuosly loops and is locked from any functionality.
As a test I tried this and it does what I said above: (Inserted in the PLC)
ActivateSignalTime = 5000
if (machEnabled == 1) then
runLube()
end
function runLube()
local inst = mc.mcGetInstance()
hsig1,rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
mc.mcSignalSetState(hsig1, 1)
wx.wxMessageBox("Output 1 On")
wx.wxMilliSleep(ActivateSignalTime)
mc.mcSignalSetState(hsig1, 0)
wx.wxMessageBox("Output 1 Off")
end
Although crude it does as stated above. Any ideas Scott?
-
Yes, since your in a PLC loop, just use a counter that accumulates up to 5000 then when it does fire off your output, then reset your counter to 0.
Scott
-
I am somewhat confused as to how to implement a timer in Lua.
For my lube cycle (way lube pump) I need an on time and off time. Once the off time is exceeded turn on outputxx. When on time exceeded turn off outputxx. I tried the wxMilliSleep but it locks down the control during the timing and since this is a timing loop the control continuosly loops and is locked from any functionality.
As a test I tried this and it does what I said above: (Inserted in the PLC)
ActivateSignalTime = 5000
if (machEnabled == 1) then
runLube()
end
function runLube()
local inst = mc.mcGetInstance()
hsig1,rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
mc.mcSignalSetState(hsig1, 1)
wx.wxMessageBox("Output 1 On")
wx.wxMilliSleep(ActivateSignalTime)
mc.mcSignalSetState(hsig1, 0)
wx.wxMessageBox("Output 1 Off")
end
Although crude it does as stated above. Any ideas Scott?
How could I exit the loop if another signal became active during the sleep time? Can this be used in an M code. I'm trying to wait for a THC to fire. Thanks for any help.