/[anoncvs]/projects/dispense2/sql-edition/servers/MIFAREClient.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/MIFAREClient.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Wed May 4 08:57:12 2011 UTC (10 years ago) by tpg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-python
Updated config locations for new machine (and MIFARE serial port)

1 from MIFAREDriver import MIFAREReader, MIFAREException
2 from serial import Serial
3 from LDAPConnector import get_uid, set_card_id
4
5 class MIFAREClient:
6 def __init__(self):
7 self.port = Serial('/dev/ttyS2', baudrate = 19200)
8 self.reader = MIFAREReader(self.port)
9 self.reader.set_led(red = False, green = True)
10 self.reader.beep(100)
11
12 def get_card_id(self):
13 self.reader.set_led(red = True, green = False)
14 try:
15 card_id, capacity = self.reader.select_card()
16 except MIFAREException:
17 self.reader.set_led(red = False, green = True)
18 return None
19 else:
20 self.reader.set_led(red = False, green = True)
21 self.reader.beep(100)
22 return card_id
23
24 def get_card_uid(self):
25 card_id = self.get_card_id()
26 if card_id == None:
27 return None
28 else:
29 return get_uid(card_id)
30
31 def add_card(self, uid):
32 self.reader.set_led(red = True, green = False)
33 for attempt in range(5):
34 self.reader.beep(50)
35 try:
36 card_id, capacity = self.reader.select_card()
37 except MIFAREException:
38 pass
39 else:
40 set_card_id(uid, card_id)
41 self.reader.set_led(red = False, green = True)
42 return True
43 self.reader.set_led(red = False, green = True)
44 return False

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26