当前位置: 首页>>代码示例>>Python>>正文


Python usb1.USBErrorNoDevice方法代码示例

本文整理汇总了Python中usb1.USBErrorNoDevice方法的典型用法代码示例。如果您正苦于以下问题:Python usb1.USBErrorNoDevice方法的具体用法?Python usb1.USBErrorNoDevice怎么用?Python usb1.USBErrorNoDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在usb1的用法示例。


在下文中一共展示了usb1.USBErrorNoDevice方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def read(self, timeout=0):
        if self.usb_inp is not None:
            try:
                ep_addr = self.usb_inp.getAddress()
                frame = self.usb_dev.bulkRead(ep_addr, 300, timeout)
            except libusb.USBErrorTimeout:
                raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
            except libusb.USBErrorNoDevice:
                raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
            except libusb.USBError as error:
                log.error("%r", error)
                raise IOError(errno.EIO, os.strerror(errno.EIO))

            if len(frame) == 0:
                log.error("bulk read returned zero data")
                raise IOError(errno.EIO, os.strerror(errno.EIO))

            frame = bytearray(frame)
            log.log(logging.DEBUG-1, "<<< %s", hexlify(frame).decode())
            return frame 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:22,代码来源:transport.py

示例2: write

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def write(self, frame, timeout=0):
        if self.usb_out is not None:
            log.log(logging.DEBUG-1, ">>> %s", hexlify(frame).decode())
            try:
                ep_addr = self.usb_out.getAddress()
                self.usb_dev.bulkWrite(ep_addr, bytes(frame), timeout)
                if len(frame) % self.usb_out.getMaxPacketSize() == 0:
                    self.usb_dev.bulkWrite(ep_addr, b'', timeout)
            except libusb.USBErrorTimeout:
                raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
            except libusb.USBErrorNoDevice:
                raise IOError(errno.ENODEV, os.strerror(errno.ENODEV))
            except libusb.USBError as error:
                log.error("%r", error)
                raise IOError(errno.EIO, os.strerror(errno.EIO)) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:17,代码来源:transport.py

示例3: closeLink

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def closeLink(self):
		if self._dev_handle:

			for t in self._writeTransfers:
				try:
					t.cancel()
				except usb1.USBErrorNotFound:
					pass

			self._writeTransfers = []

			if self._linkReader:
				self._linkReader.stop()
				self._linkReader = None

			#if self._incomingQueue:
			#	self._incomingQueue.stop()
			#	self._incomingQueue = None

			try:
				self._dev_handle.releaseInterface(0)
			except ( usb1.USBErrorNoDevice, usb1.USBErrorNotFound):
				pass

			self._dev_handle = None
			self._context = None
			self._port_id = None

			self._eventListener.onLinkClosed()
			self._serialLoggerEnabled and self._serialLogger.debug("(X) Link Closed")

	# ~~~~~~~ From PrinterCommTransport ~~~~~~~~~~ 
开发者ID:AstroPrint,项目名称:AstroBox,代码行数:34,代码来源:usb_t.py

示例4: stop

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def stop(self):
		self._stopped = True

		for x in self._transferList:
			if x.isSubmitted():
				try:
					x.cancel()
				except ( usb1.USBErrorNotFound, usb1.USBErrorNoDevice ):
					pass

#
# Class to queue incoming commands
# 
开发者ID:AstroPrint,项目名称:AstroBox,代码行数:15,代码来源:usb_t.py

示例5: FindDevicesSafe

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def FindDevicesSafe(cls, setting_matcher, device_matcher=None,
                      usb_info='', timeout_ms=None):
    """Safe version of FindDevices.

    Like FindDevices, but catch USB exceptions as devices are iterated through.

    Yields:
      Unopened UsbHandle instances.
    """
    ctx = usb1.USBContext()
    try:
      for device in ctx.getDeviceList(skip_on_error=True):
        setting = setting_matcher(device)
        if setting is None:
          continue

        try:
          handle = cls(device, setting, usb_info=usb_info,
                       timeout_ms=timeout_ms)
          if device_matcher is None or device_matcher(handle):
            yield handle
        except (usb1.USBErrorOther, usb1.USBErrorNoDevice) as e:
          logging.error(
              'Failed to open USB device, is user in group plugdev? %s', e)
          continue
    except usb1.USBError as e:
      logging.error('Failed to get device list: %s', e) 
开发者ID:luci,项目名称:luci-py,代码行数:29,代码来源:common.py

示例6: trezor_exception

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [as 别名]
def trezor_exception(f):
    def func(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except ValueError as e:
            raise BadArgumentError(str(e))
        except Cancelled:
            raise ActionCanceledError('{} canceled'.format(f.__name__))
        except USBErrorNoDevice:
            raise DeviceConnectionError('Device disconnected')
    return func 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:13,代码来源:trezor.py

示例7: open

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBErrorNoDevice [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)) 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:59,代码来源:transport.py


注:本文中的usb1.USBErrorNoDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。