Beispiel #1
0
 def reset_card(self):
     self._con.disconnect()
     try:
         self._con.connect()
     except NoCardException:
         raise NoCardError()
     return 1
Beispiel #2
0
	def wait_for_card(self, timeout=None, newcardonly=False):
		cr = CardRequest(readers=[self._reader], timeout=timeout, newcardonly=newcardonly)
		try:
			cr.waitforcard()
		except CardRequestTimeoutException:
			raise NoCardError()
		self.connect()
Beispiel #3
0
 def connect(self):
     try:
         # Explicitly select T=0 communication protocol
         self._con.connect(CardConnection.T0_protocol)
     except CardConnectionException:
         raise ProtocolError()
     except NoCardException:
         raise NoCardError()
Beispiel #4
0
    def connect(self):
        try:
            # To avoid leakage of resources, make sure the reader
            # is disconnected
            self.disconnect()

            # Explicitly select T=0 communication protocol
            self._con.connect(CardConnection.T0_protocol)
        except CardConnectionException:
            raise ProtocolError()
        except NoCardException:
            raise NoCardError()
Beispiel #5
0
    def wait_for_card(self, timeout=None, newcardonly=False):
        # Direct try
        existing = False

        try:
            self.reset_card()
            if not newcardonly:
                return
            else:
                existing = True
        except NoCardError:
            pass

        # Poll ...
        mt = time.time() + timeout if timeout is not None else None
        pe = 0

        while (mt is None) or (time.time() < mt):
            try:
                time.sleep(0.5)
                self.reset_card()
                if not existing:
                    return
            except NoCardError:
                existing = False
            except ProtocolError:
                if existing:
                    existing = False
                else:
                    # Tolerate a couple of protocol error ... can happen if
                    # we try when the card is 'half' inserted
                    pe += 1
                    if (pe > 2):
                        raise

        # Timed out ...
        raise NoCardError()
Beispiel #6
0
 def reset_card(self):
     rv = self._reset_card()
     if rv == 0:
         raise NoCardError()
     elif rv < 0:
         raise ProtocolError()
Beispiel #7
0
 def connect(self):
     try:
         self._con.connect()
     except NoCardException:
         raise NoCardError()