本文整理汇总了Python中usb1.USBErrorBusy方法的典型用法代码示例。如果您正苦于以下问题:Python usb1.USBErrorBusy方法的具体用法?Python usb1.USBErrorBusy怎么用?Python usb1.USBErrorBusy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类usb1
的用法示例。
在下文中一共展示了usb1.USBErrorBusy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorBusy [as 别名]
def open(cls):
#pdb.set_trace()
try:
cls.transport = get_transport(None, prefix_search=False)
except StopIteration as e:
debug(); pdb.set_trace()
init_msg = proto.Initialize()
if cls.state is not None:
init_msg.state = cls.state
try:
cls.features = cls.call_raw(init_msg)
logging.info("call_raw transport.write(msg): %s", init_msg)
except (TransportException, USBErrorBusy):
raise OpenCredstickError("Error opening Trezor")
示例2: openLink
# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorBusy [as 别名]
def openLink(self, port_id, sendEndpoint, receiveEndpoint):
if port_id is not None:
if self._dev_handle is None:
try:
port_parts = port_id.split(':') #port id is "vid:pid"
vid = int(port_parts[0])
pid = int(port_parts[1])
self._context = usb1.USBContext()
self._dev_handle = self._context.openByVendorIDAndProductID(vid, pid, skip_on_error=True)
if self._dev_handle is not None:
self._hasError = False
self._dev_handle.claimInterface(0)
self._port_id = port_id
self._sendEP = sendEndpoint
self._receiveEP = receiveEndpoint
#self._incomingQueue = IncomingQueue(self._eventListener)
#self._incomingQueue.start()
#self._linkReader = LinkReader(self._dev_handle, self._context, receiveEndpoint, self._eventListener, self._incomingQueue, self)
self._linkReader = LinkReader(self._dev_handle, self._context, receiveEndpoint, self._eventListener, self)
self._linkReader.start()
self._serialLoggerEnabled and self._serialLogger.debug("Connected to USB Device -> Vendor: 0x%04x, Product: 0x%04x" % (vid, pid))
self._eventListener.onLinkOpened()
return True
except usb1.USBErrorBusy:
return False
else:
return True #It was already opened
return False
#
# closes communication with the USB device
#
示例3: catchUsbBusy
# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorBusy [as 别名]
def catchUsbBusy(fn):
def wrapped(*args, **kwargs):
try:
return fn(*args, **kwargs)
except usb1.USBErrorBusy as e:
logger.error("Could not claim USB device, got LIBUSB_ERROR_BUSY.\nIf you have a running adb server, you'll need to stop it by running 'adb kill-server' and then try again")
sys.exit(1)
return wrapped
示例4: wait_for_device
# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorBusy [as 别名]
def wait_for_device(self):
while State.DISCONNECTED == self.state:
usbdev = self.find_fastboot_device()
if None != usbdev:
try:
usbdev.Open()
I("fastboot connected to %s", usbdev.serial_number)
except usb1.USBError as e:
usbdev.Close()
time.sleep(5)
continue
self.usbdev = usbdev
self.set_state(State.CONNECTED_FB)
continue
usbdev = self.find_adb_device()
if None != usbdev:
try:
usbdev.Open()
I("adb: connected")
self.set_state(State.CONNECTED_ADB_DEVICE)
except usb1.USBErrorBusy as e:
self.set_state(self.adb_get_state())
if State.CONNECTED_ADB_DEVICE == self.state:
I("adb: connected")
except usb1.USBError:
usbdev.Close()
time.sleep(5)
continue
self.usbdev = usbdev
continue
I("Waiting for device...")
time.sleep(5)
示例5: open
# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorBusy [as 别名]
def open(self, usb_bus, dev_adr):
self.usb_dev = None
self.usb_out = None
self.usb_inp = None
for dev in self.context.getDeviceList(skip_on_error=True):
if ((dev.getBusNumber() == usb_bus and
dev.getDeviceAddress() == dev_adr)):
break
else:
log.error("no device {0} on bus {1}".format(dev_adr, usb_bus))
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
try:
first_setting = next(dev.iterSettings())
except StopIteration:
log.error("no usb configuration settings, please replug device")
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
def transfer_type(x):
return x & libusb.TRANSFER_TYPE_MASK
def endpoint_dir(x):
return x & libusb.ENDPOINT_DIR_MASK
for endpoint in first_setting.iterEndpoints():
ep_addr = endpoint.getAddress()
ep_attr = endpoint.getAttributes()
if transfer_type(ep_attr) == libusb.TRANSFER_TYPE_BULK:
if endpoint_dir(ep_addr) == libusb.ENDPOINT_IN:
if not self.usb_inp:
self.usb_inp = endpoint
if endpoint_dir(ep_addr) == libusb.ENDPOINT_OUT:
if not self.usb_out:
self.usb_out = endpoint
if not (self.usb_inp and self.usb_out):
log.error("no bulk endpoints for read and write")
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
try:
# workaround the PN533's buggy USB implementation
self._manufacturer_name = dev.getManufacturer()
self._product_name = dev.getProduct()
except libusb.USBErrorIO:
self._manufacturer_name = None
self._product_name = None
try:
self.usb_dev = dev.open()
self.usb_dev.claimInterface(0)
except libusb.USBErrorAccess:
raise IOError(errno.EACCES, os.strerror(errno.EACCES))
except libusb.USBErrorBusy:
raise IOError(errno.EBUSY, os.strerror(errno.EBUSY))
except libusb.USBErrorNoDevice:
raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))