def BulkRead(self, length, timeout_ms=None): if self._handle is None: raise usb_exceptions.ReadFailedError( 'This handle has been closed, probably due to another being opened.', None) try: return self._handle.bulkRead( self._read_endpoint, length, timeout=self.Timeout(timeout_ms)) except libusb1.USBError as e: raise usb_exceptions.ReadFailedError( 'Could not receive data from %s (timeout %sms)' % ( self.usb_info, self.Timeout(timeout_ms)), e)
def BulkRead(self, length, timeout_ms=None): if self._handle is None: raise usb_exceptions.ReadFailedError( 'This handle 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 bytearray(self._handle.bulkRead( self._read_endpoint, length, timeout=self.Timeout(timeout_ms))) except libusb1.USBError as e: raise usb_exceptions.ReadFailedError( 'Could not receive data from %s (timeout %sms)' % ( self.usb_info, self.Timeout(timeout_ms)), e)
def BulkRead(self, length, timeout_ms=None): # pylint: disable=unused-argument with self._lock: if not self._expected_io: raise usb_exceptions.ReadFailedError(None, None) # pragma: no cover if self._expected_io[0][0] != 'read': # Nothing to read for now. raise usb_exceptions.ReadFailedError(None, None) # pragma: no cover data = self._expected_io.pop(0)[1] if length < len(data): raise ValueError( 'Unexpected read length. Read %d bytes, got %d bytes' % (length, len(data))) # pragma: no cover return data
def BulkWrite(self, data, timeout_ms=None): try: self._connection.settimeout(self.Timeout(timeout_ms) / 1000.0) return self._connection.sendall(data) except socket.timeout as e: raise usb_exceptions.ReadFailedError( 'Could not send data (timeout %sms)' % (self.Timeout(timeout_ms)), e)
def BulkRead(self, length, timeout_ms=None): try: self._connection.settimeout(self.Timeout(timeout_ms) / 1000.0) return self._connection.recv(length) except socket.timeout as e: raise usb_exceptions.ReadFailedError( 'Could not receive data (timeout %sms)' % ( self.Timeout(timeout_ms)), e)