Posix_QextSerialPort Class Reference

#include <posix_qextserialport.h>

Inheritance diagram for Posix_QextSerialPort:

QextSerialBase QIODevice QextBaseType QextSerialPort List of all members.

Public Types

 EventDriven
 Polling
enum  QueryMode { Polling, EventDriven }

Signals

void dsrChanged (bool status)

Public Member Functions

 aboutToClose ()
 atEnd ()
virtual bool atEnd () const
virtual BaudRateType baudRate () const
virtual qint64 bytesAvailable ()
 bytesToWrite ()
 bytesWritten (qint64 bytes)
 canReadLine ()
virtual void close ()
virtual void construct ()
virtual DataBitsType dataBits () const
 errorString ()
virtual FlowType flowControl () const
virtual void flush ()
 getChar (char *c)
 isOpen ()
 isReadable ()
 isSequential ()
virtual bool isSequential () const
 isTextModeEnabled ()
 isWritable ()
virtual ulong lastError () const
virtual ulong lineStatus ()
virtual bool open (OpenMode mode)
 openMode ()
Posix_QextSerialPortoperator= (const Posix_QextSerialPort &s)
virtual ParityType parity () const
 peek (qint64 maxSize)
 peek (char *data, qint64 maxSize)
virtual QString portName () const
 pos ()
 Posix_QextSerialPort (const QString &name, const PortSettings &settings, QextSerialBase::QueryMode mode=QextSerialBase::Polling)
 Posix_QextSerialPort (const PortSettings &settings, QextSerialBase::QueryMode mode=QextSerialBase::Polling)
 Posix_QextSerialPort (const QString &name, QextSerialBase::QueryMode mode=QextSerialBase::Polling)
 Posix_QextSerialPort (const Posix_QextSerialPort &s)
 Posix_QextSerialPort ()
 putChar (char c)
QextSerialBase::QueryMode queryMode () const
 read (qint64 maxSize)
 read (char *data, qint64 maxSize)
 readAll ()
 readLine (qint64 maxSize=0)
virtual qint64 readLine (char *data, qint64 maxSize)
 readLineData (char *data, qint64 maxSize)
 readyRead ()
 reset ()
 seek (qint64 pos)
virtual void setBaudRate (BaudRateType)
virtual void setDataBits (DataBitsType)
virtual void setDtr (bool set=true)
 setErrorString (const QString &str)
virtual void setFlowControl (FlowType)
 setOpenMode (OpenMode openMode)
virtual void setParity (ParityType)
virtual void setPortName (const QString &name)
virtual void setQueryMode (QueryMode mode)
virtual void setRts (bool set=true)
virtual void setStopBits (StopBitsType)
 setTextModeEnabled (bool enabled)
virtual void setTimeout (ulong, ulong)
 size ()
virtual qint64 size () const
virtual StopBitsType stopBits () const
virtual void translateError (ulong error)
virtual void ungetChar (char c)
 waitForBytesWritten (int msecs)
 waitForReadyRead (int msecs)
 write (const QByteArray &byteArray)
 write (const char *data, qint64 maxSize)
virtual ~Posix_QextSerialPort ()

Protected Member Functions

virtual qint64 readData (char *data, qint64 maxSize)
virtual qint64 writeData (const char *data, qint64 maxSize)

Protected Attributes

QextSerialBase::QueryMode _queryMode
ulong lastErr
QMutex * mutex
QString port
termios Posix_CommConfig
timeval Posix_Copy_Timeout
QFile * Posix_File
timeval Posix_Timeout
PortSettings Settings

Private Member Functions

void init ()

Detailed Description

Version:
1.0.0
Author:
Stefan Sander

Michal Policht

A cross-platform serial port class. This class encapsulates the POSIX portion of QextSerialPort. The user will be notified of errors and possible portability conflicts at run-time by default - this behavior can be turned off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off portability warnings) in the project. Note that _TTY_NOWARN_ will also turn off portability warnings.


Member Enumeration Documentation

enum QextSerialBase::QueryMode [inherited]

Enumerator:
Polling 
EventDriven 

Reimplemented in QextSerialPort.

00154                        {
00155             Polling,
00156             EventDriven
00157         };


Constructor & Destructor Documentation

Posix_QextSerialPort::Posix_QextSerialPort (  ) 

Default constructor. Note that the name of the device used by a QextSerialPort constructed with this constructor will be determined by defined constants, or lack thereof - the default behavior is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are:

Constant         Used By         Naming Convention
----------       -------------   ------------------------
_TTY_WIN_        Windows         COM1, COM2
_TTY_IRIX_       SGI/IRIX        /dev/ttyf1, /dev/ttyf2
_TTY_HPUX_       HP-UX           /dev/tty1p0, /dev/tty2p0
_TTY_SUN_        SunOS/Solaris   /dev/ttya, /dev/ttyb
_TTY_DIGITAL_    Digital UNIX    /dev/tty01, /dev/tty02
_TTY_FREEBSD_    FreeBSD         /dev/ttyd0, /dev/ttyd1
_TTY_LINUX_      Linux           /dev/ttyS0, /dev/ttyS1
<none>           Linux           /dev/ttyS0, /dev/ttyS1

This constructor assigns the device name to the name of the first port on the specified system. See the other constructors if you need to open a different port.

00042 : QextSerialBase()
00043 {
00044     Posix_File=new QFile();
00045 }

Posix_QextSerialPort::Posix_QextSerialPort ( const Posix_QextSerialPort s  ) 

Copy constructor.

00052  : QextSerialBase(s.port)
00053 {
00054     setOpenMode(s.openMode());
00055     port = s.port;
00056     Settings.BaudRate=s.Settings.BaudRate;
00057     Settings.DataBits=s.Settings.DataBits;
00058     Settings.Parity=s.Settings.Parity;
00059     Settings.StopBits=s.Settings.StopBits;
00060     Settings.FlowControl=s.Settings.FlowControl;
00061     lastErr=s.lastErr;
00062 
00063     Posix_File=new QFile();
00064     Posix_File=s.Posix_File;
00065     memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval));
00066     memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval));
00067     memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios));
00068 }

Posix_QextSerialPort::Posix_QextSerialPort ( const QString &  name,
QextSerialBase::QueryMode  mode = QextSerialBase::Polling 
)

00077  : QextSerialBase(name)
00078 {
00079     Posix_File=new QFile();
00080     setQueryMode(mode);
00081     init();
00082 }

Posix_QextSerialPort::Posix_QextSerialPort ( const PortSettings settings,
QextSerialBase::QueryMode  mode = QextSerialBase::Polling 
)

00089  : QextSerialBase()
00090 {
00091     setBaudRate(settings.BaudRate);
00092     setDataBits(settings.DataBits);
00093     setParity(settings.Parity);
00094     setStopBits(settings.StopBits);
00095     setFlowControl(settings.FlowControl);
00096 
00097     Posix_File=new QFile();
00098     setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
00099     setQueryMode(mode);
00100     init();
00101 }

Posix_QextSerialPort::Posix_QextSerialPort ( const QString &  name,
const PortSettings settings,
QextSerialBase::QueryMode  mode = QextSerialBase::Polling 
)

00108  : QextSerialBase(name)
00109 {
00110     setBaudRate(settings.BaudRate);
00111     setDataBits(settings.DataBits);
00112     setParity(settings.Parity);
00113     setStopBits(settings.StopBits);
00114     setFlowControl(settings.FlowControl);
00115 
00116     Posix_File=new QFile();
00117     setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
00118     setQueryMode(mode);
00119     init();
00120 }

Posix_QextSerialPort::~Posix_QextSerialPort (  )  [virtual]

Standard destructor.

00155 {
00156     if (isOpen()) {
00157         close();
00158     }
00159     Posix_File->close();
00160     delete Posix_File;
00161 }


Member Function Documentation

bool QextSerialBase::atEnd (  )  const [virtual, inherited]

This function will return true if the input buffer is empty (or on error), and false otherwise. Call QextSerialBase::lastError() for error information.

00164 {
00165     if (size()) {
00166         return true;
00167     }
00168     return false;
00169 }

BaudRateType QextSerialBase::baudRate ( void   )  const [virtual, inherited]

Returns the baud rate of the serial port. For a list of possible return values see the definition of the enum BaudRateType.

00103 {
00104     return Settings.BaudRate;
00105 }

qint64 Posix_QextSerialPort::bytesAvailable (  )  [virtual]

Returns the number of bytes waiting in the port's receive queue. This function will return 0 if the port is not currently open, or -1 on error. Error information can be retrieved by calling Posix_QextSerialPort::getLastError().

Implements QextSerialBase.

00922 {
00923     LOCK_MUTEX();
00924     if (isOpen()) {
00925         int bytesQueued;
00926         fd_set fileSet;
00927         FD_ZERO(&fileSet);
00928         FD_SET(Posix_File->handle(), &fileSet);
00929 
00930         /*on Linux systems the Posix_Timeout structure will be altered by the select() call.
00931           Make sure we use the right timeout values*/
00932         //memcpy(&Posix_Timeout, &Posix_Copy_Timeout, sizeof(struct timeval));
00933         Posix_Timeout = Posix_Copy_Timeout;
00934         int n=select(Posix_File->handle()+1, &fileSet, NULL, &fileSet, &Posix_Timeout);
00935         if (!n) {
00936             lastErr=E_PORT_TIMEOUT;
00937             UNLOCK_MUTEX();
00938             return -1;
00939         }
00940         if (n==-1 || ioctl(Posix_File->handle(), FIONREAD, &bytesQueued)==-1) {
00941             translateError(errno);
00942             UNLOCK_MUTEX();
00943             return -1;
00944         }
00945         lastErr=E_NO_ERROR;
00946         UNLOCK_MUTEX();
00947         return bytesQueued + QIODevice::bytesAvailable();
00948     }
00949     UNLOCK_MUTEX();
00950     return 0;
00951 }

void Posix_QextSerialPort::close (  )  [virtual]

Closes a serial port. This function has no effect if the serial port associated with the class is not currently open.

Implements QextSerialBase.

00878 {
00879     LOCK_MUTEX();
00880     Posix_File->close();
00881     QIODevice::close();
00882     UNLOCK_MUTEX();
00883 }

void QextSerialBase::construct (  )  [virtual, inherited]

Common constructor function for setting up default port settings. (115200 Baud, 8N1, Hardware flow control where supported, otherwise no flow control, and 0 ms timeout).

00062 {
00063     Settings.BaudRate=BAUD115200;
00064     Settings.DataBits=DATA_8;
00065     Settings.Parity=PAR_NONE;
00066     Settings.StopBits=STOP_1;
00067     Settings.FlowControl=FLOW_HARDWARE;
00068     Settings.Timeout_Sec=0;
00069     Settings.Timeout_Millisec=0;
00070     mutex = new QMutex( QMutex::Recursive );
00071     setOpenMode(QIODevice::NotOpen);
00072 }

DataBitsType QextSerialBase::dataBits (  )  const [virtual, inherited]

Returns the number of data bits used by the port. For a list of possible values returned by this function, see the definition of the enum DataBitsType.

00113 {
00114     return Settings.DataBits;
00115 }

void QextSerialBase::dsrChanged ( bool  status  )  [signal, inherited]

This signal is emitted whenever dsr line has changed its state. You may use this signal to check if device is connected.

Parameters:
status true when DSR signal is on, false otherwise.
See also:
lineStatus().

FlowType QextSerialBase::flowControl (  )  const [virtual, inherited]

Returns the type of flow control used by the port. For a list of possible values returned by this function, see the definition of the enum FlowType.

00143 {
00144     return Settings.FlowControl;
00145 }

void Posix_QextSerialPort::flush (  )  [virtual]

Flushes all pending I/O to the serial port. This function has no effect if the serial port associated with the class is not currently open.

Implements QextSerialBase.

00891 {
00892     LOCK_MUTEX();
00893     if (isOpen()) {
00894         Posix_File->flush();
00895     }
00896     UNLOCK_MUTEX();
00897 }

void Posix_QextSerialPort::init (  )  [private]

This method is a part of constructor.

00145 {
00146     if (queryMode() == QextSerialBase::EventDriven)
00147         qWarning("POSIX doesn't have event driven mechanism implemented yet");
00148 }

bool QextSerialBase::isSequential (  )  const [virtual, inherited]

Returns true if device is sequential, otherwise returns false. Serial port is sequential device so this function always returns true. Check QIODevice::isSequential() documentation for more information.

00154 {
00155     return true;
00156 }

ulong QextSerialBase::lastError (  )  const [virtual, inherited]

Returns the code for the last error encountered by the port, or E_NO_ERROR if the last port operation was successful. Possible error codes are:

Error                           Explanation
---------------------------     -------------------------------------------------------------
E_NO_ERROR                      No Error has occured
E_INVALID_FD                    Invalid file descriptor (port was not opened correctly)
E_NO_MEMORY                     Unable to allocate memory tables (POSIX)
E_CAUGHT_NON_BLOCKED_SIGNAL     Caught a non-blocked signal (POSIX)
E_PORT_TIMEOUT                  Operation timed out (POSIX)
E_INVALID_DEVICE                The file opened by the port is not a character device (POSIX)
E_BREAK_CONDITION               The port detected a break condition
E_FRAMING_ERROR                 The port detected a framing error
                                (usually caused by incorrect baud rate settings)
E_IO_ERROR                      There was an I/O error while communicating with the port
E_BUFFER_OVERRUN                Character buffer overrun
E_RECEIVE_OVERFLOW              Receive buffer overflow
E_RECEIVE_PARITY_ERROR          The port detected a parity error in the received data
E_TRANSMIT_OVERFLOW             Transmit buffer overflow
E_READ_FAILED                   General read operation failure
E_WRITE_FAILED                  General write operation failure
00225 {
00226     return lastErr;
00227 }

unsigned long Posix_QextSerialPort::lineStatus ( void   )  [virtual]

returns the line status as stored by the port function. This function will retrieve the states of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned long with specific bits indicating which lines are high. The following constants should be used to examine the states of individual lines:

Mask        Line
------      ----
LS_CTS      CTS
LS_DSR      DSR
LS_DCD      DCD
LS_RI       RI
LS_RTS      RTS (POSIX only)
LS_DTR      DTR (POSIX only)
LS_ST       Secondary TXD (POSIX only)
LS_SR       Secondary RXD (POSIX only)

This function will return 0 if the port associated with the class is not currently open.

Implements QextSerialBase.

01055 {
01056     unsigned long Status=0, Temp=0;
01057     LOCK_MUTEX();
01058     if (isOpen()) {
01059         ioctl(Posix_File->handle(), TIOCMGET, &Temp);
01060         if (Temp&TIOCM_CTS) {
01061             Status|=LS_CTS;
01062         }
01063         if (Temp&TIOCM_DSR) {
01064             Status|=LS_DSR;
01065         }
01066         if (Temp&TIOCM_RI) {
01067             Status|=LS_RI;
01068         }
01069         if (Temp&TIOCM_CD) {
01070             Status|=LS_DCD;
01071         }
01072         if (Temp&TIOCM_DTR) {
01073             Status|=LS_DTR;
01074         }
01075         if (Temp&TIOCM_RTS) {
01076             Status|=LS_RTS;
01077         }
01078         if (Temp&TIOCM_ST) {
01079             Status|=LS_ST;
01080         }
01081         if (Temp&TIOCM_SR) {
01082             Status|=LS_SR;
01083         }
01084     }
01085     UNLOCK_MUTEX();
01086     return Status;
01087 }

bool Posix_QextSerialPort::open ( OpenMode  mode  )  [virtual]

Opens the serial port associated to this class. This function has no effect if the port associated with the class is already open. The port is also configured to the current settings, as stored in the Settings structure.

Implements QextSerialBase.

00830 {
00831     LOCK_MUTEX();
00832     if (mode == QIODevice::NotOpen)
00833         return isOpen();
00834     if (!isOpen()) {
00835         /*open the port*/
00836         Posix_File->setFileName(port);
00837         qDebug("Trying to open File");
00838         if (Posix_File->open(QIODevice::ReadWrite|QIODevice::Unbuffered)) {
00839             qDebug("Opened File succesfully");
00840             /*set open mode*/
00841             QIODevice::open(mode);
00842 
00843             /*configure port settings*/
00844             tcgetattr(Posix_File->handle(), &Posix_CommConfig);
00845 
00846             /*set up other port settings*/
00847             Posix_CommConfig.c_cflag|=CREAD|CLOCAL;
00848             Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
00849             Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
00850             Posix_CommConfig.c_oflag&=(~OPOST);
00851             Posix_CommConfig.c_cc[VMIN]=0;
00852             Posix_CommConfig.c_cc[VINTR] = _POSIX_VDISABLE;
00853             Posix_CommConfig.c_cc[VQUIT] = _POSIX_VDISABLE;
00854             Posix_CommConfig.c_cc[VSTART] = _POSIX_VDISABLE;
00855             Posix_CommConfig.c_cc[VSTOP] = _POSIX_VDISABLE;
00856             Posix_CommConfig.c_cc[VSUSP] = _POSIX_VDISABLE;
00857             setBaudRate(Settings.BaudRate);
00858             setDataBits(Settings.DataBits);
00859             setParity(Settings.Parity);
00860             setStopBits(Settings.StopBits);
00861             setFlowControl(Settings.FlowControl);
00862             setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec);
00863             tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00864         } else {
00865             qDebug("Could not open File! Error code : %d", Posix_File->error());
00866         }
00867     }
00868     UNLOCK_MUTEX();
00869     return isOpen();
00870 }

Posix_QextSerialPort & Posix_QextSerialPort::operator= ( const Posix_QextSerialPort s  ) 

Override the = operator.

00127 {
00128     setOpenMode(s.openMode());
00129     port = s.port;
00130     Settings.BaudRate=s.Settings.BaudRate;
00131     Settings.DataBits=s.Settings.DataBits;
00132     Settings.Parity=s.Settings.Parity;
00133     Settings.StopBits=s.Settings.StopBits;
00134     Settings.FlowControl=s.Settings.FlowControl;
00135     lastErr=s.lastErr;
00136 
00137     Posix_File=s.Posix_File;
00138     memcpy(&Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval));
00139     memcpy(&Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval));
00140     memcpy(&Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios));
00141     return *this;
00142 }

ParityType QextSerialBase::parity (  )  const [virtual, inherited]

Returns the type of parity used by the port. For a list of possible values returned by this function, see the definition of the enum ParityType.

00123 {
00124     return Settings.Parity;
00125 }

QString QextSerialBase::portName (  )  const [virtual, inherited]

Returns the name set by setPortName().

00093 {
00094     return port;
00095 }

QextSerialBase::QueryMode QextSerialBase::queryMode (  )  const [inline, inherited]

00176 { return _queryMode; };

qint64 Posix_QextSerialPort::readData ( char *  data,
qint64  maxSize 
) [protected, virtual]

Reads a block of data from the serial port. This function will read at most maxSize bytes from the serial port and place them in the buffer pointed to by data. Return value is the number of bytes actually read, or -1 on error.

Warning:
before calling this function ensure that serial port associated with this class is currently open (use isOpen() function to check if port is open).

Implements QextSerialBase.

01099 {
01100     LOCK_MUTEX();
01101     int retVal=0;
01102     retVal=Posix_File->read(data, maxSize);
01103     if (retVal==-1)
01104         lastErr=E_READ_FAILED;
01105     UNLOCK_MUTEX();
01106 
01107     return retVal;
01108 }

qint64 QextSerialBase::readLine ( char *  data,
qint64  maxSize 
) [virtual, inherited]

This function will read a line of buffered input from the port, stopping when either maxSize bytes have been read, the port has no more data available, or a newline is encountered. The value returned is the length of the string that was read.

Reimplemented from QIODevice.

00178 {
00179     qint64 numBytes = bytesAvailable();
00180     char* pData = data;
00181 
00182     if (maxSize < 2)    //maxSize must be larger than 1
00183         return -1;
00184 
00185     /*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/
00186     while (pData<(data+numBytes) && --maxSize) {
00187         readData(pData, 1);
00188         if (*pData++ == '\n') {
00189             break;
00190         }
00191     }
00192     *pData='\0';
00193 
00194     /*return size of data read*/
00195     return (pData-data);
00196 }

void Posix_QextSerialPort::setBaudRate ( BaudRateType  baudRate  )  [virtual]

Sets the baud rate of the serial port. Note that not all rates are applicable on all platforms. The following table shows translations of the various baud rate constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * are speeds that are usable on both Windows and POSIX.

Note:
BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support BAUD1800.
  RATE          Windows Speed   POSIX Speed
  -----------   -------------   -----------
   BAUD50                 110          50
   BAUD75                 110          75
  *BAUD110                110         110
   BAUD134                110         134.5
   BAUD150                110         150
   BAUD200                110         200
  *BAUD300                300         300
  *BAUD600                600         600
  *BAUD1200              1200        1200
   BAUD1800              1200        1800
  *BAUD2400              2400        2400
  *BAUD4800              4800        4800
  *BAUD9600              9600        9600
   BAUD14400            14400        9600
  *BAUD19200            19200       19200
  *BAUD38400            38400       38400
   BAUD56000            56000       38400
  *BAUD57600            57600       57600
   BAUD76800            57600       76800
  *BAUD115200          115200      115200
   BAUD128000          128000      115200
   BAUD256000          256000      115200

Implements QextSerialBase.

00203 {
00204     LOCK_MUTEX();
00205     if (Settings.BaudRate!=baudRate) {
00206         switch (baudRate) {
00207             case BAUD14400:
00208                 Settings.BaudRate=BAUD9600;
00209                 break;
00210 
00211             case BAUD56000:
00212                 Settings.BaudRate=BAUD38400;
00213                 break;
00214 
00215             case BAUD76800:
00216 
00217 #ifndef B76800
00218                 Settings.BaudRate=BAUD57600;
00219 #else
00220                 Settings.BaudRate=baudRate;
00221 #endif
00222                 break;
00223 
00224             case BAUD128000:
00225             case BAUD256000:
00226                 Settings.BaudRate=BAUD115200;
00227                 break;
00228 
00229             default:
00230                 Settings.BaudRate=baudRate;
00231                 break;
00232         }
00233     }
00234     if (isOpen()) {
00235         switch (baudRate) {
00236 
00237             /*50 baud*/
00238             case BAUD50:
00239                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation.");
00240 #ifdef CBAUD
00241                 Posix_CommConfig.c_cflag&=(~CBAUD);
00242                 Posix_CommConfig.c_cflag|=B50;
00243 #else
00244                 cfsetispeed(&Posix_CommConfig, B50);
00245                 cfsetospeed(&Posix_CommConfig, B50);
00246 #endif
00247                 break;
00248 
00249             /*75 baud*/
00250             case BAUD75:
00251                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation.");
00252 #ifdef CBAUD
00253                 Posix_CommConfig.c_cflag&=(~CBAUD);
00254                 Posix_CommConfig.c_cflag|=B75;
00255 #else
00256                 cfsetispeed(&Posix_CommConfig, B75);
00257                 cfsetospeed(&Posix_CommConfig, B75);
00258 #endif
00259                 break;
00260 
00261             /*110 baud*/
00262             case BAUD110:
00263 #ifdef CBAUD
00264                 Posix_CommConfig.c_cflag&=(~CBAUD);
00265                 Posix_CommConfig.c_cflag|=B110;
00266 #else
00267                 cfsetispeed(&Posix_CommConfig, B110);
00268                 cfsetospeed(&Posix_CommConfig, B110);
00269 #endif
00270                 break;
00271 
00272             /*134.5 baud*/
00273             case BAUD134:
00274                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 134.5 baud operation.");
00275 #ifdef CBAUD
00276                 Posix_CommConfig.c_cflag&=(~CBAUD);
00277                 Posix_CommConfig.c_cflag|=B134;
00278 #else
00279                 cfsetispeed(&Posix_CommConfig, B134);
00280                 cfsetospeed(&Posix_CommConfig, B134);
00281 #endif
00282                 break;
00283 
00284             /*150 baud*/
00285             case BAUD150:
00286                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 150 baud operation.");
00287 #ifdef CBAUD
00288                 Posix_CommConfig.c_cflag&=(~CBAUD);
00289                 Posix_CommConfig.c_cflag|=B150;
00290 #else
00291                 cfsetispeed(&Posix_CommConfig, B150);
00292                 cfsetospeed(&Posix_CommConfig, B150);
00293 #endif
00294                 break;
00295 
00296             /*200 baud*/
00297             case BAUD200:
00298                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 200 baud operation.");
00299 #ifdef CBAUD
00300                 Posix_CommConfig.c_cflag&=(~CBAUD);
00301                 Posix_CommConfig.c_cflag|=B200;
00302 #else
00303                 cfsetispeed(&Posix_CommConfig, B200);
00304                 cfsetospeed(&Posix_CommConfig, B200);
00305 #endif
00306                 break;
00307 
00308             /*300 baud*/
00309             case BAUD300:
00310 #ifdef CBAUD
00311                 Posix_CommConfig.c_cflag&=(~CBAUD);
00312                 Posix_CommConfig.c_cflag|=B300;
00313 #else
00314                 cfsetispeed(&Posix_CommConfig, B300);
00315                 cfsetospeed(&Posix_CommConfig, B300);
00316 #endif
00317                 break;
00318 
00319             /*600 baud*/
00320             case BAUD600:
00321 #ifdef CBAUD
00322                 Posix_CommConfig.c_cflag&=(~CBAUD);
00323                 Posix_CommConfig.c_cflag|=B600;
00324 #else
00325                 cfsetispeed(&Posix_CommConfig, B600);
00326                 cfsetospeed(&Posix_CommConfig, B600);
00327 #endif
00328                 break;
00329 
00330             /*1200 baud*/
00331             case BAUD1200:
00332 #ifdef CBAUD
00333                 Posix_CommConfig.c_cflag&=(~CBAUD);
00334                 Posix_CommConfig.c_cflag|=B1200;
00335 #else
00336                 cfsetispeed(&Posix_CommConfig, B1200);
00337                 cfsetospeed(&Posix_CommConfig, B1200);
00338 #endif
00339                 break;
00340 
00341             /*1800 baud*/
00342             case BAUD1800:
00343                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation.");
00344 #ifdef CBAUD
00345                 Posix_CommConfig.c_cflag&=(~CBAUD);
00346                 Posix_CommConfig.c_cflag|=B1800;
00347 #else
00348                 cfsetispeed(&Posix_CommConfig, B1800);
00349                 cfsetospeed(&Posix_CommConfig, B1800);
00350 #endif
00351                 break;
00352 
00353             /*2400 baud*/
00354             case BAUD2400:
00355 #ifdef CBAUD
00356                 Posix_CommConfig.c_cflag&=(~CBAUD);
00357                 Posix_CommConfig.c_cflag|=B2400;
00358 #else
00359                 cfsetispeed(&Posix_CommConfig, B2400);
00360                 cfsetospeed(&Posix_CommConfig, B2400);
00361 #endif
00362                 break;
00363 
00364             /*4800 baud*/
00365             case BAUD4800:
00366 #ifdef CBAUD
00367                 Posix_CommConfig.c_cflag&=(~CBAUD);
00368                 Posix_CommConfig.c_cflag|=B4800;
00369 #else
00370                 cfsetispeed(&Posix_CommConfig, B4800);
00371                 cfsetospeed(&Posix_CommConfig, B4800);
00372 #endif
00373                 break;
00374 
00375             /*9600 baud*/
00376             case BAUD9600:
00377 #ifdef CBAUD
00378                 Posix_CommConfig.c_cflag&=(~CBAUD);
00379                 Posix_CommConfig.c_cflag|=B9600;
00380 #else
00381                 cfsetispeed(&Posix_CommConfig, B9600);
00382                 cfsetospeed(&Posix_CommConfig, B9600);
00383 #endif
00384                 break;
00385 
00386             /*14400 baud*/
00387             case BAUD14400:
00388                 TTY_WARNING("Posix_QextSerialPort: POSIX does not support 14400 baud operation.  Switching to 9600 baud.");
00389 #ifdef CBAUD
00390                 Posix_CommConfig.c_cflag&=(~CBAUD);
00391                 Posix_CommConfig.c_cflag|=B9600;
00392 #else
00393                 cfsetispeed(&Posix_CommConfig, B9600);
00394                 cfsetospeed(&Posix_CommConfig, B9600);
00395 #endif
00396                 break;
00397 
00398             /*19200 baud*/
00399             case BAUD19200:
00400 #ifdef CBAUD
00401                 Posix_CommConfig.c_cflag&=(~CBAUD);
00402                 Posix_CommConfig.c_cflag|=B19200;
00403 #else
00404                 cfsetispeed(&Posix_CommConfig, B19200);
00405                 cfsetospeed(&Posix_CommConfig, B19200);
00406 #endif
00407                 break;
00408 
00409             /*38400 baud*/
00410             case BAUD38400:
00411 #ifdef CBAUD
00412                 Posix_CommConfig.c_cflag&=(~CBAUD);
00413                 Posix_CommConfig.c_cflag|=B38400;
00414 #else
00415                 cfsetispeed(&Posix_CommConfig, B38400);
00416                 cfsetospeed(&Posix_CommConfig, B38400);
00417 #endif
00418                 break;
00419 
00420             /*56000 baud*/
00421             case BAUD56000:
00422                 TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation.  Switching to 38400 baud.");
00423 #ifdef CBAUD
00424                 Posix_CommConfig.c_cflag&=(~CBAUD);
00425                 Posix_CommConfig.c_cflag|=B38400;
00426 #else
00427                 cfsetispeed(&Posix_CommConfig, B38400);
00428                 cfsetospeed(&Posix_CommConfig, B38400);
00429 #endif
00430                 break;
00431 
00432             /*57600 baud*/
00433             case BAUD57600:
00434 #ifdef CBAUD
00435                 Posix_CommConfig.c_cflag&=(~CBAUD);
00436                 Posix_CommConfig.c_cflag|=B57600;
00437 #else
00438                 cfsetispeed(&Posix_CommConfig, B57600);
00439                 cfsetospeed(&Posix_CommConfig, B57600);
00440 #endif
00441                 break;
00442 
00443             /*76800 baud*/
00444             case BAUD76800:
00445                 TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation.");
00446 #ifdef CBAUD
00447                 Posix_CommConfig.c_cflag&=(~CBAUD);
00448 
00449 #ifdef B76800
00450                 Posix_CommConfig.c_cflag|=B76800;
00451 #else
00452                 TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support.  Switching to 57600 baud.");
00453                 Posix_CommConfig.c_cflag|=B57600;
00454 #endif //B76800
00455 #else  //CBAUD
00456 #ifdef B76800
00457                 cfsetispeed(&Posix_CommConfig, B76800);
00458                 cfsetospeed(&Posix_CommConfig, B76800);
00459 #else
00460                 TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support.  Switching to 57600 baud.");
00461                 cfsetispeed(&Posix_CommConfig, B57600);
00462                 cfsetospeed(&Posix_CommConfig, B57600);
00463 #endif //B76800
00464 #endif //CBAUD
00465                 break;
00466 
00467             /*115200 baud*/
00468             case BAUD115200:
00469 #ifdef CBAUD
00470                 Posix_CommConfig.c_cflag&=(~CBAUD);
00471                 Posix_CommConfig.c_cflag|=B115200;
00472 #else
00473                 cfsetispeed(&Posix_CommConfig, B115200);
00474                 cfsetospeed(&Posix_CommConfig, B115200);
00475 #endif
00476                 break;
00477 
00478             /*128000 baud*/
00479             case BAUD128000:
00480                 TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation.  Switching to 115200 baud.");
00481 #ifdef CBAUD
00482                 Posix_CommConfig.c_cflag&=(~CBAUD);
00483                 Posix_CommConfig.c_cflag|=B115200;
00484 #else
00485                 cfsetispeed(&Posix_CommConfig, B115200);
00486                 cfsetospeed(&Posix_CommConfig, B115200);
00487 #endif
00488                 break;
00489 
00490             /*256000 baud*/
00491             case BAUD256000:
00492                 TTY_WARNING("Posix_QextSerialPort: POSIX does not support 256000 baud operation.  Switching to 115200 baud.");
00493 #ifdef CBAUD
00494                 Posix_CommConfig.c_cflag&=(~CBAUD);
00495                 Posix_CommConfig.c_cflag|=B115200;
00496 #else
00497                 cfsetispeed(&Posix_CommConfig, B115200);
00498                 cfsetospeed(&Posix_CommConfig, B115200);
00499 #endif
00500                 break;
00501         }
00502         tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00503     }
00504     UNLOCK_MUTEX();
00505 }

void Posix_QextSerialPort::setDataBits ( DataBitsType  dataBits  )  [virtual]

Sets the number of data bits used by the serial port. Possible values of dataBits are:

    DATA_5      5 data bits
    DATA_6      6 data bits
    DATA_7      7 data bits
    DATA_8      8 data bits

Note:
This function is subject to the following restrictions:
5 data bits cannot be used with 2 stop bits.
8 data bits cannot be used with space parity on POSIX systems.

Implements QextSerialBase.

00526 {
00527     LOCK_MUTEX();
00528     if (Settings.DataBits!=dataBits) {
00529         if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) ||
00530             (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) ||
00531             (Settings.Parity==PAR_SPACE && dataBits==DATA_8)) {
00532         }
00533         else {
00534             Settings.DataBits=dataBits;
00535         }
00536     }
00537     if (isOpen()) {
00538         switch(dataBits) {
00539 
00540             /*5 data bits*/
00541             case DATA_5:
00542                 if (Settings.StopBits==STOP_2) {
00543                     TTY_WARNING("Posix_QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
00544                 }
00545                 else {
00546                     Settings.DataBits=dataBits;
00547                     Posix_CommConfig.c_cflag&=(~CSIZE);
00548                     Posix_CommConfig.c_cflag|=CS5;
00549                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00550                 }
00551                 break;
00552 
00553             /*6 data bits*/
00554             case DATA_6:
00555                 if (Settings.StopBits==STOP_1_5) {
00556                     TTY_WARNING("Posix_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
00557                 }
00558                 else {
00559                     Settings.DataBits=dataBits;
00560                     Posix_CommConfig.c_cflag&=(~CSIZE);
00561                     Posix_CommConfig.c_cflag|=CS6;
00562                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00563                 }
00564                 break;
00565 
00566             /*7 data bits*/
00567             case DATA_7:
00568                 if (Settings.StopBits==STOP_1_5) {
00569                     TTY_WARNING("Posix_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
00570                 }
00571                 else {
00572                     Settings.DataBits=dataBits;
00573                     Posix_CommConfig.c_cflag&=(~CSIZE);
00574                     Posix_CommConfig.c_cflag|=CS7;
00575                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00576                 }
00577                 break;
00578 
00579             /*8 data bits*/
00580             case DATA_8:
00581                 if (Settings.StopBits==STOP_1_5) {
00582                     TTY_WARNING("Posix_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
00583                 }
00584                 else {
00585                     Settings.DataBits=dataBits;
00586                     Posix_CommConfig.c_cflag&=(~CSIZE);
00587                     Posix_CommConfig.c_cflag|=CS8;
00588                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00589                 }
00590                 break;
00591         }
00592     }
00593     UNLOCK_MUTEX();
00594 }

void Posix_QextSerialPort::setDtr ( bool  set = true  )  [virtual]

Sets DTR line to the requested state (high by default). This function will have no effect if the port associated with the class is not currently open.

Implements QextSerialBase.

00993 {
00994     LOCK_MUTEX();
00995     if (isOpen()) {
00996         int status;
00997         ioctl(Posix_File->handle(), TIOCMGET, &status);
00998         if (set) {
00999             status|=TIOCM_DTR;
01000         }
01001         else {
01002             status&=~TIOCM_DTR;
01003         }
01004         ioctl(Posix_File->handle(), TIOCMSET, &status);
01005     }
01006     UNLOCK_MUTEX();
01007 }

void Posix_QextSerialPort::setFlowControl ( FlowType  flow  )  [virtual]

Sets the flow control used by the port. Possible values of flow are:

    FLOW_OFF            No flow control
    FLOW_HARDWARE       Hardware (RTS/CTS) flow control
    FLOW_XONXOFF        Software (XON/XOFF) flow control
Note:
FLOW_HARDWARE may not be supported on all versions of UNIX. In cases where it is unsupported, FLOW_HARDWARE is the same as FLOW_OFF.

Implements QextSerialBase.

00759 {
00760     LOCK_MUTEX();
00761     if (Settings.FlowControl!=flow) {
00762         Settings.FlowControl=flow;
00763     }
00764     if (isOpen()) {
00765         switch(flow) {
00766 
00767             /*no flow control*/
00768             case FLOW_OFF:
00769                 Posix_CommConfig.c_cflag&=(~CRTSCTS);
00770                 Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY));
00771                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00772                 break;
00773 
00774             /*software (XON/XOFF) flow control*/
00775             case FLOW_XONXOFF:
00776                 Posix_CommConfig.c_cflag&=(~CRTSCTS);
00777                 Posix_CommConfig.c_iflag|=(IXON|IXOFF|IXANY);
00778                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00779                 break;
00780 
00781             case FLOW_HARDWARE:
00782                 Posix_CommConfig.c_cflag|=CRTSCTS;
00783                 Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY));
00784                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00785                 break;
00786         }
00787     }
00788     UNLOCK_MUTEX();
00789 }

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.

00617 {
00618     LOCK_MUTEX();
00619     if (Settings.Parity!=parity) {
00620         if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) {
00621         }
00622         else {
00623             Settings.Parity=parity;
00624         }
00625     }
00626     if (isOpen()) {
00627         switch (parity) {
00628 
00629             /*space parity*/
00630             case PAR_SPACE:
00631                 if (Settings.DataBits==DATA_8) {
00632                     TTY_PORTABILITY_WARNING("Posix_QextSerialPort:  Space parity is only supported in POSIX with 7 or fewer data bits");
00633                 }
00634                 else {
00635 
00636                     /*space parity not directly supported - add an extra data bit to simulate it*/
00637                     Posix_CommConfig.c_cflag&=~(PARENB|CSIZE);
00638                     switch(Settings.DataBits) {
00639                         case DATA_5:
00640                             Settings.DataBits=DATA_6;
00641                             Posix_CommConfig.c_cflag|=CS6;
00642                             break;
00643 
00644                         case DATA_6:
00645                             Settings.DataBits=DATA_7;
00646                             Posix_CommConfig.c_cflag|=CS7;
00647                             break;
00648 
00649                         case DATA_7:
00650                             Settings.DataBits=DATA_8;
00651                             Posix_CommConfig.c_cflag|=CS8;
00652                             break;
00653 
00654                         case DATA_8:
00655                             break;
00656                     }
00657                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00658                 }
00659                 break;
00660 
00661             /*mark parity - WINDOWS ONLY*/
00662             case PAR_MARK:
00663                 TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX.");
00664                 break;
00665 
00666             /*no parity*/
00667             case PAR_NONE:
00668                 Posix_CommConfig.c_cflag&=(~PARENB);
00669                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00670                 break;
00671 
00672             /*even parity*/
00673             case PAR_EVEN:
00674                 Posix_CommConfig.c_cflag&=(~PARODD);
00675                 Posix_CommConfig.c_cflag|=PARENB;
00676                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00677                 break;
00678 
00679             /*odd parity*/
00680             case PAR_ODD:
00681                 Posix_CommConfig.c_cflag|=(PARENB|PARODD);
00682                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00683                 break;
00684         }
00685     }
00686     UNLOCK_MUTEX();
00687 }

void QextSerialBase::setPortName ( const QString &  name  )  [virtual, inherited]

Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0".

00084 {
00085     port = name;
00086 }

void QextSerialBase::setQueryMode ( QueryMode  mode  )  [virtual, inherited]

Set desired serial communication handling style. You may choose from polling or event driven approach. This function does nothing when port is open; to apply changes port must be reopened.

In event driven approach read() and write() functions are acting asynchronously. They return immediately and the operation is performed in the background, so they doesn't freeze the calling thread. To determine when operation is finished, QextSerialPort runs separate thread and monitors serial port events. Whenever the event occurs, adequate signal is emitted.

When polling is set, read() and write() are acting synchronously. Signals are not working in this mode and some functions may not be available. The advantage of polling is that it generates less overhead due to lack of signals emissions and it doesn't start separate thread to monitor events.

Generally event driven approach is more capable and friendly, although some applications may need as low overhead as possible and then polling comes.

Parameters:
mode query mode.
00075 {
00076     _queryMode = mechanism;
00077 }

void Posix_QextSerialPort::setRts ( bool  set = true  )  [virtual]

Sets RTS line to the requested state (high by default). This function will have no effect if the port associated with the class is not currently open.

Implements QextSerialBase.

01015 {
01016     LOCK_MUTEX();
01017     if (isOpen()) {
01018         int status;
01019         ioctl(Posix_File->handle(), TIOCMGET, &status);
01020         if (set) {
01021             status|=TIOCM_RTS;
01022         }
01023         else {
01024             status&=~TIOCM_RTS;
01025         }
01026         ioctl(Posix_File->handle(), TIOCMSET, &status);
01027     }
01028     UNLOCK_MUTEX();
01029 }

void Posix_QextSerialPort::setStopBits ( StopBitsType  stopBits  )  [virtual]

Sets the number of stop bits used by the serial port. Possible values of stopBits are:

    STOP_1      1 stop bit
    STOP_1_5    1.5 stop bits
    STOP_2      2 stop bits
Note:
This function is subject to the following restrictions:
2 stop bits cannot be used with 5 data bits.
POSIX does not support 1.5 stop bits.

Implements QextSerialBase.

00706 {
00707     LOCK_MUTEX();
00708     if (Settings.StopBits!=stopBits) {
00709         if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || stopBits==STOP_1_5) {}
00710         else {
00711             Settings.StopBits=stopBits;
00712         }
00713     }
00714     if (isOpen()) {
00715         switch (stopBits) {
00716 
00717             /*one stop bit*/
00718             case STOP_1:
00719                 Settings.StopBits=stopBits;
00720                 Posix_CommConfig.c_cflag&=(~CSTOPB);
00721                 tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00722                 break;
00723 
00724             /*1.5 stop bits*/
00725             case STOP_1_5:
00726                 TTY_WARNING("Posix_QextSerialPort: 1.5 stop bit operation is not supported by POSIX.");
00727                 break;
00728 
00729             /*two stop bits*/
00730             case STOP_2:
00731                 if (Settings.DataBits==DATA_5) {
00732                     TTY_WARNING("Posix_QextSerialPort: 2 stop bits cannot be used with 5 data bits");
00733                 }
00734                 else {
00735                     Settings.StopBits=stopBits;
00736                     Posix_CommConfig.c_cflag|=CSTOPB;
00737                     tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00738                 }
00739                 break;
00740         }
00741     }
00742     UNLOCK_MUTEX();
00743 }

void Posix_QextSerialPort::setTimeout ( ulong  sec,
ulong  millisec 
) [virtual]

Sets the read and write timeouts for the port to sec seconds and millisec milliseconds. Note that this is a per-character timeout, i.e. the port will wait this long for each individual character, not for the whole read operation. This timeout also applies to the bytesWaiting() function.

Note:
POSIX does not support millisecond-level control for I/O timeout values. Any timeout set using this function will be set to the next lowest tenth of a second for the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and writing the port. However millisecond-level control is allowed by the select() system call, so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for the purpose of detecting available bytes in the read buffer.

Implements QextSerialBase.

00809 {
00810     LOCK_MUTEX();
00811     Settings.Timeout_Sec=sec;
00812     Settings.Timeout_Millisec=millisec;
00813     Posix_Copy_Timeout.tv_sec=sec;
00814     Posix_Copy_Timeout.tv_usec=millisec;
00815     if (isOpen()) {
00816         tcgetattr(Posix_File->handle(), &Posix_CommConfig);
00817         Posix_CommConfig.c_cc[VTIME]=sec*10+millisec/100;
00818         tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig);
00819     }
00820     UNLOCK_MUTEX();
00821 }

qint64 Posix_QextSerialPort::size (  )  const [virtual]

This function will return the number of bytes waiting in the receive queue of the serial port. It is included primarily to provide a complete QIODevice interface, and will not record errors in the lastErr member (because it is const). This function is also not thread-safe - in multithreading situations, use Posix_QextSerialPort::bytesWaiting() instead.

Implements QextSerialBase.

00907 {
00908     int numBytes;
00909     if (ioctl(Posix_File->handle(), FIONREAD, &numBytes)<0) {
00910         numBytes=0;
00911     }
00912     return (qint64)numBytes;
00913 }

StopBitsType QextSerialBase::stopBits (  )  const [virtual, inherited]

Returns the number of stop bits used by the port. For a list of possible return values, see the definition of the enum StopBitsType.

00133 {
00134     return Settings.StopBits;
00135 }

void Posix_QextSerialPort::translateError ( ulong  error  )  [virtual]

Translates a system-specific error code to a QextSerialPort error code. Used internally.

Implements QextSerialBase.

00970 {
00971     switch (error) {
00972         case EBADF:
00973         case ENOTTY:
00974             lastErr=E_INVALID_FD;
00975             break;
00976 
00977         case EINTR:
00978             lastErr=E_CAUGHT_NON_BLOCKED_SIGNAL;
00979             break;
00980 
00981         case ENOMEM:
00982             lastErr=E_NO_MEMORY;
00983             break;
00984     }
00985 }

void Posix_QextSerialPort::ungetChar ( char  c  )  [virtual]

This function is included to implement the full QIODevice interface, and currently has no purpose within this class. This function is meaningless on an unbuffered device and currently only prints a warning message to that effect.

Implements QextSerialBase.

00960 {
00961     /*meaningless on unbuffered sequential device - return error and print a warning*/
00962     TTY_WARNING("Posix_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless");
00963 }

qint64 Posix_QextSerialPort::writeData ( const char *  data,
qint64  maxSize 
) [protected, virtual]

Writes a block of data to the serial port. This function will write maxSize bytes from the buffer pointed to by data to the serial port. Return value is the number of bytes actually written, or -1 on error.

Warning:
before calling this function ensure that serial port associated with this class is currently open (use isOpen() function to check if port is open).

Implements QextSerialBase.

01120 {
01121     LOCK_MUTEX();
01122     int retVal=0;
01123     retVal=Posix_File->write(data, maxSize);
01124     if (retVal==-1)
01125        lastErr=E_WRITE_FAILED;
01126     UNLOCK_MUTEX();
01127 //    flush();
01128     return retVal;
01129 }


Member Data Documentation

QextSerialBase::QueryMode QextSerialBase::_queryMode [protected, inherited]

ulong QextSerialBase::lastErr [protected, inherited]

QMutex* QextSerialBase::mutex [protected, inherited]

QString QextSerialBase::port [protected, inherited]

struct termios Posix_QextSerialPort::Posix_CommConfig [protected]

struct timeval Posix_QextSerialPort::Posix_Copy_Timeout [protected]

QFile* Posix_QextSerialPort::Posix_File [protected]

struct timeval Posix_QextSerialPort::Posix_Timeout [protected]

PortSettings QextSerialBase::Settings [protected, inherited]


The documentation for this class was generated from the following files:
Generated on Wed Sep 5 19:31:21 2007 for QextSerialPort by  doxygen 1.4.7