Logo Search packages:      
Sourcecode: qmk-groundstation version File versions  Download package

void Posix_QextSerialPort::setParity ( ParityType  parity  )  [virtual]

Sets the parity associated with the serial port. The possible values of parity are:

		PAR_SPACE       Space Parity
		PAR_MARK        Mark Parity
		PAR_NONE        No Parity
		PAR_EVEN        Even Parity
		PAR_ODD         Odd Parity
		

Note:
This function is subject to the following limitations:
POSIX systems do not support mark parity.
POSIX systems support space parity only if tricked into doing so, and only with fewer than 8 data bits. Use space parity very carefully with POSIX systems.

Implements QextSerialBase.

Definition at line 603 of file posix_qextserialport.cpp.

Referenced by open(), and Posix_QextSerialPort().

{
      LOCK_MUTEX();
      if (Settings.Parity!=parity) {
            if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) {
            }
            else {
                  Settings.Parity=parity;
            }
      }
      if (isOpen()) {
            switch (parity) {
                        
                        /*space parity*/
                  case PAR_SPACE:
                        if (Settings.DataBits==DATA_8) {
                              TTY_PORTABILITY_WARNING("Posix_QextSerialPort:  Space parity is only supported in POSIX with 7 or fewer data bits");
                        }
                        else {
                              
                              /*space parity not directly supported - add an extra data bit to simulate it*/
                              Posix_CommConfig.c_cflag&=~(PARENB|CSIZE);
                        switch(Settings.DataBits) {
                              case DATA_5:
                                    Settings.DataBits=DATA_6;
                                    Posix_CommConfig.c_cflag|=CS6;
                                    break;
                                    
                              case DATA_6:
                                    Settings.DataBits=DATA_7;
                                    Posix_CommConfig.c_cflag|=CS7;
                                    break;
                                    
                              case DATA_7:
                                    Settings.DataBits=DATA_8;
                                    Posix_CommConfig.c_cflag|=CS8;
                                    break;
                                    
                              case DATA_8:
                                    break;
                              }
                              tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
                        }
                        break;
                        
                        /*mark parity - WINDOWS ONLY*/
                  case PAR_MARK:
                        TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX.");
                        break;
                        
                        /*no parity*/
                  case PAR_NONE:
                        Posix_CommConfig.c_cflag&=(~PARENB);
                        tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
                        break;
                        
                        /*even parity*/
                  case PAR_EVEN:
                        Posix_CommConfig.c_cflag&=(~PARODD);
                        Posix_CommConfig.c_cflag|=PARENB;
                        tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
                        break;
                        
                        /*odd parity*/
                  case PAR_ODD:
                        Posix_CommConfig.c_cflag|=(PARENB|PARODD);
                        tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
                        break;
                  }
      }
      UNLOCK_MUTEX();
}


Generated by  Doxygen 1.6.0   Back to index