コード例 #1
0
 def get_packet(self, deadline):
     try:
         bufferLen = self.epr.wMaxPacketSize
         timeout = max(int((deadline - time.monotonic()) * 1000), 0)
         ret = self.epr.read(bufferLen, timeout)
         if self._was_damaged:
             self._logger.debug("Recovered from USB halt/stall condition")
             self._was_damaged = False
         return bytearray(ret)
     except usb.core.USBError as ex:
         if ex.errno == 19 or ex.errno == 32:  # "no such device", "pipe error"
             raise fibre.protocol.ChannelBrokenException()
         elif ex.errno is None or ex.errno == 60 or ex.errno == 110:  # timeout
             raise TimeoutError()
         else:
             self._logger.debug(
                 "error in usbbulk_transport.py, process_packet")
             self._logger.debug(traceback.format_exc())
             self._logger.debug("halt condition: {}".format(ex.errno))
             self._logger.debug(str(ex))
             # Try resetting halt/stall condition
             try:
                 self.deinit()
                 self.init()
             except usb.core.USBError:
                 raise fibre.protocol.ChannelBrokenException()
             # Retry transfer
             self._was_damaged = True
             raise fibre.protocol.ChannelDamagedException()
コード例 #2
0
 def process_packet(self, usbBuffer):
     try:
         ret = self.epw.write(usbBuffer, 0)
         if self._was_damaged:
             self._logger.debug("Recovered from USB halt/stall condition")
             self._was_damaged = False
         return ret
     except usb.core.USBError as ex:
         if ex.errno == 19 or ex.errno == 32:  # "no such device", "pipe error"
             raise fibre.protocol.ChannelBrokenException()
         elif ex.errno is None or ex.errno == 60 or ex.errno == 110:  # timeout
             raise TimeoutError()
         else:
             self._logger.debug(
                 "error in usbbulk_transport.py, process_packet")
             self._logger.debug(traceback.format_exc())
             self._logger.debug("halt condition: {}".format(ex.errno))
             self._logger.debug(str(ex))
             # Try resetting halt/stall condition
             try:
                 self.deinit()
                 self.init()
             except usb.core.USBError:
                 raise fibre.protocol.ChannelBrokenException()
             # Retry transfer
             self._was_damaged = True
             raise fibre.protocol.ChannelDamagedException()
コード例 #3
0
ファイル: tcp_transport.py プロジェクト: zytra/ODrive
 def get_bytes_or_fail(self, n_bytes, deadline):
     result = self.get_bytes(n_bytes, deadline)
     if len(result) < n_bytes:
         raise TimeoutError("expected {} bytes but got only {}".format(
             n_bytes, len(result)))
     return result