#111 Can't change line ending type with RawIOBase derived Serial


As it noted in the documentation, with sufficiently new python versions the Serial class will inherit from RawIOBase. The readline implementation of RawIOBase does not allow the eol keyword argument to be passed, instead deriving its line ending from the newline keyword argument passed to the constructor. Unfortunately, the Serial constructor does not have a newline keyword argument. This is a severe regression.

While the RawIOBase approach is acceptable for some cases, it is convenient to be able to choose delimiters on a case-by-case basis when working with many serial devices. For this reason, it would be nice if a readuntil function were implemented in the Serial class, allowing one to easily read until some delimiting sequence (e.g. the old behavior of readline).


  • Chris Liechti

    Chris Liechti - 2011-11-02

    looking for lines implies that it is a text based protocol. in that case the encoding should also be considered.

    the io module provides filter classes that cope with both problems: eg. io.TextIOWrapper translates a raw stream (such as pySerial's port) to a text based stream including EOL handling.

    see also test/test_iolib.py

    Regarding eol keyword for the Serial class:
    As I see it, it is in line with other classes provided by the io module. RawIO streams do not have an eol or newline parameter (e.g. see io.FileIO) and the eol character for the readline functions of raw streams is always '\n'. pySerials Serial class is a RawIO stream and therefore behaves as expected.

  • Chris Liechti

    Chris Liechti - 2011-11-02
    • status: open --> pending-rejected
  • Chris Liechti

    Chris Liechti - 2013-10-17
    • status: pending-rejected --> closed-rejected
    • assigned_to: Chris Liechti
    • Group: --> v2.6

Log in to post a comment.