Started by margadon, November 20, 2015, 04:06:56 pm
def read(self, size=1): """Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.""" if not self._isOpen: raise portNotOpenError read = bytearray() while len(read) < size: try: ready,_,_ = select.select([self.fd],,, self._timeout) # If select was used with a timeout, and the timeout occurs, it # returns with empty lists -> thus abort read operation. # For timeout == 0 (non-blocking operation) also abort when there # is nothing to read. if not ready: break # timeout buf = os.read(self.fd, size-len(read)) # read should always return some data as select reported it was # ready to read when we get to this point. if not buf: # Disconnected devices, at least on Linux, show the # behavior that they are always ready to read immediately # but reading returns nothing. raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)') read.extend(buf) except select.error, e: # ignore EAGAIN errors. all other errors are shown # see also http://www.python.org/dev/peps/pep-3151/#select if e != errno.EAGAIN: raise SerialException('read failed: %s' % (e,)) except OSError, e: # ignore EAGAIN errors. all other errors are shown if e.errno != errno.EAGAIN: raise SerialException('read failed: %s' % (e,)) return bytes(read) def write(self, data): """Output the given string over the serial port.""" if not self._isOpen: raise portNotOpenError d = to_bytes(data) tx_len = len(d) if self._writeTimeout is not None and self._writeTimeout > 0: timeout = time.time() + self._writeTimeout else: timeout = None while tx_len > 0: try: n = os.write(self.fd, d) if timeout: # when timeout is set, use select to wait for being ready # with the time left as timeout timeleft = timeout - time.time() if timeleft < 0: raise writeTimeoutError _, ready, _ = select.select(, [self.fd], , timeleft) if not ready: raise writeTimeoutError else: # wait for write operation _, ready, _ = select.select(, [self.fd], , None) if not ready: raise SerialException('write failed (select)') d = d[n:] tx_len -= n except OSError, v: if v.errno != errno.EAGAIN: raise SerialException('write failed: %s' % (v,)) return len(data)
QuoteYou've not left the cpu governor unchanged I hope...Various settings are utterly useless. (google...)
Quoteif you want minimal response times, use the performance governor, it will keep the CPU on maximum clock speed.