Skip to content

Commit daaf33e

Browse files
committed
Documented read_until and updated parameter name to reflect functionality beyond just line terminators.
1 parent d7ae8f6 commit daaf33e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

documentation/pyserial_api.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ Native ports
157157
Returns an instance of :class:`bytes` when available (Python 2.6
158158
and newer) and :class:`str` otherwise.
159159

160+
.. method:: read_until(expected=LF, size=None)
161+
162+
:param expected: The byte string to search for.
163+
:param size: Number of bytes to read.
164+
:return: Bytes read from the port.
165+
:rtype: bytes
166+
167+
Read until an expected sequence is found ('\n' by default), the size
168+
is exceeded or until timeout occurs. If a timeout is set it may
169+
return less characters as requested. With no timeout it will block
170+
until the requested number of bytes is read.
171+
172+
.. versionchanged:: 2.5
173+
Returns an instance of :class:`bytes` when available (Python 2.6
174+
and newer) and :class:`str` otherwise.
175+
160176
.. method:: write(data)
161177

162178
:param data: Data to send.

serial/serialutil.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,19 +649,19 @@ def read_all(self):
649649
"""
650650
return self.read(self.in_waiting)
651651

652-
def read_until(self, terminator=LF, size=None):
652+
def read_until(self, expected=LF, size=None):
653653
"""\
654-
Read until a termination sequence is found ('\n' by default), the size
654+
Read until an expected sequence is found ('\n' by default), the size
655655
is exceeded or until timeout occurs.
656656
"""
657-
lenterm = len(terminator)
657+
lenterm = len(expected)
658658
line = bytearray()
659659
timeout = Timeout(self._timeout)
660660
while True:
661661
c = self.read(1)
662662
if c:
663663
line += c
664-
if line[-lenterm:] == terminator:
664+
if line[-lenterm:] == expected:
665665
break
666666
if size is not None and len(line) >= size:
667667
break

0 commit comments

Comments
 (0)