Skip to content

Instantly share code, notes, and snippets.

@swinton
Created November 16, 2010 16:20
Show Gist options
  • Select an option

  • Save swinton/702005 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/702005 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import serial, sys
DEVICE='/dev/cu.usbserial-A7006gOH'
IDS={
'28001D71E1': 'Ross',
'0800D9D1AB': 'Steve',
}
def puts(msg):
sys.stdout.write(msg + "\n")
sys.stdout.flush()
def rfid_reader():
puts("Opening " + DEVICE)
ser=serial.Serial(DEVICE, 2400, timeout=1)
try:
while ser.isOpen():
data=ser.readline()
id=IDS.get(data[:-1], False)
if id: yield id
except KeyboardInterrupt:
ser.close()
return
if __name__ == "__main__":
for id in rfid_reader():
puts("Hello, %s" % id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment