QextSerialBase Class Reference

#include <qextserialbase.h>

Inheritance diagram for QextSerialBase:

QIODevice Posix_QextSerialPort Win_QextSerialPort QextBaseType QextBaseType QextSerialPort 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 ()=0
 bytesToWrite ()
 bytesWritten (qint64 bytes)
 canReadLine ()
virtual void close ()=0
virtual void construct ()
virtual DataBitsType dataBits () const
 errorString ()
virtual FlowType flowControl () const
virtual void flush ()=0
 getChar (char *c)
 isOpen ()
 isReadable ()
 isSequential ()
virtual bool isSequential () const
 isTextModeEnabled ()
 isWritable ()
virtual ulong lastError () const
virtual ulong lineStatus ()=0
virtual bool open (OpenMode mode)=0
 openMode ()
virtual ParityType parity () const
 peek (qint64 maxSize)
 peek (char *data, qint64 maxSize)
virtual QString portName () const
 pos ()
 putChar (char c)
 QextSerialBase (const QString &name)
 QextSerialBase ()
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)=0
virtual void setDataBits (DataBitsType)=0
virtual void setDtr (bool set=true)=0
 setErrorString (const QString &str)
virtual void setFlowControl (FlowType)=0
 setOpenMode (OpenMode openMode)
virtual void setParity (ParityType)=0
virtual void setPortName (const QString &name)
virtual void setQueryMode (QueryMode mode)
virtual void setRts (bool set=true)=0
virtual void setStopBits (StopBitsType)=0
 setTextModeEnabled (bool enabled)
virtual void setTimeout (ulong, ulong)=0
 size ()
virtual qint64 size () const =0
virtual StopBitsType stopBits () const
virtual void translateError (ulong error)=0
virtual void ungetChar (char c)=0
 waitForBytesWritten (int msecs)
 waitForReadyRead (int msecs)
 write (const QByteArray &byteArray)
 write (const char *data, qint64 maxSize)
virtual ~QextSerialBase ()

Protected Member Functions

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

Protected Attributes

QextSerialBase::QueryMode _queryMode
ulong lastErr
QMutex * mutex
QString port
PortSettings Settings

Detailed Description

Author:
Stefan Sander

Michal Policht

A common base class for Win_QextSerialBase, Posix_QextSerialBase and QextSerialPort.


Member Enumeration Documentation

enum QextSerialBase::QueryMode

Enumerator:
Polling 
EventDriven 

Reimplemented in QextSerialPort.

00154                        {
00155             Polling,
00156             EventDriven
00157         };


Constructor & Destructor Documentation

QextSerialBase::QextSerialBase (  ) 

Default constructor.

00008  : QIODevice()
00009 {
00010 
00011 #ifdef _TTY_WIN_
00012     setPortName("COM1");
00013 
00014 #elif defined(_TTY_IRIX_)
00015     setPortName("/dev/ttyf1");
00016 
00017 #elif defined(_TTY_HPUX_)
00018     setPortName("/dev/tty1p0");
00019 
00020 #elif defined(_TTY_SUN_)
00021     setPortName("/dev/ttya");
00022 
00023 #elif defined(_TTY_DIGITAL_)
00024     setPortName("/dev/tty01");
00025 
00026 #elif defined(_TTY_FREEBSD_)
00027     setPortName("/dev/ttyd1");
00028 
00029 #else
00030     setPortName("/dev/ttyS0");
00031 #endif
00032 
00033     construct();
00034 }

QextSerialBase::QextSerialBase ( const QString &  name  ) 

Construct a port and assign it to the device specified by the name parameter.

00041  : QIODevice()
00042 {
00043     setPortName(name);
00044     construct();
00045 }

QextSerialBase::~QextSerialBase (  )  [virtual]

Standard destructor.

00052 {
00053     delete mutex;
00054 }


Member Function Documentation

bool QextSerialBase::atEnd (  )  const [virtual]

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]

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 }

virtual qint64 QextSerialBase::bytesAvailable (  )  [pure virtual]

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::close (  )  [pure virtual]

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

void QextSerialBase::construct (  )  [virtual]

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]

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]

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]

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 }

virtual void QextSerialBase::flush (  )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

bool QextSerialBase::isSequential (  )  const [virtual]

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]

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 }

virtual ulong QextSerialBase::lineStatus (  )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual bool QextSerialBase::open ( OpenMode  mode  )  [pure virtual]

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

ParityType QextSerialBase::parity (  )  const [virtual]

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]

Returns the name set by setPortName().

00093 {
00094     return port;
00095 }

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

00176 { return _queryMode; };

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

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

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

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 }

virtual void QextSerialBase::setBaudRate ( BaudRateType   )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::setDataBits ( DataBitsType   )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

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

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::setFlowControl ( FlowType   )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::setParity ( ParityType   )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

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

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]

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 }

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

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::setStopBits ( StopBitsType   )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::setTimeout ( ulong  ,
ulong   
) [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual qint64 QextSerialBase::size (  )  const [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

StopBitsType QextSerialBase::stopBits (  )  const [virtual]

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 }

virtual void QextSerialBase::translateError ( ulong  error  )  [pure virtual]

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual void QextSerialBase::ungetChar ( char  c  )  [pure virtual]

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

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

Reimplemented from QIODevice.

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.


Member Data Documentation

QextSerialBase::QueryMode QextSerialBase::_queryMode [protected]

ulong QextSerialBase::lastErr [protected]

QMutex* QextSerialBase::mutex [protected]

QString QextSerialBase::port [protected]

PortSettings QextSerialBase::Settings [protected]


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