- Main Page
- Classes
- Files

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# QextSerialBase Class Reference

`#include <qextserialbase.h>`

Inheritance diagram for QextSerialBase:

List of all members.

## 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)=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 ()
| 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 | 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
ulong | lastErr
QString | port
PortSettings | Settings
## Static Protected Attributes
static QMutex * | mutex = NULL
static ulong | refCount = 0

## Detailed Description

Version:
  1.0.0

Author:
  Stefan Sander

A common base class for Win_QextSerialBase, Posix_QextSerialBase and QextSerialPort.

## Constructor & Destructor Documentation

QextSerialBase::QextSerialBase | ( |  | ) |

Default constructor.

    00021  : QIODevice()
    00022 {
    00023
    00024 #ifdef _TTY_WIN_
    00025     setPortName("COM1");
    00026
    00027 #elif defined(_TTY_IRIX_)
    00028     setPortName("/dev/ttyf1");
    00029
    00030 #elif defined(_TTY_HPUX_)
    00031     setPortName("/dev/tty1p0");
    00032
    00033 #elif defined(_TTY_SUN_)
    00034     setPortName("/dev/ttya");
    00035
    00036 #elif defined(_TTY_DIGITAL_)
    00037     setPortName("/dev/tty01");
    00038
    00039 #elif defined(_TTY_FREEBSD_)
    00040     setPortName("/dev/ttyd1");
    00041
    00042 #else
    00043     setPortName("/dev/ttyS0");
    00044 #endif
    00045
    00046     construct();
    00047 }

QextSerialBase::QextSerialBase | ( | const QString & | name | ) |

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

    00054  : QIODevice()
    00055 {
    00056     setPortName(name);
    00057     construct();
    00058 }

QextSerialBase::~QextSerialBase | ( |  | ) | `[virtual]`

Standard destructor.

    00065 {
    00066
    00067 #ifdef QT_THREAD_SUPPORT
    00068     refCount--;
    00069     if (mutex && refCount==0) {
    00070         delete mutex;
    00071         mutex=NULL;
    00072     }
    00073 #endif
    00074
    00075 }

## 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.

    00187 {
    00188     if (size()) {
    00189         return true;
    00190     }
    00191     return false;
    00192 }

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.

    00126 {
    00127     return Settings.BaudRate;
    00128 }

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 500 ms timeout).

    00083 {
    00084     Settings.BaudRate=BAUD115200;
    00085     Settings.DataBits=DATA_8;
    00086     Settings.Parity=PAR_NONE;
    00087     Settings.StopBits=STOP_1;
    00088     Settings.FlowControl=FLOW_HARDWARE;
    00089     Settings.Timeout_Sec=0;
    00090     Settings.Timeout_Millisec=500;
    00091
    00092 #ifdef QT_THREAD_SUPPORT
    00093     if (!mutex) {
    00094         mutex=new QMutex( QMutex::Recursive );
    00095     }
    00096     refCount++;
    00097 #endif
    00098
    00099     setOpenMode(QIODevice::NotOpen);
    00100 }

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.

    00136 {
    00137     return Settings.DataBits;
    00138 }

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.

    00166 {
    00167     return Settings.FlowControl;
    00168 }

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.

    00177 {
    00178     return true;
    00179 }

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

    00248 {
    00249     return lastErr;
    00250 }

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

Implemented in Posix_QextSerialPort, and Win_QextSerialPort.

virtual bool QextSerialBase::open | ( | OpenMode | mode = `0` | ) | `[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.

    00146 {
    00147     return Settings.Parity;
    00148 }

QString QextSerialBase::portName | ( |  | ) | const`[virtual]`

Returns the name set by setPortName().

    00116 {
    00117     return port;
    00118 }

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.

    00201 {
    00202     qint64 numBytes = bytesAvailable();
    00203     char* pData = data;
    00204
    00205     if (maxSize < 2)    //maxSize must be larger than 1
    00206         return -1;
    00207
    00208     /*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/
    00209     while (pData<(data+numBytes) && --maxSize) {
    00210         readData(pData, 1);
    00211         if (*pData++ == '\n') {
    00212             break;
    00213         }
    00214     }
    00215     *pData='\0';
    00216
    00217     /*return size of data read*/
    00218     return (pData-data);
    00219 }

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".

    00107 {
    00108     port = name;
    00109 }

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.

    00156 {
    00157     return Settings.StopBits;
    00158 }

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

ulong QextSerialBase::lastErr`[protected]`

QMutex * QextSerialBase::mutex = NULL`[static, protected]`

QString QextSerialBase::port`[protected]`

unsigned long QextSerialBase::refCount = 0`[static, protected]`

PortSettings QextSerialBase::Settings`[protected]`

The documentation for this class was generated from the following files:

- qextserialbase.h
- qextserialbase.cpp