I am wondering if there could be a possibility to get a timer working. Its a client that want to visualize the staircase timer.
So like a clock or something else to count the time remaining.
with value from the detector triggers the count down and new "1" retriggers the remaining time?
-- ** Staircase logic with external time object and retriggering on input object Version 3.1 ** ---- ****************************** Created by Erwin van der Zwart **************************** ---- ************************************** SET PARAMETERS ************************************ ---- Set input addressAddressInput = '6/0/0'-- Set output addressAddressOutput = '6/0/1'-- Set external time address (optional)AddressExternalTime = '6/0/2'-- Use time left indication UseTimeLeft = true-- Set to false if no time left indication is used -- Set feedback adress of time left indication (optional)AddressTimeLeft = '6/0/3'-- Set time delay (Used when external time is not available)SetDelay = 10-- Seconds or MinutesSetSec = true-- Set to false for Minutes-- Set factor delay (Multiplies Delay)SetFac = 1-- Set unique name for staircase timer (to avoid same storage name usage)StaircaseName = 'Staircase_1'-- Logic can be turned of by value 0Off_by_Value_Zero = false-- ************************************** END PARAMETERS ************************************ ---- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --inputvalue = event.getvalueifOff_by_Value_Zero == falseand (event.getvalue() == falseorevent.getvalue() == 0) then-- Exit scriptreturnendValueInput = grp.getvalue(AddressInput)
ValueOutput = grp.getvalue(AddressOutput)
ValueExternalTime = grp.getvalue(AddressExternalTime)
ifSetSec == truethenSetSeconds = 1elseSetSeconds = 60endifValueExternalTime == nilthenValueExternalTime = 0endifValueExternalTime > 0thenStairCaseTime = ValueExternalTime * SetSeconds * SetFacelseStairCaseTime = SetDelay * SetSeconds * SetFacendifValueInput == truethen--check for earlier started scrips--check storage for stpid valuestpid = storage.get(StaircaseName)
--check if stpid has a value ifstpid == nilthenpid = os.getpid()
storage.set(StaircaseName, pid)
else-- kill earlier running script os.kill(stpid, signal.SIGKILL)
-- create new pid for next time to kill pid = os.getpid()
storage.set(StaircaseName, pid)
endifValueOutput == falsethengrp.write(AddressOutput, true)
ValueOutput = trueend-- Check time left indication is used ifUseTimeLeft == truethenifStairCaseTime > 0thengrp.update(AddressTimeLeft, StairCaseTime)
repeatStairCaseTime = StairCaseTime - 1grp.update(AddressTimeLeft, StairCaseTime)
os.sleep(1)
untilStairCaseTime == 0endelseos.sleep(StairCaseTime)
endValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == truethenValueInput = grp.getvalue(AddressInput)
ifValueInput == truethengrp.write(AddressInput, false)
ValueInput = falseendifOff_by_Value_Zero == falsethenifValueOutput == truethengrp.write(AddressOutput, false)
ValueOutput = falseendelse-- Do nothing, this will trigger else condition below on next runendendelse--check for earlier started scrips--check storage for stpid valuestpid = storage.get(StaircaseName)
--check if stpid has a value ifstpid == nilthenelse-- kill earlier running script os.kill(stpid, signal.SIGKILL)
grp.update(AddressTimeLeft, 0)
pid = nilstorage.set(StaircaseName, pid)
endifValueOutput == truethengrp.write(AddressOutput, false)
endend
-- ** Staircase logic with external time object and retriggering on input object Version 3.1 ** ---- ****************************** Created by Erwin van der Zwart **************************** ---- ************************************** SET PARAMETERS ************************************ ---- Set input addressAddressInput = '6/0/0'-- Set output addressAddressOutput = '6/0/1'-- Set external time address (optional)AddressExternalTime = '6/0/2'-- Use time left indication UseTimeLeft = true-- Set to false if no time left indication is used -- Set feedback adress of time left indication (optional)AddressTimeLeft = '6/0/3'-- Set time delay (Used when external time is not available)SetDelay = 10-- Seconds or MinutesSetSec = true-- Set to false for Minutes-- Set factor delay (Multiplies Delay)SetFac = 1-- Set unique name for staircase timer (to avoid same storage name usage)StaircaseName = 'Staircase_1'-- Logic can be turned of by value 0Off_by_Value_Zero = false-- ************************************** END PARAMETERS ************************************ ---- *************************** DON'T CHANGE ANYTHING UNDER THIS LINE ************************ --inputvalue = event.getvalueifOff_by_Value_Zero == falseand (event.getvalue() == falseorevent.getvalue() == 0) then-- Exit scriptreturnendValueInput = grp.getvalue(AddressInput)
ValueOutput = grp.getvalue(AddressOutput)
ValueExternalTime = grp.getvalue(AddressExternalTime)
ifSetSec == truethenSetSeconds = 1elseSetSeconds = 60endifValueExternalTime == nilthenValueExternalTime = 0endifValueExternalTime > 0thenStairCaseTime = ValueExternalTime * SetSeconds * SetFacelseStairCaseTime = SetDelay * SetSeconds * SetFacendifValueInput == truethen--check for earlier started scrips--check storage for stpid valuestpid = storage.get(StaircaseName)
--check if stpid has a value ifstpid == nilthenpid = os.getpid()
storage.set(StaircaseName, pid)
else-- kill earlier running script os.kill(stpid, signal.SIGKILL)
-- create new pid for next time to kill pid = os.getpid()
storage.set(StaircaseName, pid)
endifValueOutput == falsethengrp.write(AddressOutput, true)
ValueOutput = trueend-- Check time left indication is used ifUseTimeLeft == truethenifStairCaseTime > 0thengrp.update(AddressTimeLeft, StairCaseTime)
repeatStairCaseTime = StairCaseTime - 1grp.update(AddressTimeLeft, StairCaseTime)
os.sleep(1)
untilStairCaseTime == 0endelseos.sleep(StairCaseTime)
endValueOutput = grp.getvalue(AddressOutput)
ifValueOutput == truethenValueInput = grp.getvalue(AddressInput)
ifValueInput == truethengrp.write(AddressInput, false)
ValueInput = falseendifOff_by_Value_Zero == falsethenifValueOutput == truethengrp.write(AddressOutput, false)
ValueOutput = falseendelse-- Do nothing, this will trigger else condition below on next runendendelse--check for earlier started scrips--check storage for stpid valuestpid = storage.get(StaircaseName)
--check if stpid has a value ifstpid == nilthenelse-- kill earlier running script os.kill(stpid, signal.SIGKILL)
grp.update(AddressTimeLeft, 0)
pid = nilstorage.set(StaircaseName, pid)
endifValueOutput == truethengrp.write(AddressOutput, false)
endend
BR,
Erwin
Thanks alot. Will not be improved by me, because Lua is not my strong side at all. But will definitly test it.. Thanks alot.
I gonna create three virtual objects and then i am wondering whats the correct datatype. Is it 10 Time/date. ?
16.12.2018, 16:09 (This post was last modified: 16.12.2018, 16:13 by AlexLV.)
Erwin,
sorry, should it be a resident script? If yes wich delay should be used?
Can you pls a little more in detail describe your script data types? Is it correct:
6/0/0 Boolean
6/0/1 Boolean
6/0/2 2 bytes unsigned int
6/0/3 2 bytes unsigned int
I tried to make resident script with 1 sec delay and have error:
Resident script:38: attempt to index global 'event' (a nil value)
stack traceback:
19.12.2018, 22:14 (This post was last modified: 19.12.2018, 22:45 by AlexLV.)
Hi guys, I have in front hour = 2 Just now started this script for testing...
Erwin, what it could be? (May be time difference? I have eastern Europe time zone (+2 hours), but how it can influence here??) I think error in in time calculation function..
Hi
I see this code potentially dangerous. I think there is small but still chance you hit a different running process with the same PID after LM restart. Isn't there more "clean" solution? Mutexes, semaphores etc?
How about adding new function script.NumActive() which returns number of parallel running instances of the same script? And call this function in the loop cycle after sleep and exit the cycle after the returned value is bigger than 1?
Any idea why yhe mosaic wont show the value of the 3 byte value. Showed it when i used the 2 byte value in seconds and in minutes.
But when i changed the adress and upgraded the mosaic it wont show the value any longer.
Just tested it with time so definitly now showing 3 byte values.
(20.12.2018, 22:27)Tokatubs Wrote: Great work as always Erwin.
Any idea why yhe mosaic wont show the value of the 3 byte value. Showed it when i used the 2 byte value in seconds and in minutes.
But when i changed the adress and upgraded the mosaic it wont show the value any longer.
Just tested it with time so definitly now showing 3 byte values.
Date/time object is not supported in this widget, convert it to string and use 250byte
(20.12.2018, 22:27)Tokatubs Wrote: Great work as always Erwin.
Any idea why yhe mosaic wont show the value of the 3 byte value. Showed it when i used the 2 byte value in seconds and in minutes.
But when i changed the adress and upgraded the mosaic it wont show the value any longer.
Just tested it with time so definitly now showing 3 byte values.
Date/time object is not supported in this widget, convert it to string and use 250byte
OK. Cant seem to find converter for that under the converter in FBEDITOR. Then i maybe need to search for a script to convert the value.
Thanks for input.