Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fe46149b9 | |||
| e7d92fba8a | |||
| 6b1b0f479f | |||
| e5c3e9c824 | |||
| a90e215aba | |||
| 9be8b77983 |
@@ -79,6 +79,14 @@ class PicoKey:
|
||||
self.product = Product(Product.UNKNOWN)
|
||||
self.version = (0, 0)
|
||||
|
||||
def close(self):
|
||||
if isinstance(self.__card, RescuePicoKey):
|
||||
self.__card.close()
|
||||
else:
|
||||
self.__card.disconnect()
|
||||
self.__card.release()
|
||||
self.__card = None
|
||||
|
||||
def transmit(self, apdu):
|
||||
response, sw1, sw2 = self.__card.transmit(apdu)
|
||||
return response, sw1, sw2
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
*/
|
||||
"""
|
||||
|
||||
import os
|
||||
import usb.core
|
||||
import usb.util
|
||||
import libusb_package
|
||||
import usb.backend.libusb1
|
||||
from .ICCD import ICCD
|
||||
|
||||
class RescuePicoKey:
|
||||
@@ -37,7 +40,12 @@ class RescuePicoKey:
|
||||
return True
|
||||
return False
|
||||
|
||||
devs = usb.core.find(find_all=True, custom_match=find_class(0x0B))
|
||||
backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
|
||||
try:
|
||||
devs = usb.core.find(find_all=True, custom_match=find_class(0x0B), backend=backend)
|
||||
except Exception as e:
|
||||
print("RescuePicoKey: exception during usb.core.find:", e)
|
||||
devs = []
|
||||
found = False
|
||||
for dev in devs:
|
||||
if (dev.manufacturer == 'Pol Henarejos'):
|
||||
@@ -66,6 +74,16 @@ class RescuePicoKey:
|
||||
if (not found):
|
||||
raise Exception('Not found any Pico Key device')
|
||||
|
||||
def close(self):
|
||||
if self.__dev:
|
||||
usb.util.dispose_resources(self.__dev)
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
self.close()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dev)
|
||||
|
||||
@@ -77,8 +95,15 @@ class RescuePicoKey:
|
||||
assert(self.__dev.write(self.__out, data, timeout) == len(data))
|
||||
|
||||
def exchange(self, data, timeout=2000):
|
||||
self.write(data=data, timeout=timeout)
|
||||
return self.read(timeout=timeout)
|
||||
try:
|
||||
self.write(data=data, timeout=timeout)
|
||||
except Exception as e:
|
||||
raise Exception("USB write error: " + str(e))
|
||||
try:
|
||||
ret = self.read(timeout=timeout)
|
||||
except Exception as e:
|
||||
raise Exception("USB read error: " + str(e))
|
||||
return ret
|
||||
|
||||
def powerOn(self):
|
||||
if (not self.__active):
|
||||
|
||||
+1
-1
@@ -18,4 +18,4 @@
|
||||
*/
|
||||
"""
|
||||
|
||||
__version__ = "1.1.2"
|
||||
__version__ = "1.1.5"
|
||||
|
||||
Reference in New Issue
Block a user