當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。