pytty

changeset 27:0c10d2151b79

Added TTY.parity property.
author Arc Riley <arcriley@gmail.com>
date Tue, 10 Jul 2012 03:23:28 -0400
parents 381984878a49
children 6b65d84b51b7
files src/__init__.py
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/src/__init__.py	Mon Jul 09 04:43:33 2012 -0400
     1.2 +++ b/src/__init__.py	Tue Jul 10 03:23:28 2012 -0400
     1.3 @@ -145,5 +145,33 @@
     1.4              tc[2] &= cs
     1.5              termios.tcsetattr(fd, termios.TCSANOW, tc)
     1.6  
     1.7 +    @property
     1.8 +    def parity (self) :
     1.9 +        '''Parity bit
    1.10 +
    1.11 +    This may be set to 'N' (none), 'E' (even), or 'O' (odd).
    1.12 +        '''
    1.13 +        import termios
    1.14 +        cflag = termios.tcgetattr(self._fdi)[2]
    1.15 +        return ((('N', 'N'), ('E', 'O'))
    1.16 +                [cflag & termios.PARENB and 1][cflag & termios.PARODD and 1])
    1.17 +
    1.18 +    @parity.setter
    1.19 +    def parity (self, value) :
    1.20 +        import termios
    1.21 +        for fd in (self._fdi, self._fdo) :
    1.22 +            tc = termios.tcgetattr(fd)
    1.23 +            if value in 'Nn' :
    1.24 +                tc[2] &= ~termios.PARENB
    1.25 +            else :
    1.26 +                tc[2] |= termios.PARENB
    1.27 +                if value in 'Ee' :
    1.28 +                    tc[2] &= ~termios.PARODD
    1.29 +                elif value in 'Oo' :
    1.30 +                    tc[2] |= termios.PARODD
    1.31 +                else :
    1.32 +                    raise IOError("Parity must be 'N', 'E', or 'O'.")
    1.33 +            termios.tcsetattr(fd, termios.TCSANOW, tc)
    1.34 +
    1.35  # Clean up package namespace
    1.36  del(io)