UART parity setting as "mark" or "space" (using Pyserial???)

Petr Jakes petr at
Sun Nov 13 00:20:50 CET 2005

To provide feedback:

I have found the way how to control serial port parity bit on the Linux
(how to set the parity bit to the "mark" or "space" parity) within
Python using termios module.

With the help of:
import serial
import termios
import TERMIOS

ser=serial.Serial('/dev/ttyS0', 9600, 8, "N", timeout=1)

iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(ser)

cflag |= PARENB | CMSPAR # To select SPACE parity
cflag &= ~PARODD

cflag |= PARENB | CMSPAR | PARODD # to select MARK parity

termios.tcsetattr(ser, termios.TCSANOW, [iflag, oflag, cflag, lflag,
ispeed, ospeed, cc])
Using above mentioned it is possible to establish 9bit serial
communication according to the given protocol specifics. It is
necessary to control parity bit setting before sending each
communication byte.


Petr Jakes

More information about the Python-list mailing list