QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QSerialPort Class Reference

#include <AndroidSerialPort.h>

Inheritance diagram for QSerialPort:
Collaboration diagram for QSerialPort:

Public Types

enum  Direction { Input = 1 , Output = 2 , AllDirections = Input | Output }
enum  BaudRate {
  Baud1200 = 1200 , Baud2400 = 2400 , Baud4800 = 4800 , Baud9600 = 9600 ,
  Baud19200 = 19200 , Baud38400 = 38400 , Baud57600 = 57600 , Baud115200 = 115200
}
enum  DataBits { Data5 = 5 , Data6 = 6 , Data7 = 7 , Data8 = 8 }
enum  Parity {
  NoParity = 0 , EvenParity = 2 , OddParity = 3 , SpaceParity = 4 ,
  MarkParity = 5
}
enum  StopBits { OneStop = 1 , OneAndHalfStop = 3 , TwoStop = 2 }
enum  FlowControl { NoFlowControl , HardwareControl , SoftwareControl }
enum  PinoutSignal {
  NoSignal = 0x00 , DataTerminalReadySignal = 0x04 , DataCarrierDetectSignal = 0x08 , DataSetReadySignal = 0x10 ,
  RingIndicatorSignal = 0x20 , RequestToSendSignal = 0x40 , ClearToSendSignal = 0x80 , SecondaryTransmittedDataSignal = 0x100 ,
  SecondaryReceivedDataSignal = 0x200
}
enum  SerialPortError {
  NoError , DeviceNotFoundError , PermissionError , OpenError ,
  WriteError , ReadError , ResourceError , UnsupportedOperationError ,
  UnknownError , TimeoutError , NotOpenError
}

Signals

void baudRateChanged (qint32 baudRate, QSerialPort::Directions directions)
void dataBitsChanged (QSerialPort::DataBits dataBits)
void parityChanged (QSerialPort::Parity parity)
void stopBitsChanged (QSerialPort::StopBits stopBits)
void flowControlChanged (QSerialPort::FlowControl flowControl)
void dataTerminalReadyChanged (bool set)
void requestToSendChanged (bool set)
void errorOccurred (QSerialPort::SerialPortError error)
 Emitted whenever the error is set, also to NoError.
void breakEnabledChanged (bool set)

Public Member Functions

 QSerialPort (QObject *parent=nullptr)
 QSerialPort (const QString &name, QObject *parent=nullptr)
 QSerialPort (const QSerialPortInfo &info, QObject *parent=nullptr)
 ~QSerialPort () override
void setPortName (const QString &name)
QString portName () const
void setPort (const QSerialPortInfo &info)
bool open (OpenMode mode) override
void close () override
bool setBaudRate (qint32 baudRate, Directions directions=AllDirections)
qint32 baudRate (Directions directions=AllDirections) const
bool setDataBits (DataBits dataBits)
DataBits dataBits () const
bool setParity (Parity parity)
Parity parity () const
bool setStopBits (StopBits stopBits)
StopBits stopBits () const
bool setFlowControl (FlowControl flowControl)
FlowControl flowControl () const
bool setDataTerminalReady (bool set)
bool isDataTerminalReady ()
bool setRequestToSend (bool set)
bool isRequestToSend ()
PinoutSignals pinoutSignals ()
bool setBreakEnabled (bool set=true)
bool isBreakEnabled () const
bool flush ()
 Hands buffered output to the device, as far as it takes it now, and returns whether it took any.
bool clear (Directions directions=AllDirections)
SerialPortError error () const
void clearError ()
void setReadBufferSize (qint64 size)
qint64 readBufferSize () const
int handle () const
 The file descriptor of the open device, or -1.
bool isSequential () const override
qint64 bytesAvailable () const override
qint64 bytesToWrite () const override
bool canReadLine () const override
bool waitForReadyRead (int msecs=30000) override
 Returns true only for input that was not announced before.
bool waitForBytesWritten (int msecs=30000) override

Protected Member Functions

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

Friends

class AndroidSerialBackendHost

Detailed Description

The serial port of QGC on Android. Qt Serial Port's own opens device nodes only, and Android lets an app reach a USB serial adapter through its USB API alone. This class has the name and the interface of Qt Serial Port's, so that code which uses a serial port is the same on every platform and includes <QtSerialPort/QSerialPort>. Of that interface it leaves out the properties and their bindables, and a baud rate for one direction only.

The port's name decides what it opens (AndroidSerialBackend): a USB serial adapter, which Java drives, or a serial device node. Input arrives on other threads and is announced on the port's own, which is the only one that may call the port.

Definition at line 28 of file AndroidSerialPort.h.

Member Enumeration Documentation

◆ BaudRate

Enumerator
Baud1200 
Baud2400 
Baud4800 
Baud9600 
Baud19200 
Baud38400 
Baud57600 
Baud115200 

Definition at line 47 of file AndroidSerialPort.h.

◆ DataBits

Enumerator
Data5 
Data6 
Data7 
Data8 

Definition at line 60 of file AndroidSerialPort.h.

◆ Direction

Enumerator
Input 
Output 
AllDirections 

Definition at line 38 of file AndroidSerialPort.h.

◆ FlowControl

Enumerator
NoFlowControl 
HardwareControl 
SoftwareControl 

Definition at line 87 of file AndroidSerialPort.h.

◆ Parity

Enumerator
NoParity 
EvenParity 
OddParity 
SpaceParity 
MarkParity 

Definition at line 69 of file AndroidSerialPort.h.

◆ PinoutSignal

Enumerator
NoSignal 
DataTerminalReadySignal 
DataCarrierDetectSignal 
DataSetReadySignal 
RingIndicatorSignal 
RequestToSendSignal 
ClearToSendSignal 
SecondaryTransmittedDataSignal 
SecondaryReceivedDataSignal 

Definition at line 95 of file AndroidSerialPort.h.

◆ SerialPortError

Enumerator
NoError 
DeviceNotFoundError 
PermissionError 
OpenError 
WriteError 
ReadError 
ResourceError 
UnsupportedOperationError 
UnknownError 
TimeoutError 
NotOpenError 

Definition at line 110 of file AndroidSerialPort.h.

◆ StopBits

Enumerator
OneStop 
OneAndHalfStop 
TwoStop 

Definition at line 79 of file AndroidSerialPort.h.

Constructor & Destructor Documentation

◆ QSerialPort() [1/3]

QSerialPort::QSerialPort ( QObject * parent = nullptr)
explicit

Definition at line 62 of file AndroidSerialPort.cc.

◆ QSerialPort() [2/3]

QSerialPort::QSerialPort ( const QString & name,
QObject * parent = nullptr )
explicit

Definition at line 66 of file AndroidSerialPort.cc.

References setPortName().

◆ QSerialPort() [3/3]

QSerialPort::QSerialPort ( const QSerialPortInfo & info,
QObject * parent = nullptr )
explicit

Definition at line 72 of file AndroidSerialPort.cc.

References setPort().

◆ ~QSerialPort()

QSerialPort::~QSerialPort ( )
override

Definition at line 78 of file AndroidSerialPort.cc.

References close().

Member Function Documentation

◆ baudRate()

qint32 QSerialPort::baudRate ( Directions directions = AllDirections) const

Definition at line 262 of file AndroidSerialPort.cc.

Referenced by baudRateChanged(), and setBaudRate().

◆ baudRateChanged

void QSerialPort::baudRateChanged ( qint32 baudRate,
QSerialPort::Directions directions )
signal

References baudRate().

Referenced by setBaudRate().

◆ breakEnabledChanged

void QSerialPort::breakEnabledChanged ( bool set)
signal

Referenced by setBreakEnabled().

◆ bytesAvailable()

qint64 QSerialPort::bytesAvailable ( ) const
override

Definition at line 416 of file AndroidSerialPort.cc.

◆ bytesToWrite()

qint64 QSerialPort::bytesToWrite ( ) const
override

Definition at line 422 of file AndroidSerialPort.cc.

Referenced by waitForBytesWritten().

◆ canReadLine()

bool QSerialPort::canReadLine ( ) const
override

Definition at line 428 of file AndroidSerialPort.cc.

◆ clear()

bool QSerialPort::clear ( Directions directions = AllDirections)

Definition at line 821 of file AndroidSerialPort.cc.

References Input, and Output.

◆ clearError()

void QSerialPort::clearError ( )

Definition at line 229 of file AndroidSerialPort.cc.

References NoError.

Referenced by open().

◆ close()

void QSerialPort::close ( )
override

Definition at line 155 of file AndroidSerialPort.cc.

References NotOpenError, ResourceError, and WriteError.

Referenced by ~QSerialPort().

◆ dataBits()

DataBits QSerialPort::dataBits ( ) const
inline

Definition at line 139 of file AndroidSerialPort.h.

Referenced by dataBitsChanged(), and setDataBits().

◆ dataBitsChanged

void QSerialPort::dataBitsChanged ( QSerialPort::DataBits dataBits)
signal

References dataBits().

Referenced by setDataBits().

◆ dataTerminalReadyChanged

void QSerialPort::dataTerminalReadyChanged ( bool set)
signal

Referenced by setDataTerminalReady().

◆ error()

SerialPortError QSerialPort::error ( ) const
inline

Definition at line 168 of file AndroidSerialPort.h.

Referenced by AndroidSerialBackendHost, and errorOccurred().

◆ errorOccurred

void QSerialPort::errorOccurred ( QSerialPort::SerialPortError error)
signal

Emitted whenever the error is set, also to NoError.

References error().

Referenced by SerialWorker::setupPort(), and GPSDeviceTransport::waitUntil().

◆ flowControl()

FlowControl QSerialPort::flowControl ( ) const
inline

Definition at line 151 of file AndroidSerialPort.h.

Referenced by flowControlChanged(), and setFlowControl().

◆ flowControlChanged

void QSerialPort::flowControlChanged ( QSerialPort::FlowControl flowControl)
signal

References flowControl().

Referenced by setFlowControl().

◆ flush()

bool QSerialPort::flush ( )

Hands buffered output to the device, as far as it takes it now, and returns whether it took any.

Definition at line 811 of file AndroidSerialPort.cc.

◆ handle()

int QSerialPort::handle ( ) const

The file descriptor of the open device, or -1.

Definition at line 393 of file AndroidSerialPort.cc.

◆ isBreakEnabled()

bool QSerialPort::isBreakEnabled ( ) const
inline

Definition at line 162 of file AndroidSerialPort.h.

◆ isDataTerminalReady()

bool QSerialPort::isDataTerminalReady ( )

Definition at line 338 of file AndroidSerialPort.cc.

References DataTerminalReadySignal, and pinoutSignals().

◆ isRequestToSend()

bool QSerialPort::isRequestToSend ( )

Definition at line 367 of file AndroidSerialPort.cc.

References pinoutSignals(), and RequestToSendSignal.

◆ isSequential()

bool QSerialPort::isSequential ( ) const
override

Definition at line 411 of file AndroidSerialPort.cc.

◆ open()

bool QSerialPort::open ( OpenMode mode)
override

Definition at line 100 of file AndroidSerialPort.cc.

References clearError(), OpenError, and UnsupportedOperationError.

◆ parity()

Parity QSerialPort::parity ( ) const
inline

Definition at line 143 of file AndroidSerialPort.h.

Referenced by parityChanged(), and setParity().

◆ parityChanged

void QSerialPort::parityChanged ( QSerialPort::Parity parity)
signal

References parity().

Referenced by setParity().

◆ pinoutSignals()

QSerialPort::PinoutSignals QSerialPort::pinoutSignals ( )

Definition at line 372 of file AndroidSerialPort.cc.

References NoSignal, and AndroidSerialBackend::pinoutSignals().

Referenced by isDataTerminalReady(), and isRequestToSend().

◆ portName()

QString QSerialPort::portName ( ) const

◆ readBufferSize()

qint64 QSerialPort::readBufferSize ( ) const
inline

Definition at line 177 of file AndroidSerialPort.h.

◆ readData()

qint64 QSerialPort::readData ( char * data,
qint64 maxSize )
overrideprotected

Definition at line 438 of file AndroidSerialPort.cc.

◆ requestToSendChanged

void QSerialPort::requestToSendChanged ( bool set)
signal

Referenced by setRequestToSend().

◆ setBaudRate()

bool QSerialPort::setBaudRate ( qint32 baudRate,
Directions directions = AllDirections )

A closed port keeps the settings it is given and applies them when it opens. An open port keeps a setting only if the device took it.

Definition at line 234 of file AndroidSerialPort.cc.

References AllDirections, baudRate(), baudRateChanged(), and UnsupportedOperationError.

◆ setBreakEnabled()

bool QSerialPort::setBreakEnabled ( bool set = true)

◆ setDataBits()

bool QSerialPort::setDataBits ( DataBits dataBits)

Definition at line 267 of file AndroidSerialPort.cc.

References dataBits(), and dataBitsChanged().

◆ setDataTerminalReady()

bool QSerialPort::setDataTerminalReady ( bool set)

Does not ask the device how the line is: it signals a change from what the port itself last set since it opened, and the first set counts as one. Likewise setRequestToSend().

Definition at line 323 of file AndroidSerialPort.cc.

References dataTerminalReadyChanged(), and AndroidSerialBackend::setDataTerminalReady().

◆ setFlowControl()

bool QSerialPort::setFlowControl ( FlowControl flowControl)

Definition at line 309 of file AndroidSerialPort.cc.

References flowControl(), and flowControlChanged().

◆ setParity()

bool QSerialPort::setParity ( Parity parity)

Definition at line 281 of file AndroidSerialPort.cc.

References parity(), and parityChanged().

◆ setPort()

void QSerialPort::setPort ( const QSerialPortInfo & info)

Definition at line 95 of file AndroidSerialPort.cc.

References QSerialPortInfo::systemLocation().

Referenced by QSerialPort().

◆ setPortName()

void QSerialPort::setPortName ( const QString & name)

Definition at line 85 of file AndroidSerialPort.cc.

References QSerialPortInfo::portNameToSystemLocation().

Referenced by QSerialPort().

◆ setReadBufferSize()

void QSerialPort::setReadBufferSize ( qint64 size)

How much input the port lets its owner see at a time: bytesAvailable() does not exceed it. What arrives beyond it waits, hidden, for a read to make room, and when that alone reaches the limit the device is read no further, so the port holds up to twice the limit. 0 or less is no limit.

Definition at line 398 of file AndroidSerialPort.cc.

◆ setRequestToSend()

bool QSerialPort::setRequestToSend ( bool set)

◆ setStopBits()

bool QSerialPort::setStopBits ( StopBits stopBits)

Definition at line 295 of file AndroidSerialPort.cc.

References stopBits(), and stopBitsChanged().

◆ stopBits()

StopBits QSerialPort::stopBits ( ) const
inline

Definition at line 147 of file AndroidSerialPort.h.

Referenced by setStopBits(), and stopBitsChanged().

◆ stopBitsChanged

void QSerialPort::stopBitsChanged ( QSerialPort::StopBits stopBits)
signal

References stopBits().

Referenced by setStopBits().

◆ waitForBytesWritten()

bool QSerialPort::waitForBytesWritten ( int msecs = 30000)
override

Definition at line 678 of file AndroidSerialPort.cc.

References bytesToWrite(), and TimeoutError.

◆ waitForReadyRead()

bool QSerialPort::waitForReadyRead ( int msecs = 30000)
override

Returns true only for input that was not announced before.

Definition at line 645 of file AndroidSerialPort.cc.

References TimeoutError.

◆ writeData()

qint64 QSerialPort::writeData ( const char * data,
qint64 maxSize )
overrideprotected

Definition at line 697 of file AndroidSerialPort.cc.

References WriteError.

◆ AndroidSerialBackendHost


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