Non-POSIX parity (mark/space) with Python-Serial on Linux.

Chris Angelico rosuav at gmail.com
Mon Nov 21 11:41:01 EST 2011


On Tue, Nov 22, 2011 at 3:28 AM, Matthew Lenz <matthew at nocturnal.org> wrote:
> Using 8N1 under minicom with this device resulted in garbled text when once connected.  Connection using 7M1 resulted in the correct text.  So there must be something else that needs to be done in my python program correct?

Using 8N1 when it's really 7M1 means you have the high bit set on
every byte. I don't know if there's an easy way to do this fast in
Python, but what you need to do is mask them all off... I'm not sure
if there's a better way, but this ought to work:

string = "".join(chr(ord(x)&0x7f) for x in string)

In Python 3, iterating over a 'bytes' string produces integers, so
omit the ord() call. Other than that, code is not tested.

ChrisA



More information about the Python-list mailing list