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


Python usb1.USBError方法代码示例

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


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

示例1: read

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [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: close

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def close(self):
		"""	Close USB connection and cleanup. OctoPrint Serial Factory method"""

		self._logger.debug("FlashForge.close()")
		self._incoming = None
		self._plugin.on_disconnect()
		if self._handle:
			try:
				self._handle.releaseInterface(0)
			except Exception:
				pass
			try:
				self._handle.close()
			except usb1.USBError as usberror:
				raise FlashForgeError("Error releasing USB", usberror)
			self._handle = None 
开发者ID:Mrnt,项目名称:OctoPrint-FlashForge,代码行数:18,代码来源:flashforge.py

示例3: Close

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def Close(self):
    port_path = self.port_path
    _LOG.info('%s.Close()', self.port_path_str)
    with self._HANDLE_CACHE_LOCK:
      self._HANDLE_CACHE.pop(port_path, None)
    if self._handle is None:
      return
    try:
      if self._interface_number:
        self._handle.releaseInterface(self._interface_number)
      self._handle.close()
    except libusb1.USBError as e:
      _LOG.info('%s.Close(): USBError: %s', self.port_path_str, e)
    finally:
      self._handle = None
      self._read_endpoint = None
      self._write_endpoint = None
      self._interface_number = None
      self._max_read_packet_len = None 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:common.py

示例4: usb_info

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def usb_info(self):
        """TODO

        Returns
        -------
        TODO
            TODO

        """
        try:
            sn = self.serial_number
        except usb1.USBError:
            sn = ''
        if sn and sn != self._usb_info:
            return '%s %s' % (self._usb_info, sn)
        return self._usb_info

    # ======================================================================= #
    #                                                                         #
    #                                Matchers                                 #
    #                                                                         #
    # ======================================================================= # 
开发者ID:JeffLIrion,项目名称:adb_shell,代码行数:24,代码来源:usb_transport.py

示例5: write

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [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

示例6: write

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def write(self, data):
		"""Write commands to printer. OctoPrint Serial Factory method

		Formats the commands sent by OctoPrint to make them FlashForge friendly.
		"""

		self._logger.debug("FlashForge.write() called by thread {}".format(threading.currentThread().getName()))

		# save the length for return on success
		data_len = len(data)
		self._writelock.acquire()

		# strip carriage return, etc so we can terminate lines the FlashForge way
		data = data.strip(b" \r\n")
		# try to filter out garbage commands (we need to replace with something harmless)
		# do this here instead of octoprint.comm.protocol.gcode.sending hook so DisplayLayerProgress plugin will work
		if len(data) and not self._plugin.valid_command(data):
			data = b"M119"

		try:
			self._logger.debug("FlashForge.write() {0}".format(data.decode()))
			self._handle.bulkWrite(self._usb_cmd_endpoint_out, b"~%s\r\n" % data, int(self._write_timeout * 1000.0))
			self._writelock.release()
			return data_len
		except usb1.USBError as usberror:
			self._writelock.release()
			raise FlashForgeError('USB Error write()', usberror) 
开发者ID:Mrnt,项目名称:OctoPrint-FlashForge,代码行数:29,代码来源:flashforge.py

示例7: writeraw

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def writeraw(self, data, command = True):
		"""Write raw data to printer.

		data: bytearray to send
		command: True to send g-code, False to send to upload SD card
		"""

		self._logger.debug("FlashForge.writeraw() called by thread {}".format(threading.currentThread().getName()))

		try:
			self._handle.bulkWrite(self._usb_cmd_endpoint_out if command else self._usb_sd_endpoint_out, data)
			return len(data)
		except usb1.USBError as usberror:
			raise FlashForgeError('USB Error writeraw()', usberror) 
开发者ID:Mrnt,项目名称:OctoPrint-FlashForge,代码行数:16,代码来源:flashforge.py

示例8: readraw

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def readraw(self, timeout=-1):
		"""
		Read everything available from the from the printer

		Returns:
			String containing response from the printer
		"""

		data = b''
		if timeout == -1:
			timeout = int(self._read_timeout * 1000.0)
		self._logger.debug("FlashForge.readraw() called by thread: {}, timeout: {}".format(threading.currentThread().getName(), timeout))

		try:
			# read data from USB until ok signals end or timeout
			while not data.strip().endswith(b"ok"):
				data += self._handle.bulkRead(self._usb_cmd_endpoint_in, self.BUFFER_SIZE, timeout)

		except usb1.USBError as usberror:
			if not usberror.value == -7:  # LIBUSB_ERROR_TIMEOUT:
				raise FlashForgeError("USB Error readraw()", usberror)
			else:
				self._logger.debug("FlashForge.readraw() error: {}".format(usberror))

		self._logger.debug("FlashForge.readraw() {}".format(data.decode().replace("\r\n", " | ")))
		return data 
开发者ID:Mrnt,项目名称:OctoPrint-FlashForge,代码行数:28,代码来源:flashforge.py

示例9: usb_info

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def usb_info(self):
    try:
      sn = self.serial_number
    except libusb1.USBError:
      sn = ''
    if sn and sn != self._usb_info and self._usb_info:
      return '%s %s' % (self._usb_info, sn)
    return self._usb_info 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:common.py

示例10: Reset

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def Reset(self):
    if self._handle is None:
      return
    try:
      self._handle.resetDevice()
    except libusb1.USBError as e:
      _LOG.error('Could not reset device %s: %s', self.port_path_str, e)
      self.Close() 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:common.py

示例11: BulkWrite

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def BulkWrite(self, data, timeout_ms=None):
    if self._handle is None:
      raise usb_exceptions.WriteFailedError(
          'This handle has been closed, probably due to another being opened.',
          None)
    try:
      return self._handle.bulkWrite(
          self._write_endpoint, data, timeout=self.Timeout(timeout_ms))
    except libusb1.USBError as e:
      raise usb_exceptions.WriteFailedError(
          'Could not send data to %s (timeout %sms)' % (
              self.usb_info, self.Timeout(timeout_ms)), e) 
开发者ID:luci,项目名称:luci-py,代码行数:14,代码来源:common.py

示例12: FindDevicesSafe

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [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

示例13: close

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def close(self):
        """Close the USB connection.

        """
        if self._transport is None:
            return
        try:
            self._transport.releaseInterface(self._interface_number)
            self._transport.close()
        except usb1.USBError:
            _LOGGER.info('USBError while closing transport %s: ', self.usb_info, exc_info=True)
        finally:
            self._transport = None 
开发者ID:JeffLIrion,项目名称:adb_shell,代码行数:15,代码来源:usb_transport.py

示例14: bulk_read

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def bulk_read(self, numbytes, transport_timeout_s=None):
        """Receive data from the USB device.

        Parameters
        ----------
        numbytes : int
            The maximum amount of data to be received
        transport_timeout_s : float, None
            When the timeout argument is omitted, ``select.select`` blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.

        Returns
        -------
        bytes
            The received data

        Raises
        ------
        adb_shell.exceptions.UsbReadFailedError
            Could not receive data

        """
        if self._transport is None:
            raise exceptions.UsbReadFailedError('This transport has been closed, probably due to another being opened.', None)
        try:
            # python-libusb1 > 1.6 exposes bytearray()s now instead of bytes/str.
            # To support older and newer versions, we ensure everything's bytearray()
            # from here on out.
            return bytes(self._transport.bulkRead(self._read_endpoint, numbytes, timeout=self._timeout_ms(transport_timeout_s)))
        except usb1.USBError as e:
            raise exceptions.UsbReadFailedError('Could not receive data from %s (timeout %sms)' % (self.usb_info, self._timeout_ms(transport_timeout_s)), e) 
开发者ID:JeffLIrion,项目名称:adb_shell,代码行数:32,代码来源:usb_transport.py

示例15: bulk_write

# 需要导入模块: import usb1 [as 别名]
# 或者: from usb1 import USBError [as 别名]
def bulk_write(self, data, transport_timeout_s=None):
        """Send data to the USB device.

        Parameters
        ----------
        data : bytes
            The data to be sent
        transport_timeout_s : float, None
            When the timeout argument is omitted, ``select.select`` blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.

        Returns
        -------
        int
            The number of bytes sent

        Raises
        ------
        adb_shell.exceptions.UsbWriteFailedError
            This transport has been closed, probably due to another being opened
        adb_shell.exceptions.UsbWriteFailedError
            Could not send data

        """
        if self._transport is None:
            raise exceptions.UsbWriteFailedError('This transport has been closed, probably due to another being opened.', None)

        try:
            return self._transport.bulkWrite(self._write_endpoint, data, timeout=self._timeout_ms(transport_timeout_s))

        except usb1.USBError as e:
            raise exceptions.UsbWriteFailedError('Could not send data to %s (timeout %sms)' % (self.usb_info, self._timeout_ms(transport_timeout_s)), e) 
开发者ID:JeffLIrion,项目名称:adb_shell,代码行数:33,代码来源:usb_transport.py


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