modmadmike
July 21st, 2010, 08:39 AM
I wrote a program that pareses the serial input (to which a RFID reader is attached) for a string and executes a command upon finding the string; however, if the string is entered twice it runs the command twice even though there is a timeout.
Here is the main program:
#!/usr/bin/python
################################################## ###########
## Serial RFID authenticator by Mike Walker aka modmadmike ##
################################################## ###########
import time, serial, os
# Begin serial setup
ser = serial.Serial()
ser.baudrate = 2400
ser.port = '/dev/ttyS0'
# End serial setup
while True:
ser.open()
if len(ser.readline()) >= 10:
code=str(ser.read(10)) #10 byte code
if code == 'CODE-A' or code == 'CODE-B':
print 'Code '+code+' is valid'
os.system('sh /home/modmadmike/radr.sh') # Runs a script that types my password
ser.flushInput() # !!!!!!!!!!!!THIS IS SUPPOSED TO CLEAR THE ENTIRE SERIAL BUFFER, BUT IT NEVER DOES!!!!!!!!
code=''
time.sleep(6) # Wait a few seconds for next authentication
else:
print 'Code '+code+' is invalid'
ser.flushInput()
ser.close()
code=''
This RFID reader (http://www.parallax.com/tabid/768/ProductID/114/Default.aspx) attached like so (http://forums.parallax.com/forums/attach.aspx?a=12828) is what is connected to the serial port to send the codes. (They are only $10 at radioshack right now lol)
Here is the main program:
#!/usr/bin/python
################################################## ###########
## Serial RFID authenticator by Mike Walker aka modmadmike ##
################################################## ###########
import time, serial, os
# Begin serial setup
ser = serial.Serial()
ser.baudrate = 2400
ser.port = '/dev/ttyS0'
# End serial setup
while True:
ser.open()
if len(ser.readline()) >= 10:
code=str(ser.read(10)) #10 byte code
if code == 'CODE-A' or code == 'CODE-B':
print 'Code '+code+' is valid'
os.system('sh /home/modmadmike/radr.sh') # Runs a script that types my password
ser.flushInput() # !!!!!!!!!!!!THIS IS SUPPOSED TO CLEAR THE ENTIRE SERIAL BUFFER, BUT IT NEVER DOES!!!!!!!!
code=''
time.sleep(6) # Wait a few seconds for next authentication
else:
print 'Code '+code+' is invalid'
ser.flushInput()
ser.close()
code=''
This RFID reader (http://www.parallax.com/tabid/768/ProductID/114/Default.aspx) attached like so (http://forums.parallax.com/forums/attach.aspx?a=12828) is what is connected to the serial port to send the codes. (They are only $10 at radioshack right now lol)