Hardware Reference
In-Depth Information
event = line.split(',')
#store the first item in the sensor variable - this
#is which beam (inner or outer)
sensor = int(event[0])
#store the type of the event in the eventType
#variable -- this is if the beam broke or unbroke
eventType = int(event[1])
# convert the text representation of the time into
#a datetime object in eventTime variable
eventTime = datetime.datetime.strptime(event[2],;
“%d %b %Y %H:%M:%S.%f”)
debug (“RawEvent:”+line+”, Current STATE:”+state)
#Main state machine
#INITIALISATION, runs the first time around the loop
if (state == “INIT”):
lastEventTime = eventTime
state = “IDLE”
#calculate the time since the last event took place
diffTime = eventTime - lastEventTime
#to recover state, if the last event was greater than
#30 seconds ago, treat it as independent and reset the
#state machine to IDLE.
#since the idle state of the box is both sensors
#unbroken, waiting for an entry or exit to start
if (diffTime.seconds > 30):
if (state != “IDLE”):
debug (“TIMEOUT - statemachine reset”)
state = “IDLE”
#The idle state is waiting for either the outside or
#inside beam to be broken.
if (state == “IDLE”):
# the inside sensor has been broken
continued
Search WWH ::




Custom Search