python - USB RFID reader + raspberry pi -
i have usb rfid reader connected raspberry pi rfid reader chinese brand act keyboard , read first 10 digit
so trying here read card , compare stored number in code
#!/usr/bin/env python import time import sys card = '0019171125' # stored card number consider using list or file. def main(): # define main function. while true: # loop until program encounters error. sys.stdin = open('/dev/tty0', 'r') rfid_input = input() if rfid_input == card: # coppare stored number input , if true execute code. print "access granted" print "read code rfid reader:{0}".format(rfid_input) else: # , if condition false excecute code. print "access denied" tty.close() main() # call main function. but error keep showing
rfid_input = input()
^ indentationerror: unindent not match outer indentation level
any suggestion
python indentation-sensitive, need indent code properly:
#!/usr/bin/env python import time import sys card = '0019171125' def main(): while true: sys.stdin = open('/dev/tty0', 'r') rfid_input = input() if rfid_input == card: print "access granted" print "read code rfid reader:{0}".format(rfid_input) else: print "access denied" tty.close() main() note tty.close() raise error because there no tty defined. want close sys.stdin there, although it’s not idea use sys.stdin different stream when read stream directly instead.
also, don’t use input() user input, use raw_input.
def main(): open('/dev/tty0', 'r') tty: while true: rfid_input = tty.readline() if rfid_input == card: print "access granted" print "read code rfid reader:{0}".format(rfid_input) else: print "access denied"
Comments
Post a Comment