Home · All Classes · Grouped Classes · Annotated · Functions

QBluetoothRfcommSerialPort Class Reference

The QBluetoothRfcommSerialPort class represents a RFCOMM serial port device. More...

    #include <QBluetoothRfcommSerialPort>

Inherits QObject.

Public Types

Public Functions

Signals

Static Public Members

Additional Inherited Members


Detailed Description

The QBluetoothRfcommSerialPort class represents a RFCOMM serial port device.

This class enables conversion of RFCOMM sockets into serial tty devices. The class can be used in two major ways, by adapting an existing connected RFCOMM socket or by using the connect() function to establish a client connection to a remote device and adapt the resulting connection to a tty device.

The resulting tty device can be used by other applications like a regular serial tty device.

    // Adapt a connected RFCOMM socket into a serial tty device

    if (rfcommSocket->state() != QBluetoothRfcommSocket::ConnectedState) {
        // Bail out
        return;
    }

    QBluetoothRfcommSerialPort *serial =
        new QBluetoothRfcommSerialPort(rfcommSocket);

    if (serial->id() == -1) {
        // Error creating serial port
        return;
    }

    rfcommSocket->close();

    // Use serial port
    openSerialPort(serial->device());

See also QBluetoothRfcommSocket and QSerialIODevice.


Member Type Documentation

enum QBluetoothRfcommSerialPort::Error

Defines errors that could occur in QBluetoothRfcommSerialPort

ConstantValueDescription
QBluetoothRfcommSerialPort::NoError0No error has occurred.
QBluetoothRfcommSerialPort::SocketNotConnected1The given socket is not connected.
QBluetoothRfcommSerialPort::ConnectionFailed2Could not connect to the remote device.
QBluetoothRfcommSerialPort::ConnectionCancelled3Connection has been cancelled.
QBluetoothRfcommSerialPort::CreationError4Could not create the serial port device.

enum QBluetoothRfcommSerialPort::Flag
flags QBluetoothRfcommSerialPort::Flags

Defines flags that alter the behavior of the QBluetoothRfcommSerialPort

ConstantValueDescription
QBluetoothRfcommSerialPort::KeepAlive0x01Deleting the serial port object will not necessarily shut down the serial port. The serial port will be kept open until all open handles (file descriptors) to the serial port are closed. You can use the release() method to forcibly delete a serial port.

The Flags type is a typedef for QFlags<Flag>. It stores an OR combination of Flag values.


Member Function Documentation

QBluetoothRfcommSerialPort::QBluetoothRfcommSerialPort ( QObject * parent = 0 )

Constructs a new RFCOMM serial port object. The parent is passed to the QObject constructor.

QBluetoothRfcommSerialPort::QBluetoothRfcommSerialPort ( QBluetoothRfcommSocket * socket, QBluetoothRfcommSerialPort::Flags deviceFlags = 0, QObject * parent = 0 )

Converts a connected RFCOMM socket to an RFCOMM serial port.

This constructor is useful in situations where you already have a connected RFCOMM socket and wish to convert it to a serial port. This is true of connections returned by QBluetoothRfcommServer::nextPendingConnection() or RFCOMM socket connections which require non-blocking connections.

Note: The caller should call QBluetoothRfcommSocket::close() on socket immediately after calling this constructor. Before the created QBluetoothRfcommSerialPort device can be used, the socket should be closed. The deviceFlags parameter holds the optional flags that modify the serial port behavior.

In case the device could not be created or an error occurred, the id() method will return -1. The caller should check the return value of id() before using the serial port device.

See also id().

QBluetoothRfcommSerialPort::~QBluetoothRfcommSerialPort ()

Destroys a Bluetooth serial port object. If the instance is managing a serial port, disconnect() will be called first.

bool QBluetoothRfcommSerialPort::connect ( const QBluetoothAddress & local, const QBluetoothAddress & remote, int channel )

This method tries to establish a connection to the remote device with address remote on channel. The local device is given by local. This method will return true if the request could be started, and false otherwise. The connected() signal will be sent once the operation completes.

You can cancel the connection process at any time by calling disconnect(). If the process is cancelled, the error() signal will be sent with the QBluetoothRfcommSerialPort::ConnectionCancelled error set.

See also error() and connected().

void QBluetoothRfcommSerialPort::connected ( const QString & device )   [signal]

This signal is emitted whenever the RFCOMM serial port is connected. The device parameter holds the device name of the created serial port.

See also connect().

QString QBluetoothRfcommSerialPort::device () const

Returns the RFCOMM tty device which is being managed by the current instance of this class. If the instance is not managing a device, an empty string is returned.

See also id().

bool QBluetoothRfcommSerialPort::disconnect ()

Returns true if able to disconnects the serial port; otherwise returns false. The underlying device will be removed unless the QBluetoothRfcommSerialPort::KeepAlive flag is set. The disconnected() signal will be sent once the disconnection is complete.

See also disconnected().

void QBluetoothRfcommSerialPort::disconnected ()   [signal]

This signal is emitted whenever the RFCOMM serial port is disconnected.

See also disconnect().

QBluetoothRfcommSerialPort::Error QBluetoothRfcommSerialPort::error () const

Returns the last error that has occurred.

See also errorString().

void QBluetoothRfcommSerialPort::error ( QBluetoothRfcommSerialPort::Error err )   [signal]

This is an overloaded member function, provided for convenience.

This signal is emitted whenever an error occurs. The err parameter holds the error that has occurred.

See also connect().

QString QBluetoothRfcommSerialPort::errorString () const

Returns the human readable form of the last error that has occurred.

See also error().

QBluetoothRfcommSerialPort::Flags QBluetoothRfcommSerialPort::flags () const

Returns the flags that the serial port has been opened with.

int QBluetoothRfcommSerialPort::id () const

Returns the device id of the associated RFCOMM device. If no device is found, returns -1. The device id is usually in the range of 0-31.

See also device().

QList<int> QBluetoothRfcommSerialPort::listDevices ()   [static]

Returns a list of all RFCOMM device bindings.

See also releaseDevice().

QList<int> QBluetoothRfcommSerialPort::listDevices ( const QBluetoothLocalDevice & local )   [static]

This is an overloaded member function, provided for convenience.

Returns a list of all RFCOMM devices for a particular Bluetooth adapter given by local.

See also releaseDevice().

QBluetoothAddress QBluetoothRfcommSerialPort::localAddress () const

Returns the address of the local device. If the socket is not currently connected, returns QBluetoothAddress::invalid.

See also remoteAddress().

bool QBluetoothRfcommSerialPort::releaseDevice ( int id )   [static]

Returns true if able to release the RFCOMM device with id; otherwise returns false.

See also listDevices().

QBluetoothAddress QBluetoothRfcommSerialPort::remoteAddress () const

Returns the address of the remote device. If the socket is not currently connected, returns QBluetoothAddress::invalid.

See also localAddress() and remoteChannel().

int QBluetoothRfcommSerialPort::remoteChannel () const

Returns the RFCOMM channel of the remote device. If the socket is not currently connected, returns -1.

See also remoteAddress().


Copyright © 2008 Nokia Trademarks
Qtopia 4.3.3