diff options
Diffstat (limited to 'serial/urlhandler')
-rw-r--r-- | serial/urlhandler/protocol_loop.py | 42 | ||||
-rw-r--r-- | serial/urlhandler/protocol_socket.py | 36 |
2 files changed, 52 insertions, 26 deletions
diff --git a/serial/urlhandler/protocol_loop.py b/serial/urlhandler/protocol_loop.py index 7da94ad..a414839 100644 --- a/serial/urlhandler/protocol_loop.py +++ b/serial/urlhandler/protocol_loop.py @@ -36,8 +36,10 @@ class LoopbackSerial(SerialBase): 9600, 19200, 38400, 57600, 115200) def open(self): - """Open port with current settings. This may throw a SerialException - if the port cannot be opened.""" + """\ + Open port with current settings. This may throw a SerialException + if the port cannot be opened. + """ if self._isOpen: raise SerialException("Port is already open.") self.logger = None @@ -63,8 +65,10 @@ class LoopbackSerial(SerialBase): self.flushOutput() def _reconfigurePort(self): - """Set communication parameters on opened port. for the loop:// - protocol all settings are ignored!""" + """\ + Set communication parameters on opened port. For the loop:// + protocol all settings are ignored! + """ # not that's it of any real use, but it helps in the unit tests if not isinstance(self._baudrate, (int, long)) or not 0 < self._baudrate < 2**32: raise ValueError("invalid baudrate: %r" % (self._baudrate)) @@ -115,9 +119,11 @@ class LoopbackSerial(SerialBase): return len(self.loop_buffer) def read(self, size=1): - """Read size bytes from the serial port. If a timeout is set it may + """\ + 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.""" + until the requested number of bytes is read. + """ if not self._isOpen: raise portNotOpenError if self._timeout is not None: timeout = time.time() + self._timeout @@ -140,9 +146,11 @@ class LoopbackSerial(SerialBase): return bytes(data) def write(self, data): - """Output the given string over the serial port. Can block if the + """\ + Output the given string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is - closed.""" + closed. + """ if not self._isOpen: raise portNotOpenError # ensure we're working with bytes data = to_bytes(data) @@ -172,20 +180,26 @@ class LoopbackSerial(SerialBase): self.buffer_lock.release() def flushOutput(self): - """Clear output buffer, aborting the current output and - discarding all that is in the buffer.""" + """\ + Clear output buffer, aborting the current output and + discarding all that is in the buffer. + """ if not self._isOpen: raise portNotOpenError if self.logger: self.logger.info('flushOutput()') def sendBreak(self, duration=0.25): - """Send break condition. Timed, returns to idle state after given - duration.""" + """\ + Send break condition. Timed, returns to idle state after given + duration. + """ if not self._isOpen: raise portNotOpenError def setBreak(self, level=True): - """Set break: Controls TXD. When active, to transmitting is - possible.""" + """\ + Set break: Controls TXD. When active, to transmitting is + possible. + """ if not self._isOpen: raise portNotOpenError if self.logger: self.logger.info('setBreak(%r)' % (level,)) diff --git a/serial/urlhandler/protocol_socket.py b/serial/urlhandler/protocol_socket.py index 09a23d0..41e59b1 100644 --- a/serial/urlhandler/protocol_socket.py +++ b/serial/urlhandler/protocol_socket.py @@ -39,8 +39,10 @@ class SocketSerial(SerialBase): 9600, 19200, 38400, 57600, 115200) def open(self): - """Open port with current settings. This may throw a SerialException - if the port cannot be opened.""" + """\ + Open port with current settings. This may throw a SerialException + if the port cannot be opened. + """ self.logger = None if self._port is None: raise SerialException("Port must be configured before it can be used.") @@ -67,8 +69,10 @@ class SocketSerial(SerialBase): self.flushOutput() def _reconfigurePort(self): - """Set communication parameters on opened port. for the socket:// - protocol all settings are ignored!""" + """\ + Set communication parameters on opened port. For the socket:// + protocol all settings are ignored! + """ if self._socket is None: raise SerialException("Can only operate on open ports") if self.logger: @@ -132,9 +136,11 @@ class SocketSerial(SerialBase): return 0 # hmmm, see comment in read() def read(self, size=1): - """Read size bytes from the serial port. If a timeout is set it may + """\ + 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.""" + until the requested number of bytes is read. + """ if not self._isOpen: raise portNotOpenError data = bytearray() if self._timeout is not None: @@ -163,9 +169,11 @@ class SocketSerial(SerialBase): return bytes(data) def write(self, data): - """Output the given string over the serial port. Can block if the + """\ + Output the given string over the serial port. Can block if the connection is blocked. May raise SerialException if the connection is - closed.""" + closed. + """ if not self._isOpen: raise portNotOpenError try: self._socket.sendall(to_bytes(data)) @@ -181,15 +189,19 @@ class SocketSerial(SerialBase): self.logger.info('ignored flushInput') def flushOutput(self): - """Clear output buffer, aborting the current output and - discarding all that is in the buffer.""" + """\ + Clear output buffer, aborting the current output and + discarding all that is in the buffer. + """ if not self._isOpen: raise portNotOpenError if self.logger: self.logger.info('ignored flushOutput') def sendBreak(self, duration=0.25): - """Send break condition. Timed, returns to idle state after given - duration.""" + """\ + Send break condition. Timed, returns to idle state after given + duration. + """ if not self._isOpen: raise portNotOpenError if self.logger: self.logger.info('ignored sendBreak(%r)' % (duration,)) |