Created
May 7, 2014 15:17
-
-
Save broluwo/a7abf54c7bf2c3b34bec to your computer and use it in GitHub Desktop.
RFID Reading Script for Doorman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#Run with root privileges, we may eventually want it to be a daemon but whatever | |
import serial# http://pyserial.sourceforge.net/ | |
port = "/dev/ttyUSB0" # change port name to match the port of the card reader, should always be somewhere in dev | |
ser = serial.Serial(port, 2400) # open serial port | |
print "Enabling the module...", | |
ser.setDTR(True)# the module is enabled by asserting DTR | |
print "Success!" | |
print "Reading tag's unique serial number...", | |
while True: | |
buf = ser.read(12) # get bytes (will block until received)- Not sure ow many bytes the tag is. 12 seems like a good estimate. | |
if buf[0] == chr(0x0A):# if valid data received with no error, continue | |
for i in range(1,len(buf)-1):# display data (ignore final 0x0D byte sent by the reader) | |
tagNum = tagNum + buf[i] | |
#print buf[i], | |
print tagNum | |
else: | |
print "Invalid Tag" | |
#Now we check against the file of tags | |
#If true, then we add the username and datetime data to the log | |
# And run the motor, sleep for a second then run the motor | |
# in the reverse direction | |
print "Disabling the module...", | |
ser.setDTR(False)# the module is disabled by de-asserting DTR | |
print "Success!" | |
ser.close()#Release the serial port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment