Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QSerialPort Class Reference
[QtBaseModule]

The QSerialPort class provides a simple serial device interface. More...

    #include <QSerialPort>

Inherits QSerialIODevice.

Public Functions

Static Public Members

Additional Inherited Members


Detailed Description

The QSerialPort class provides a simple serial device interface.

This class manages a very simple serial device, which is accessed at a specific baud rate with no parity, 8 data bits, and 1 stop bit. It is intended for communicating with GSM modems and the like.

The recommended way to create an instance of this class is to call the QSerialPort::create() method.

See also QSerialPort::create() and QSerialIODevice.


Member Function Documentation

QSerialPort::QSerialPort ( const QString & device, int rate = 38400, bool trackStatus = false )

Construct a new serial device handler object for the specified device at the given rate. After construction, it is necessary to call QSerialPort::open() to complete initialization.

If trackStatus is true, then the device should attempt to track changes in DSR, DCD, and CTS. This may require the use of a regular timeout, which will be detrimental to battery life.

Status tracking should only be enabled when absolutely required. It isn't required for modems that support GSM 07.10 multiplexing, as the multiplexing mechanism has its own method of tracking status changes that does not require the use of a timeout.

The device name is usually something like /dev/ttyS0, but it can have the special form sim:hostname, where hostname is the name of a host running a phone simulator daemon (usually localhost). The phone simulator mode is intended for debugging purposes only.

QSerialPort::~QSerialPort ()

Destruct this serial device. If the device is currently open, it will be closed.

void QSerialPort::close ()   [virtual]

Closes the serial device.

Reimplemented from QIODevice.

QSerialPort * QSerialPort::create ( const QString & name, int defaultRate = 115200, bool flowControl = false )   [static]

Create and open a serial device from a name of the form device:rate. Returns NULL if the device could not be opened. The defaultRate parameter indicates the default rate to use if :rate was not included in the device name. If flowControl is true, then CTS/RTS flow control should be enabled on the device.

The name parameter can have the special form sim:hostname, where hostname is the name of a host running a phone simulator daemon (usually localhost). The phone simulator mode is intended for debugging purposes only.

int QSerialPort::fd () const

Returns the operating system file descriptor for this serial port, or -1 if the port is currently closed.

This function was introduced in Qtopia 4.3.

bool QSerialPort::flowControl () const

Returns the state of CTS/RTS flow control on the serial device. The default value is false.

See also setFlowControl().

bool QSerialPort::flush ()

Returns true if able to flush all buffered data to the physical serial device; otherwise returns false.

bool QSerialPort::keepOpen () const

Returns true if tty devices should be kept open on a zero-byte read; otherwise returns false. The default value is true.

Some serial devices return zero bytes when there is no data available, instead of returning the system error EWOULDBLOCK. When keepOpen() is true, a zero-byte read will be treated the same as EWOULDBLOCK. When keepOpen() is false, a zero-byte read will be interpreted as an unrecoverable error and the serial port will be closed.

For Bluetooth RFCOMM sockets, keepOpen() should be false.

The keepOpen() state is ignored if the underlying serial device is a socket connection to a phone simulator.

See also setKeepOpen().

bool QSerialPort::open ( OpenMode mode )

Opens the serial device with the specified mode. Returns true if the device could be opened; false otherwise.

void QSerialPort::setFlowControl ( bool value )

Sets the state of CTS/RTS flow control on the serial device to value. This must be called before QSerialPort::open(). Changes to the value after opening will be ignored.

See also flowControl().

void QSerialPort::setKeepOpen ( bool value )

Sets the keep open flag to value. The default value is true.

Some serial devices return zero bytes when there is no data available, instead of returning the system error EWOULDBLOCK. When value is true, a zero-byte read will be treated the same as EWOULDBLOCK. When value is false, a zero-byte read will be interpreted as an unrecoverable error and the serial port will be closed.

For Bluetooth RFCOMM sockets, value should be false.

The state of value is ignored if the underlying serial device is a socket connection to a phone simulator.

See also keepOpen().


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3