[3534] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | # |
---|
| 3 | # PyKoCard |
---|
| 4 | # |
---|
| 5 | # PyKoCard : Smart Card / Vending Card managing library |
---|
| 6 | # |
---|
| 7 | # (c) 2010 Jerome Alet <alet@librelogiciel.com> |
---|
| 8 | # This program is free software: you can redistribute it and/or modify |
---|
| 9 | # it under the terms of the GNU General Public License as published by |
---|
| 10 | # the Free Software Foundation, either version 3 of the License, or |
---|
| 11 | # (at your option) any later version. |
---|
| 12 | # |
---|
| 13 | # This program is distributed in the hope that it will be useful, |
---|
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | # GNU General Public License for more details. |
---|
| 17 | # |
---|
| 18 | # You should have received a copy of the GNU General Public License |
---|
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 20 | # |
---|
| 21 | # $Id$ |
---|
| 22 | # |
---|
| 23 | |
---|
[3535] | 24 | import sys |
---|
| 25 | |
---|
[3534] | 26 | class CartadisTCRS : |
---|
| 27 | """A class to manage Cartadis TCRS vending card readers. |
---|
| 28 | |
---|
| 29 | Documentation was found in a Cartadis TCRS reader's paper manual. |
---|
| 30 | |
---|
| 31 | Cartadis is a registered trademark from Copie Monnaie France (C.M.F.) |
---|
| 32 | """ |
---|
| 33 | def __init__(self, device, timeout, debug) : |
---|
| 34 | """Initializes the connection to the reader.""" |
---|
| 35 | self.device = device |
---|
| 36 | self.timeout = timeout |
---|
| 37 | self.debug = debug |
---|
| 38 | self.serialport = None |
---|
| 39 | |
---|
| 40 | def __del__(self) : |
---|
| 41 | """Ensures the serial link is closed on deletion.""" |
---|
| 42 | self.close() |
---|
| 43 | |
---|
| 44 | def close(self) : |
---|
| 45 | """Closes the serial link if it is open.""" |
---|
| 46 | if self.serialport is not None : |
---|
| 47 | self.serialport.close() |
---|
| 48 | self.serialport = None |
---|
| 49 | |
---|
[3535] | 50 | def logDebug(self, message) : |
---|
[3534] | 51 | """Logs a debug message.""" |
---|
| 52 | if self.debug : |
---|
| 53 | sys.stderr.write("%s\n" % message) |
---|
| 54 | sys.stderr.flush() |
---|