there must be a better way than this to generate three bool tags that represent ShiftA ShiftB and ShiftC
What I am doing, I have created a tag “Hour” that represents the Gateway’s clock hour in 00-23 format. I have a timer script running every second to check the hour and set the appropriate bool .
I could have used expressions on each of the three bool tags shiftA, shiftB and shiftC. But my concern is all three expressions may not be evaluated at the exact same CPU scan and there may be an instance where neither 1 of the 3 are true.
So hopefully by putting all the evaluation logic in one script, and three are evaluated at the same time.
Is there a better and more reliable way to set 1 of 3 bits with the guarantee that 1 of the 3 will always be set?
# current Hour 00 - 23 format
hr = system.tag.getTagValue("DownTimes/Hour")
# clear shift bools, and set appropriate shift bool based on Clock hour
shiftA = 0
shiftB = 0
shiftC = 0
# test for Shift A 6:00 - 13:59:59
if hr >= 6:
if hr <14:
shiftA = 1
# test for Shift B 14:00 - 21:59:59
if hr >= 14:
if hr < 22:
shiftB = 1
# If Not shiftA AND NOT shiftB MUST be shiftC
if shiftA == 0:
if shiftB == 0:
shiftC = 1
# update shift bools
system.tag.writeToTag("DownTimes/ShiftA",shiftA)
system.tag.writeToTag("DownTimes/ShiftB",shiftB)
system.tag.writeToTag("DownTimes/ShiftC",shiftC)