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

Petr Jakes petr at tpc.cz
Sat Nov 12 18:20:50 EST 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:
http://www.lothosoft.ch/thomas/libmip/markspaceparity.php
=======================================
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.

Regards

Petr Jakes




More information about the Python-list mailing list