- Main Page
- Classes
- Files

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

# Win_QextSerialPort Class Reference

`#include <win_qextserialport.h>`

Inheritance diagram for Win_QextSerialPort:

List of all members.

## 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 (void)
virtual bool | open (OpenMode mode=0)
| openMode ()
Win_QextSerialPort & | operator= (const Win_QextSerialPort &s)
virtual ParityType | parity () const
| peek (qint64 maxSize)
| peek (char *data, qint64 maxSize)
virtual QString | portName () const
| pos ()
| putChar (char c)
| 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 | 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)
virtual void | ungetChar (char c)
| waitForBytesWritten (int msecs)
| waitForReadyRead (int msecs)
| Win_QextSerialPort (const QString &name, const PortSettings &settings)
| Win_QextSerialPort (const PortSettings &settings)
| Win_QextSerialPort (const QString &name)
| Win_QextSerialPort (Win_QextSerialPort const &s)
| Win_QextSerialPort ()
| write (const QByteArray &byteArray)
| write (const char *data, qint64 maxSize)
virtual | ~Win_QextSerialPort ()
## Protected Member Functions
virtual qint64 | readData (char *data, qint64 maxSize)
virtual qint64 | writeData (const char *data, qint64 maxSize)
## Protected Attributes
ulong | lastErr
QString | port
PortSettings | Settings
COMMCONFIG | Win_CommConfig
COMMTIMEOUTS | Win_CommTimeouts
HANDLE | Win_Handle
## Static Protected Attributes
static QMutex * | mutex = NULL
static ulong | refCount = 0

## Detailed Description

Version:
  1.0.0

Author:
  Stefan Sander

A cross-platform serial port class. This class encapsulates the Windows 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 defining _TTY_NOWARN_ also defines _TTY_NOWARN_PORT_.

Note:
  On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can make no guarantees as to the quality of POSIX support under NT/2000 however.

## Constructor & Destructor Documentation

Win_QextSerialPort::Win_QextSerialPort | ( |  | ) |

Default constructor. Note that the name of the device used by a Win_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 associates the object with the first port on the system, e.g. COM1 for Windows platforms. See the other constructor if you need a port other than the first.

    00047                                       :QextSerialBase() {
    00048     Win_Handle=INVALID_HANDLE_VALUE;
    00049 }

Win_QextSerialPort::Win_QextSerialPort | ( | Win_QextSerialPort const & | s | ) |

Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort&) Copy constructor.

    00054                                                                  :QextSerialBase(s.port) {
    00055     Win_Handle=INVALID_HANDLE_VALUE;
    00056     setOpenMode(s.openMode());
    00057     lastErr=s.lastErr;
    00058     port = s.port;
    00059     Settings.FlowControl=s.Settings.FlowControl;
    00060     Settings.Parity=s.Settings.Parity;
    00061     Settings.DataBits=s.Settings.DataBits;
    00062     Settings.StopBits=s.Settings.StopBits;
    00063     Settings.BaudRate=s.Settings.BaudRate;
    00064     Win_Handle=s.Win_Handle;
    00065     memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
    00066     memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
    00067 }

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

Constructs a serial port attached to the port specified by devName. devName is the name of the device, which is windowsystem-specific, e.g."COM2" or "/dev/ttyS0".

    00075                                                           :QextSerialBase(name) {
    00076     Win_Handle=INVALID_HANDLE_VALUE;
    00077 }

Win_QextSerialPort::Win_QextSerialPort | ( | const PortSettings & | settings | ) |

Constructs a port with default name and specified settings.

    00083                                                                    {
    00084     Win_Handle=INVALID_HANDLE_VALUE;
    00085     setBaudRate(settings.BaudRate);
    00086     setDataBits(settings.DataBits);
    00087     setStopBits(settings.StopBits);
    00088     setParity(settings.Parity);
    00089     setFlowControl(settings.FlowControl);
    00090     setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
    00091 }

Win_QextSerialPort::Win_QextSerialPort | ( | const QString & | name,
|  | const PortSettings & | settings |
| ) |  |  |

Constructs a port with specified name and settings.

    00097                                                                                          {
    00098     Win_Handle=INVALID_HANDLE_VALUE;
    00099     setPortName(name);
    00100     setBaudRate(settings.BaudRate);
    00101     setDataBits(settings.DataBits);
    00102     setStopBits(settings.StopBits);
    00103     setParity(settings.Parity);
    00104     setFlowControl(settings.FlowControl);
    00105     setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
    00106 }

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

Standard destructor.

    00112                                         {
    00113     if (isOpen()) {
    00114         close();
    00115     }
    00116 }

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

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

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.

    00126 {
    00127     return Settings.BaudRate;
    00128 }

qint64 Win_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 Win_QextSerialPort::getLastError().

Implements QextSerialBase.

    00229                                           {
    00230     LOCK_MUTEX();
    00231     if (isOpen()) {
    00232         DWORD Errors;
    00233         COMSTAT Status;
    00234         bool success=ClearCommError(Win_Handle, &Errors, &Status);
    00235         translateError(Errors);
    00236         if (success) {
    00237             lastErr=E_NO_ERROR;
    00238             UNLOCK_MUTEX();
    00239             return Status.cbInQue + QIODevice::bytesAvailable();
    00240         }
    00241         UNLOCK_MUTEX();
    00242         return (unsigned int)-1;
    00243     }
    00244     UNLOCK_MUTEX();
    00245     return 0;
    00246 }

void Win_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.

    00187                                {
    00188     LOCK_MUTEX();
    00189     CloseHandle(Win_Handle);
    00190     QIODevice::close();
    00191     UNLOCK_MUTEX();
    00192 }

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

    00136 {
    00137     return Settings.DataBits;
    00138 }

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.

    00166 {
    00167     return Settings.FlowControl;
    00168 }

void Win_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.

    00199                                {
    00200     LOCK_MUTEX();
    00201     if (isOpen()) {
    00202         FlushFileBuffers(Win_Handle);
    00203     }
    00204     UNLOCK_MUTEX();
    00205 }

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.

    00177 {
    00178     return true;
    00179 }

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

    00248 {
    00249     return lastErr;
    00250 }

ulong Win_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

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

Implements QextSerialBase.

    00838                                          {
    00839     unsigned long Status=0, Temp=0;
    00840     LOCK_MUTEX();
    00841     if (isOpen()) {
    00842         GetCommModemStatus(Win_Handle, &Temp);
    00843         if (Temp&MS_CTS_ON) {
    00844             Status|=LS_CTS;
    00845         }
    00846         if (Temp&MS_DSR_ON) {
    00847             Status|=LS_DSR;
    00848         }
    00849         if (Temp&MS_RING_ON) {
    00850             Status|=LS_RI;
    00851         }
    00852         if (Temp&MS_RLSD_ON) {
    00853             Status|=LS_DCD;
    00854         }
    00855     }
    00856     UNLOCK_MUTEX();
    00857     return Status;
    00858 }

bool Win_QextSerialPort::open | ( | OpenMode | mode = `0` | ) | `[virtual]`

Opens a serial port. Note that this function does not specify which device to open. If you need to open a device by name, see Win_QextSerialPort::open(const char*). 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.

    00144                                            {
    00145     unsigned long confSize = sizeof(COMMCONFIG);
    00146     Win_CommConfig.dwSize = confSize;
    00147
    00148     LOCK_MUTEX();
    00149     if (mode == QIODevice::NotOpen)
    00150         return isOpen();
    00151     if (!isOpen()) {
    00152         /*open the port*/
    00153         Win_Handle=CreateFileA(port.toAscii(), GENERIC_READ|GENERIC_WRITE,
    00154                               FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    00155         if (Win_Handle!=INVALID_HANDLE_VALUE) {
    00156             /*set open mode*/
    00157             QIODevice::open(mode);
    00158
    00159             /*configure port settings*/
    00160             GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
    00161             GetCommState(Win_Handle, &(Win_CommConfig.dcb));
    00162
    00163             /*set up parameters*/
    00164             Win_CommConfig.dcb.fBinary=TRUE;
    00165             Win_CommConfig.dcb.fInX=FALSE;
    00166             Win_CommConfig.dcb.fOutX=FALSE;
    00167             Win_CommConfig.dcb.fAbortOnError=FALSE;
    00168             Win_CommConfig.dcb.fNull=FALSE;
    00169             setBaudRate(Settings.BaudRate);
    00170             setDataBits(Settings.DataBits);
    00171             setStopBits(Settings.StopBits);
    00172             setParity(Settings.Parity);
    00173             setFlowControl(Settings.FlowControl);
    00174             setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec);
    00175             SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00176         }
    00177     }
    00178     UNLOCK_MUTEX();
    00179     return isOpen();
    00180 }

Win_QextSerialPort & Win_QextSerialPort::operator= | ( | const Win_QextSerialPort & | s | ) |

overrides the = operator

    00122                                                                              {
    00123     setOpenMode(s.openMode());
    00124     lastErr=s.lastErr;
    00125     port = s.port;
    00126     Settings.FlowControl=s.Settings.FlowControl;
    00127     Settings.Parity=s.Settings.Parity;
    00128     Settings.DataBits=s.Settings.DataBits;
    00129     Settings.StopBits=s.Settings.StopBits;
    00130     Settings.BaudRate=s.Settings.BaudRate;
    00131     Win_Handle=s.Win_Handle;
    00132     memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
    00133     memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
    00134     return *this;
    00135 }

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.

    00146 {
    00147     return Settings.Parity;
    00148 }

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

Returns the name set by setPortName().

    00116 {
    00117     return port;
    00118 }

qint64 Win_QextSerialPort::readData | ( | char * | data,
|  | qint64 | maxSize |
| ) |  |  | `[protected, virtual]`

Reads a block of data from the serial port. This function will read at most maxlen 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.

    00289 {
    00290     LOCK_MUTEX();
    00291     int retVal=0;
    00292     COMSTAT Win_ComStat;
    00293     DWORD Win_BytesRead=0;
    00294     DWORD Win_ErrorMask=0;
    00295     ClearCommError(Win_Handle, &Win_ErrorMask, &Win_ComStat);
    00296     if (Win_ComStat.cbInQue &&
    00297         (!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, &Win_BytesRead, NULL)
    00298         || Win_BytesRead==0)) {
    00299         lastErr=E_READ_FAILED;
    00300         retVal=-1;
    00301     }
    00302     else {
    00303         retVal=((int)Win_BytesRead);
    00304     }
    00305     UNLOCK_MUTEX();
    00306
    00307     return retVal;
    00308 }

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.

    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 }

void Win_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.

      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.

    00629                                                           {
    00630     LOCK_MUTEX();
    00631     if (Settings.BaudRate!=baudRate) {
    00632         switch (baudRate) {
    00633             case BAUD50:
    00634             case BAUD75:
    00635             case BAUD134:
    00636             case BAUD150:
    00637             case BAUD200:
    00638                 Settings.BaudRate=BAUD110;
    00639                 break;
    00640
    00641             case BAUD1800:
    00642                 Settings.BaudRate=BAUD1200;
    00643                 break;
    00644
    00645             case BAUD76800:
    00646                 Settings.BaudRate=BAUD57600;
    00647                 break;
    00648
    00649             default:
    00650                 Settings.BaudRate=baudRate;
    00651                 break;
    00652         }
    00653     }
    00654     if (isOpen()) {
    00655         switch (baudRate) {
    00656
    00657             /*50 baud*/
    00658             case BAUD50:
    00659                 TTY_WARNING("Win_QextSerialPort: Windows does not support 50 baud operation.  Switching to 110 baud.");
    00660                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00661                 break;
    00662
    00663             /*75 baud*/
    00664             case BAUD75:
    00665                 TTY_WARNING("Win_QextSerialPort: Windows does not support 75 baud operation.  Switching to 110 baud.");
    00666                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00667                 break;
    00668
    00669             /*110 baud*/
    00670             case BAUD110:
    00671                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00672                 break;
    00673
    00674             /*134.5 baud*/
    00675             case BAUD134:
    00676                 TTY_WARNING("Win_QextSerialPort: Windows does not support 134.5 baud operation.  Switching to 110 baud.");
    00677                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00678                 break;
    00679
    00680             /*150 baud*/
    00681             case BAUD150:
    00682                 TTY_WARNING("Win_QextSerialPort: Windows does not support 150 baud operation.  Switching to 110 baud.");
    00683                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00684                 break;
    00685
    00686             /*200 baud*/
    00687             case BAUD200:
    00688                 TTY_WARNING("Win_QextSerialPort: Windows does not support 200 baud operation.  Switching to 110 baud.");
    00689                 Win_CommConfig.dcb.BaudRate=CBR_110;
    00690                 break;
    00691
    00692             /*300 baud*/
    00693             case BAUD300:
    00694                 Win_CommConfig.dcb.BaudRate=CBR_300;
    00695                 break;
    00696
    00697             /*600 baud*/
    00698             case BAUD600:
    00699                 Win_CommConfig.dcb.BaudRate=CBR_600;
    00700                 break;
    00701
    00702             /*1200 baud*/
    00703             case BAUD1200:
    00704                 Win_CommConfig.dcb.BaudRate=CBR_1200;
    00705                 break;
    00706
    00707             /*1800 baud*/
    00708             case BAUD1800:
    00709                 TTY_WARNING("Win_QextSerialPort: Windows does not support 1800 baud operation.  Switching to 1200 baud.");
    00710                 Win_CommConfig.dcb.BaudRate=CBR_1200;
    00711                 break;
    00712
    00713             /*2400 baud*/
    00714             case BAUD2400:
    00715                 Win_CommConfig.dcb.BaudRate=CBR_2400;
    00716                 break;
    00717
    00718             /*4800 baud*/
    00719             case BAUD4800:
    00720                 Win_CommConfig.dcb.BaudRate=CBR_4800;
    00721                 break;
    00722
    00723             /*9600 baud*/
    00724             case BAUD9600:
    00725                 Win_CommConfig.dcb.BaudRate=CBR_9600;
    00726                 break;
    00727
    00728             /*14400 baud*/
    00729             case BAUD14400:
    00730                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 14400 baud operation.");
    00731                 Win_CommConfig.dcb.BaudRate=CBR_14400;
    00732                 break;
    00733
    00734             /*19200 baud*/
    00735             case BAUD19200:
    00736                 Win_CommConfig.dcb.BaudRate=CBR_19200;
    00737                 break;
    00738
    00739             /*38400 baud*/
    00740             case BAUD38400:
    00741                 Win_CommConfig.dcb.BaudRate=CBR_38400;
    00742                 break;
    00743
    00744             /*56000 baud*/
    00745             case BAUD56000:
    00746                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 56000 baud operation.");
    00747                 Win_CommConfig.dcb.BaudRate=CBR_56000;
    00748                 break;
    00749
    00750             /*57600 baud*/
    00751             case BAUD57600:
    00752                 Win_CommConfig.dcb.BaudRate=CBR_57600;
    00753                 break;
    00754
    00755             /*76800 baud*/
    00756             case BAUD76800:
    00757                 TTY_WARNING("Win_QextSerialPort: Windows does not support 76800 baud operation.  Switching to 57600 baud.");
    00758                 Win_CommConfig.dcb.BaudRate=CBR_57600;
    00759                 break;
    00760
    00761             /*115200 baud*/
    00762             case BAUD115200:
    00763                 Win_CommConfig.dcb.BaudRate=CBR_115200;
    00764                 break;
    00765
    00766             /*128000 baud*/
    00767             case BAUD128000:
    00768                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 128000 baud operation.");
    00769                 Win_CommConfig.dcb.BaudRate=CBR_128000;
    00770                 break;
    00771
    00772             /*256000 baud*/
    00773             case BAUD256000:
    00774                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 256000 baud operation.");
    00775                 Win_CommConfig.dcb.BaudRate=CBR_256000;
    00776                 break;
    00777         }
    00778         SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00779     }
    00780     UNLOCK_MUTEX();
    00781 }

void Win_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.

  1.5 stop bits can only be used with 5 data bits.

  8 data bits cannot be used with space parity on POSIX systems.

Implements QextSerialBase.

    00470                                                           {
    00471     LOCK_MUTEX();
    00472     if (Settings.DataBits!=dataBits) {
    00473         if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) ||
    00474             (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5)) {
    00475         }
    00476         else {
    00477             Settings.DataBits=dataBits;
    00478         }
    00479     }
    00480     if (isOpen()) {
    00481         switch(dataBits) {
    00482
    00483             /*5 data bits*/
    00484             case DATA_5:
    00485                 if (Settings.StopBits==STOP_2) {
    00486                     TTY_WARNING("Win_QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
    00487                 }
    00488                 else {
    00489                     Win_CommConfig.dcb.ByteSize=5;
    00490                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00491                 }
    00492                 break;
    00493
    00494             /*6 data bits*/
    00495             case DATA_6:
    00496                 if (Settings.StopBits==STOP_1_5) {
    00497                     TTY_WARNING("Win_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
    00498                 }
    00499                 else {
    00500                     Win_CommConfig.dcb.ByteSize=6;
    00501                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00502                 }
    00503                 break;
    00504
    00505             /*7 data bits*/
    00506             case DATA_7:
    00507                 if (Settings.StopBits==STOP_1_5) {
    00508                     TTY_WARNING("Win_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
    00509                 }
    00510                 else {
    00511                     Win_CommConfig.dcb.ByteSize=7;
    00512                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00513                 }
    00514                 break;
    00515
    00516             /*8 data bits*/
    00517             case DATA_8:
    00518                 if (Settings.StopBits==STOP_1_5) {
    00519                     TTY_WARNING("Win_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
    00520                 }
    00521                 else {
    00522                     Win_CommConfig.dcb.ByteSize=8;
    00523                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00524                 }
    00525                 break;
    00526         }
    00527     }
    00528     UNLOCK_MUTEX();
    00529 }

void Win_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.

    00788                                         {
    00789     LOCK_MUTEX();
    00790     if (isOpen()) {
    00791         if (set) {
    00792             EscapeCommFunction(Win_Handle, SETDTR);
    00793         }
    00794         else {
    00795             EscapeCommFunction(Win_Handle, CLRDTR);
    00796         }
    00797     }
    00798     UNLOCK_MUTEX();
    00799 }

void Win_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

Implements QextSerialBase.

    00358                                                      {
    00359     LOCK_MUTEX();
    00360     if (Settings.FlowControl!=flow) {
    00361         Settings.FlowControl=flow;
    00362     }
    00363     if (isOpen()) {
    00364         switch(flow) {
    00365
    00366             /*no flow control*/
    00367             case FLOW_OFF:
    00368                 Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
    00369                 Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
    00370                 Win_CommConfig.dcb.fInX=FALSE;
    00371                 Win_CommConfig.dcb.fOutX=FALSE;
    00372                 SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00373                 break;
    00374
    00375             /*software (XON/XOFF) flow control*/
    00376             case FLOW_XONXOFF:
    00377                 Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
    00378                 Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
    00379                 Win_CommConfig.dcb.fInX=TRUE;
    00380                 Win_CommConfig.dcb.fOutX=TRUE;
    00381                 SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00382                 break;
    00383
    00384             case FLOW_HARDWARE:
    00385                 Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
    00386                 Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
    00387                 Win_CommConfig.dcb.fInX=FALSE;
    00388                 Win_CommConfig.dcb.fOutX=FALSE;
    00389                 SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00390                 break;
    00391         }
    00392     }
    00393     UNLOCK_MUTEX();
    00394 }

void Win_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

Implements QextSerialBase.

    00407                                                     {
    00408     LOCK_MUTEX();
    00409     if (Settings.Parity!=parity) {
    00410         Settings.Parity=parity;
    00411     }
    00412     if (isOpen()) {
    00413         Win_CommConfig.dcb.Parity=(unsigned char)parity;
    00414         switch (parity) {
    00415
    00416             /*space parity*/
    00417             case PAR_SPACE:
    00418                 if (Settings.DataBits==DATA_8) {
    00419                     TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: Space parity with 8 data bits is not supported by POSIX systems.");
    00420                 }
    00421                 Win_CommConfig.dcb.fParity=TRUE;
    00422                 break;
    00423
    00424             /*mark parity - WINDOWS ONLY*/
    00425             case PAR_MARK:
    00426                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning:  Mark parity is not supported by POSIX systems");
    00427                 Win_CommConfig.dcb.fParity=TRUE;
    00428                 break;
    00429
    00430             /*no parity*/
    00431             case PAR_NONE:
    00432                 Win_CommConfig.dcb.fParity=FALSE;
    00433                 break;
    00434
    00435             /*even parity*/
    00436             case PAR_EVEN:
    00437                 Win_CommConfig.dcb.fParity=TRUE;
    00438                 break;
    00439
    00440             /*odd parity*/
    00441             case PAR_ODD:
    00442                 Win_CommConfig.dcb.fParity=TRUE;
    00443                 break;
    00444         }
    00445         SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00446     }
    00447     UNLOCK_MUTEX();
    00448 }

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

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

    00107 {
    00108     port = name;
    00109 }

void Win_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.

    00806                                         {
    00807     LOCK_MUTEX();
    00808     if (isOpen()) {
    00809         if (set) {
    00810             EscapeCommFunction(Win_Handle, SETRTS);
    00811         }
    00812         else {
    00813             EscapeCommFunction(Win_Handle, CLRRTS);
    00814         }
    00815     }
    00816     UNLOCK_MUTEX();
    00817 }

void Win_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.

  1.5 stop bits cannot be used with 6 or more data bits.

  POSIX does not support 1.5 stop bits.

Implements QextSerialBase.

    00549                                                           {
    00550     LOCK_MUTEX();
    00551     if (Settings.StopBits!=stopBits) {
    00552         if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) ||
    00553             (stopBits==STOP_1_5 && Settings.DataBits!=DATA_5)) {
    00554         }
    00555         else {
    00556             Settings.StopBits=stopBits;
    00557         }
    00558     }
    00559     if (isOpen()) {
    00560         switch (stopBits) {
    00561
    00562             /*one stop bit*/
    00563             case STOP_1:
    00564                 Win_CommConfig.dcb.StopBits=ONESTOPBIT;
    00565                 SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00566                 break;
    00567
    00568             /*1.5 stop bits*/
    00569             case STOP_1_5:
    00570                 TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX.");
    00571                 if (Settings.DataBits!=DATA_5) {
    00572                     TTY_WARNING("Win_QextSerialPort: 1.5 stop bits can only be used with 5 data bits");
    00573                 }
    00574                 else {
    00575                     Win_CommConfig.dcb.StopBits=ONE5STOPBITS;
    00576                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00577                 }
    00578                 break;
    00579
    00580             /*two stop bits*/
    00581             case STOP_2:
    00582                 if (Settings.DataBits==DATA_5) {
    00583                     TTY_WARNING("Win_QextSerialPort: 2 stop bits cannot be used with 5 data bits");
    00584                 }
    00585                 else {
    00586                     Win_CommConfig.dcb.StopBits=TWOSTOPBITS;
    00587                     SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
    00588                 }
    00589                 break;
    00590         }
    00591     }
    00592     UNLOCK_MUTEX();
    00593 }

void Win_QextSerialPort::setTimeout | ( | ulong | sec,
|  | ulong | millisec |
| ) |  |  | `[virtual]`

Sets the read and write timeouts for the port to sec seconds and millisec milliseconds.

Implements QextSerialBase.

    00864                                                              {
    00865     LOCK_MUTEX();
    00866     Settings.Timeout_Sec=sec;
    00867     Settings.Timeout_Millisec=millisec;
    00868     if(isOpen()) {
    00869         Win_CommTimeouts.ReadIntervalTimeout = sec*1000+millisec;
    00870         Win_CommTimeouts.ReadTotalTimeoutMultiplier = sec*1000+millisec;
    00871         Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
    00872         Win_CommTimeouts.WriteTotalTimeoutMultiplier = sec*1000+millisec;
    00873         Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
    00874         SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
    00875     }
    00876     UNLOCK_MUTEX();
    00877 }

qint64 Win_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 Win_QextSerialPort::bytesAvailable() instead.

Implements QextSerialBase.

    00214                                       {
    00215     int availBytes;
    00216     COMSTAT Win_ComStat;
    00217     DWORD Win_ErrorMask=0;
    00218     ClearCommError(Win_Handle, &Win_ErrorMask, &Win_ComStat);
    00219     availBytes = Win_ComStat.cbInQue;
    00220     return (qint64)availBytes;
    00221 }

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.

    00156 {
    00157     return Settings.StopBits;
    00158 }

void Win_QextSerialPort::translateError | ( | ulong | error | ) | `[virtual]`

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

Implements QextSerialBase.

    00252                                                    {
    00253     if (error&CE_BREAK) {
    00254         lastErr=E_BREAK_CONDITION;
    00255     }
    00256     else if (error&CE_FRAME) {
    00257         lastErr=E_FRAMING_ERROR;
    00258     }
    00259     else if (error&CE_IOE) {
    00260         lastErr=E_IO_ERROR;
    00261     }
    00262     else if (error&CE_MODE) {
    00263         lastErr=E_INVALID_FD;
    00264     }
    00265     else if (error&CE_OVERRUN) {
    00266         lastErr=E_BUFFER_OVERRUN;
    00267     }
    00268     else if (error&CE_RXPARITY) {
    00269         lastErr=E_RECEIVE_PARITY_ERROR;
    00270     }
    00271     else if (error&CE_RXOVER) {
    00272         lastErr=E_RECEIVE_OVERFLOW;
    00273     }
    00274     else if (error&CE_TXFULL) {
    00275         lastErr=E_TRANSMIT_OVERFLOW;
    00276     }
    00277 }

void Win_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.

    00343                                          {
    00344
    00345     /*meaningless on unbuffered sequential device - return error and print a warning*/
    00346     TTY_WARNING("Win_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless");
    00347 }

qint64 Win_QextSerialPort::writeData | ( | const char * | data,
|  | qint64 | maxSize |
| ) |  |  | `[protected, virtual]`

Writes a block of data to the serial port. This function will write len 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.

    00320 {
    00321     LOCK_MUTEX();
    00322     int retVal=0;
    00323     DWORD Win_BytesWritten;
    00324     if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, &Win_BytesWritten, NULL)) {
    00325         lastErr=E_WRITE_FAILED;
    00326         retVal=-1;
    00327     }
    00328     else {
    00329         retVal=((int)Win_BytesWritten);
    00330     }
    00331     UNLOCK_MUTEX();
    00332
    00333     flush();
    00334     return retVal;
    00335 }

## Member Data Documentation

ulong QextSerialBase::lastErr`[protected, inherited]`

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

QString QextSerialBase::port`[protected, inherited]`

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

PortSettings QextSerialBase::Settings`[protected, inherited]`

COMMCONFIG Win_QextSerialPort::Win_CommConfig`[protected]`

COMMTIMEOUTS Win_QextSerialPort::Win_CommTimeouts`[protected]`

HANDLE Win_QextSerialPort::Win_Handle`[protected]`

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

- win_qextserialport.h
- win_qextserialport.cpp