pytty

changeset 28:6b65d84b51b7

Added TTY.stops property
author Arc Riley <arcriley@gmail.com>
date Tue, 10 Jul 2012 03:38:18 -0400
parents 0c10d2151b79
children 10bc49064475
files src/__init__.py
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/src/__init__.py	Tue Jul 10 03:23:28 2012 -0400
     1.2 +++ b/src/__init__.py	Tue Jul 10 03:38:18 2012 -0400
     1.3 @@ -173,5 +173,28 @@
     1.4                      raise IOError("Parity must be 'N', 'E', or 'O'.")
     1.5              termios.tcsetattr(fd, termios.TCSANOW, tc)
     1.6  
     1.7 +    @property
     1.8 +    def stops (self) :
     1.9 +        '''Number of stop bits
    1.10 +
    1.11 +    How many stop bits follow a byte, either 1 or 2.
    1.12 +        '''
    1.13 +        import termios
    1.14 +        cflag = termios.tcgetattr(self._fdi)[2]
    1.15 +        return (1, 2)[termios.tcgetattr(self._fdi)[2] & termios.CSTOPB and 1]
    1.16 +
    1.17 +    @stops.setter
    1.18 +    def stops (self, value) :
    1.19 +        import termios
    1.20 +        for fd in (self._fdi, self._fdo) :
    1.21 +            tc = termios.tcgetattr(fd)
    1.22 +            if value == 1 :
    1.23 +                tc[2] &= ~termios.CSTOPB
    1.24 +            elif value == 2 :
    1.25 +                tc[2] &= termios.CSTOPB
    1.26 +            else :
    1.27 +                raise IOError('Stop bits must be either 1 or 2.')
    1.28 +            termios.tcsetattr(fd, termios.TCSANOW, tc)
    1.29 +
    1.30  # Clean up package namespace
    1.31  del(io)