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

Discussion in 'Python' started by Petr Jakes, Nov 3, 2005.

  1. Petr Jakes

    Petr Jakes Guest

    Hi,

    I am trying to set-up communication to the coin change-giver from my
    Linux box using the Python code. The change giver uses MDB (Multi Drop
    Bus) serial protocol to communicate with the master. MDB protocol is
    the 9bit serial protocol:
    (TX, RX lines only) 9600bps, 9bits, No Parity, 1 Start, 1 Stop.

    I would like to control the UART "parity bit" to try to simulate 9bit
    communication.

    Using Pyserial it is possible to set the parity bit as ODD, EVEN or
    NONE.

    I have found in the following link (paragraph 21.3)
    http://howtos.linux.com/howtos/Serial-HOWTO-21.shtml#ss21.1
    that UART hardware supports two "rarely used" parity settings as well:
    mark parity and space parity (these setings are also known as "sticky
    parity")

    A "mark" is a 1-bit (or logic 1) and a "space" is a 0-bit (or logic 0).
    For mark parity, the parity bit is always a one-bit. For space parity
    it's always a zero-bit.

    Does anybody here knows some "tricks" how to set up the mark and space
    parity on the UART (using pyserial???), so I can simulate 9bit
    communication? (I know it sounds silly, but I would like to try to
    re-configure the UART parity before each byte transmission).

    Any comment will be appreciated.

    Petr Jakes
    Petr Jakes, Nov 3, 2005
    #1
    1. Advertising

  2. On 2005-11-03, Petr Jakes <> wrote:

    > Using Pyserial it is possible to set the parity bit as ODD, EVEN or
    > NONE.


    Correct. Those are the parity settings supported by pretty
    much all platforms.

    [...]

    > Does anybody here knows some "tricks" how to set up the mark
    > and space parity on the UART (using pyserial???),


    What OS? Mark and space parity are not supported by the Unix
    termios API that is used to do serial port stuff.

    > so I can simulate 9bit communication? (I know it sounds silly,
    > but I would like to try to re-configure the UART parity before
    > each byte transmission).


    I suspect you're going to have to talk to the UART yourself to
    do this.

    In addition to the problem with mark/space being unsupported,
    you have to wait until each byte is completely sent (including
    the parity bit) before changing the parity and loading the next
    byte into the data register. Many OSes "drain" functions are
    notoriously inaccurate.

    --
    Grant Edwards grante Yow! Did I say I was a
    at sardine? Or a bus???
    visi.com
    Grant Edwards, Nov 4, 2005
    #2
    1. Advertising

  3. Petr Jakes

    Petr Jakes Guest

    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
    Petr Jakes, Nov 12, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,884
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,649
    Stephen Horne
    Oct 27, 2003
  3. Replies:
    2
    Views:
    2,300
    Eric Smith
    May 21, 2007
  4. Cirene
    Replies:
    5
    Views:
    579
    Cirene
    May 17, 2008
  5. Replies:
    23
    Views:
    817
    Chris Angelico
    Nov 22, 2011
Loading...

Share This Page