Can you please explain in great detail, line by line how this code works and function. Thank you. from options import Op

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Can you please explain in great detail, line by line how this code works and function. Thank you. from options import Op

Post by answerhappygod »

Can you please explain in great detail, line by line how
this code works and function. Thank you.
from options import Options
from time import *
from physical import *
from gpio import *
from ioeclient import IoEClient


DELAY_TIME = 1000 # var DELAY_TIME
current_time = 0 # var
current_time

X_READ_DISTANCE = 50 # var
X_READ_DISTANCE
Y_READ_DISTANCE = 50 # var
Y_READ_DISTANCE
cardID = 0 # var cardID
lastCardID = 0 # var lastCardID
state = 2 # waiting # var state

def setup ():

# Registration Server Setup

IoEClient.setup({
"type": "RFID Reader",
"states": [{
"name":
"Card ID",
"type":
"number",
"unit":
'',

"controllable": False
},
{
"name":
"Status",
"type":
"options",
"options":
{

"0": "Valid",

"1": "Invalid",

"2": "Waiting"
},

"controllable": True
}]
})

IoEClient.onInputReceive( lambda rinput:
processData(rinput, True) )

def loop ():
global cardID, lastCardID, state
devices = devicesAt(getCenterX(), getCenterY(),
X_READ_DISTANCE, Y_READ_DISTANCE) # var
devices
found = False # var
found
for i in xrange(0, len(devices)) :
if devices is getName():
continue

cardID = getDeviceProperty(devices,
'CardID')
found = True
break

if not found:
cardID = lastCardID = 0
setState(2)
else:
if lastCardID != cardID:
lastCardID = cardID
sendReport()

delay(DELAY_TIME)

def setState (newState):
global state
if state != newState:
state = newState
analogWrite(A1, state)
sendReport()
def sendReport ():
report = str( int(cardID)) + "," + str(state)
# var report
IoEClient.reportStates(report)



def processData (data, bIsRemote):
if len(data) <= 0:
return
data = data.split(",")
setState(int(data[1]))



if __name__ == "__main__":
setup()
while True:
loop()
idle()
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply