Changeset 3537 for pykocard/trunk
- Timestamp:
- 04/21/10 02:17:15 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykocard/trunk/pykocard/cartadistcrs.py
r3536 r3537 24 24 import sys 25 25 26 import serial # On Debian/Ubuntu : apt-get install python-serial 27 26 28 class CartadisTCRS : 27 29 """A class to manage Cartadis TCRS vending card readers. … … 31 33 Cartadis is a registered trademark from Copie Monnaie France (C.M.F.) 32 34 """ 33 def __init__(self, device, timeout , debug) :35 def __init__(self, device, timeout=5.0, debug=False) : 34 36 """Initializes the connection to the reader.""" 35 37 self.device = device 36 38 self.timeout = timeout 37 39 self.debug = debug 38 self.serialport = None39 40 41 self.lastcommand = None 40 42 self.tcrsprompt = chr(13) + chr(10) + '$' # the prompt 41 43 self.eoc = chr(13) # end of command … … 57 59 self.trnum = None 58 60 61 # opens the connection to the reader 62 self.tcrs = serial.Serial(device, 63 baudrate=9600, 64 bytesize=serial.EIGHTBITS, 65 parity=serial.PARITY_NONE, 66 stopbits=serial.STOPBITS_ONE, 67 xonxoff=False, 68 rtscts=True, 69 timeout=timeout) 70 71 # cleans up any data waiting to be read 72 self.tcrs.flushInput() 73 59 74 def __del__(self) : 60 75 """Ensures the serial link is closed on deletion.""" … … 63 78 def close(self) : 64 79 """Closes the serial link if it is open.""" 65 if self. serialportis not None :66 self. serialport.close()67 self. serialport= None80 if self.tcrs is not None : 81 self.tcrs.close() 82 self.tcrs = None 68 83 69 84 def logDebug(self, message) : … … 73 88 sys.stderr.flush() 74 89 90 def sendCommand(self, cmd, param=None) : 91 """Sends a command to the reader.""" 92 if param is not None : 93 command = "%s %s%s" % (cmd, param, self.eoc) 94 else : 95 command = "%s%s" % (cmd, self.eoc) 96 self.logDebug("Sending %s to reader" % repr(command)) 97 self.tcrs.write(command) 98 self.tcrs.flush() 99 self.lastcommand = command 75 100 101