Hello Guest it is March 29, 2024, 10:57:03 AM

Author Topic: Timers - Am I crazy  (Read 2455 times)

0 Members and 1 Guest are viewing this topic.

Timers - Am I crazy
« 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?

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Timers - Am I crazy
« Reply #1 on: March 19, 2015, 06:52:25 AM »
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

fun times
Re: Timers - Am I crazy
« Reply #2 on: November 17, 2016, 04:59:53 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?

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.