QlightRead package | ESS final project 1.22-beta

Posix_QextSerialPort Class Reference

#include <posix_qextserialport.h>

List of all members.

Public Member Functions

 Posix_QextSerialPort ()
 Posix_QextSerialPort (const Posix_QextSerialPort &s)
 Posix_QextSerialPort (const QString &name)
 Posix_QextSerialPort (const PortSettings &settings)
 Posix_QextSerialPort (const QString &name, const PortSettings &settings)
Posix_QextSerialPortoperator= (const Posix_QextSerialPort &s)
virtual ~Posix_QextSerialPort ()
virtual void setBaudRate (BaudRateType)
virtual void setDataBits (DataBitsType)
virtual void setParity (ParityType)
virtual void setStopBits (StopBitsType)
virtual void setFlowControl (FlowType)
virtual void setTimeout (ulong, ulong)
virtual bool open (OpenMode mode=0)
virtual void close ()
virtual void flush ()
virtual qint64 size () const
virtual qint64 bytesAvailable ()
virtual void ungetChar (char c)
virtual void translateError (ulong error)
virtual void setDtr (bool set=true)
virtual void setRts (bool set=true)
virtual ulong lineStatus ()

Protected Member Functions

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

Protected Attributes

QFile * Posix_File
struct termios Posix_CommConfig
struct timeval Posix_Timeout
struct timeval Posix_Copy_Timeout

Detailed Description

Version:
1.0.0
Author:
Stefan Sander

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.

Definition at line 14 of file posix_qextserialport.h.


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.

Definition at line 40 of file posix_qextserialport.cpp.

Posix_QextSerialPort::Posix_QextSerialPort ( const Posix_QextSerialPort s)

Copy constructor.

Definition at line 50 of file posix_qextserialport.cpp.

Posix_QextSerialPort::Posix_QextSerialPort ( const QString &  name)

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

Definition at line 75 of file posix_qextserialport.cpp.

Posix_QextSerialPort::Posix_QextSerialPort ( const PortSettings &  settings)

Constructs a port with default name and specified settings.

Definition at line 85 of file posix_qextserialport.cpp.

Here is the call graph for this function:

Posix_QextSerialPort::Posix_QextSerialPort ( const QString &  name,
const PortSettings &  settings 
)

Constructs a port with specified name and settings.

Definition at line 102 of file posix_qextserialport.cpp.

Here is the call graph for this function:

Posix_QextSerialPort::~Posix_QextSerialPort ( ) [virtual]

Standard destructor.

Definition at line 141 of file posix_qextserialport.cpp.

Here is the call graph for this function:


Member Function Documentation

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().

Definition at line 908 of file posix_qextserialport.cpp.

Here is the call graph for this function:

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.

Definition at line 864 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 877 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

unsigned long Posix_QextSerialPort::lineStatus ( ) [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.

Definition at line 1041 of file posix_qextserialport.cpp.

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

Definition at line 816 of file posix_qextserialport.cpp.

Here is the call graph for this function:

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

Override the = operator.

Definition at line 119 of file posix_qextserialport.cpp.

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

Definition at line 1085 of file posix_qextserialport.cpp.

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

Definition at line 189 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 512 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 979 of file posix_qextserialport.cpp.

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.

Definition at line 745 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 603 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 1001 of file posix_qextserialport.cpp.

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.

Definition at line 692 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 795 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 893 of file posix_qextserialport.cpp.

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

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

Definition at line 956 of file posix_qextserialport.cpp.

Here is the caller graph for this function:

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.

Definition at line 946 of file posix_qextserialport.cpp.

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

Definition at line 1106 of file posix_qextserialport.cpp.

Here is the call graph for this function:


Member Data Documentation

struct termios Posix_QextSerialPort::Posix_CommConfig [protected]

Definition at line 48 of file posix_qextserialport.h.

struct timeval Posix_QextSerialPort::Posix_Copy_Timeout [protected]

Definition at line 50 of file posix_qextserialport.h.

Definition at line 47 of file posix_qextserialport.h.

struct timeval Posix_QextSerialPort::Posix_Timeout [protected]

Definition at line 49 of file posix_qextserialport.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines