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

Provides functions to access serial ports. More...

#include <qserialport.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)
 
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)
 
virtual ~QSerialPort ()
 
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
 the data baud rate for the desired direction
 
bool setDataBits (DataBits dataBits)
 
DataBits dataBits () const
 the data bits in a frame
 
QBindable< DataBitsbindableDataBits ()
 
bool setParity (Parity parity)
 
Parity parity () const
 the parity checking mode
 
QBindable< ParitybindableParity ()
 
bool setStopBits (StopBits stopBits)
 
StopBits stopBits () const
 the number of stop bits in a frame
 
QBindable< StopBitsbindableStopBits ()
 
bool setFlowControl (FlowControl flowControl)
 
FlowControl flowControl () const
 the desired flow control mode
 
QBindable< FlowControlbindableFlowControl ()
 
bool setDataTerminalReady (bool set)
 
bool isDataTerminalReady ()
 
bool setRequestToSend (bool set)
 
bool isRequestToSend ()
 
PinoutSignals pinoutSignals ()
 
bool flush ()
 
bool clear (Directions directions=AllDirections)
 
SerialPortError error () const
 the error status of the serial port
 
void clearError ()
 
QBindable< SerialPortErrorbindableError () const
 
qint64 readBufferSize () const
 
void setReadBufferSize (qint64 size)
 
bool isSequential () const override
 
qint64 bytesAvailable () const override
 
qint64 bytesToWrite () const override
 
bool canReadLine () const override
 
bool waitForReadyRead (int msecs=30000) override
 
bool waitForBytesWritten (int msecs=30000) override
 
bool setBreakEnabled (bool set=true)
 
bool isBreakEnabled () const
 
QBindable< bool > bindableIsBreakEnabled ()
 
Handle handle () const
 

Protected Member Functions

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

Detailed Description

Provides functions to access serial ports.

\reentrant

\inmodule QtSerialPort

Since
5.1

You can get information about the available serial ports using the QSerialPortInfo helper class, which allows an enumeration of all the serial ports in the system. This is useful to obtain the correct name of the serial port you want to use. You can pass an object of the helper class as an argument to the setPort() or setPortName() methods to assign the desired serial device.

After setting the port, you can open it in read-only (r/o), write-only (w/o), or read-write (r/w) mode using the open() method.

Note
The serial port is always opened with exclusive access (that is, no other process or thread can access an already opened serial port).

Use the close() method to close the port and cancel the I/O operations.

Having successfully opened, QSerialPort tries to determine the current configuration of the port and initializes itself. You can reconfigure the port to the desired setting using the setBaudRate(), setDataBits(), setParity(), setStopBits(), and setFlowControl() methods.

There are a couple of properties to work with the pinout signals namely: QSerialPort::dataTerminalReady, QSerialPort::requestToSend. It is also possible to use the pinoutSignals() method to query the current pinout signals set.

Once you know that the ports are ready to read or write, you can use the read() or write() methods. Alternatively the readLine() and readAll() convenience methods can also be invoked. If not all the data is read at once, the remaining data will be available for later as new incoming data is appended to the QSerialPort's internal read buffer. You can limit the size of the read buffer using setReadBufferSize().

QSerialPort provides a set of functions that suspend the calling thread until certain signals are emitted. These functions can be used to implement blocking serial ports:

\list

\endlist

See the following example:

int numRead = 0, numReadTotal = 0;
char buffer[50];
for (;;) {
numRead = serial.read(buffer, 50);
// Do whatever with the array
numReadTotal += numRead;
if (numRead == 0 && !serial.waitForReadyRead())
break;
}

If \l{QIODevice::}{waitForReadyRead()} returns false, the connection has been closed or an error has occurred.

If an error occurs at any point in time, QSerialPort will emit the errorOccurred() signal. You can also call error() to find the type of error that occurred last.

Programming with a blocking serial port is radically different from programming with a non-blocking serial port. A blocking serial port does not require an event loop and typically leads to simpler code. However, in a GUI application, blocking serial port should only be used in non-GUI threads, to avoid freezing the user interface.

For more details about these approaches, refer to the \l {Qt Serial Port Examples}{example} applications.

The QSerialPort class can also be used with QTextStream and QDataStream's stream operators (operator<<() and operator>>()). There is one issue to be aware of, though: make sure that enough data is available before attempting to read by using the operator>>() overloaded operator.

See also
QSerialPortInfo

Definition at line 16 of file qserialport.h.

Member Enumeration Documentation

◆ BaudRate

This enum describes the baud rate which the communication device operates with.

Note
Only the most common standard baud rates are listed in this enum.

\value Baud1200 1200 baud. \value Baud2400 2400 baud. \value Baud4800 4800 baud. \value Baud9600 9600 baud. \value Baud19200 19200 baud. \value Baud38400 38400 baud. \value Baud57600 57600 baud. \value Baud115200 115200 baud.

See also
QSerialPort::baudRate
Enumerator
Baud1200 
Baud2400 
Baud4800 
Baud9600 
Baud19200 
Baud38400 
Baud57600 
Baud115200 

Definition at line 46 of file qserialport.h.

◆ DataBits

This enum describes the number of data bits used.

\value Data5 The number of data bits in each character is 5. It is used for Baudot code. It generally only makes sense with older equipment such as teleprinters. \value Data6 The number of data bits in each character is 6. It is rarely used. \value Data7 The number of data bits in each character is 7. It is used for true ASCII. It generally only makes sense with older equipment such as teleprinters. \value Data8 The number of data bits in each character is 8. It is used for most kinds of data, as this size matches the size of a byte. It is almost universally used in newer applications.

See also
QSerialPort::dataBits
Enumerator
Data5 
Data6 
Data7 
Data8 

Definition at line 59 of file qserialport.h.

◆ Direction

This enum describes the possible directions of the data transmission.

Note
This enumeration is used for setting the baud rate of the device separately for each direction on some operating systems (for example, POSIX-like).

\value Input Input direction. \value Output Output direction. \value AllDirections Simultaneously in two directions.

Enumerator
Input 
Output 
AllDirections 

Definition at line 37 of file qserialport.h.

◆ FlowControl

This enum describes the flow control used.

\value NoFlowControl No flow control. \value HardwareControl Hardware flow control (RTS/CTS). \value SoftwareControl Software flow control (XON/XOFF).

See also
QSerialPort::flowControl
Enumerator
NoFlowControl 
HardwareControl 
SoftwareControl 

Definition at line 86 of file qserialport.h.

◆ Parity

This enum describes the parity scheme used.

\value NoParity No parity bit it sent. This is the most common parity setting. Error detection is handled by the communication protocol. \value EvenParity The number of 1 bits in each character, including the parity bit, is always even. \value OddParity The number of 1 bits in each character, including the parity bit, is always odd. It ensures that at least one state transition occurs in each character. \value SpaceParity Space parity. The parity bit is sent in the space signal condition. It does not provide error detection information. \value MarkParity Mark parity. The parity bit is always set to the mark signal condition (logical 1). It does not provide error detection information.

See also
QSerialPort::parity
Enumerator
NoParity 
EvenParity 
OddParity 
SpaceParity 
MarkParity 

Definition at line 68 of file qserialport.h.

◆ PinoutSignal

This enum describes the possible RS-232 pinout signals.

\value NoSignal No line active \value DataTerminalReadySignal DTR (Data Terminal Ready). \value DataCarrierDetectSignal DCD (Data Carrier Detect). \value DataSetReadySignal DSR (Data Set Ready). \value RingIndicatorSignal RNG (Ring Indicator). \value RequestToSendSignal RTS (Request To Send). \value ClearToSendSignal CTS (Clear To Send). \value SecondaryTransmittedDataSignal STD (Secondary Transmitted Data). \value SecondaryReceivedDataSignal SRD (Secondary Received Data).

See also
pinoutSignals(), QSerialPort::dataTerminalReady, QSerialPort::requestToSend
Enumerator
NoSignal 
DataTerminalReadySignal 
DataCarrierDetectSignal 
DataSetReadySignal 
RingIndicatorSignal 
RequestToSendSignal 
ClearToSendSignal 
SecondaryTransmittedDataSignal 
SecondaryReceivedDataSignal 

Definition at line 94 of file qserialport.h.

◆ SerialPortError

This enum describes the errors that may be contained by the QSerialPort::error property.

\value NoError No error occurred.

\value DeviceNotFoundError An error occurred while attempting to open an non-existing device.

\value PermissionError An error occurred while attempting to open an already opened device by another process or a user not having enough permission and credentials to open.

\value OpenError An error occurred while attempting to open an already opened device in this object.

\value NotOpenError This error occurs when an operation is executed that can only be successfully performed if the device is open. This value was introduced in QtSerialPort 5.2.

\value WriteError An I/O error occurred while writing the data.

\value ReadError An I/O error occurred while reading the data.

\value ResourceError An I/O error occurred when a resource becomes unavailable, e.g. when the device is unexpectedly removed from the system.

\value UnsupportedOperationError The requested device operation is not supported or prohibited by the running operating system.

\value TimeoutError A timeout error occurred. This value was introduced in QtSerialPort 5.2.

\value UnknownError An unidentified error occurred.

See also
QSerialPort::error
Enumerator
NoError 
DeviceNotFoundError 
PermissionError 
OpenError 
WriteError 
ReadError 
ResourceError 
UnsupportedOperationError 
UnknownError 
TimeoutError 
NotOpenError 

Definition at line 109 of file qserialport.h.

◆ StopBits

This enum describes the number of stop bits used.

\value OneStop 1 stop bit. \value OneAndHalfStop 1.5 stop bits. This is only for the Windows platform. \value TwoStop 2 stop bits.

See also
QSerialPort::stopBits
Enumerator
OneStop 
OneAndHalfStop 
TwoStop 

Definition at line 78 of file qserialport.h.

Constructor & Destructor Documentation

◆ QSerialPort() [1/3]

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

Constructs a new serial port object with the given parent.

Definition at line 332 of file qserialport.cpp.

◆ QSerialPort() [2/3]

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

Constructs a new serial port object with the given parent to represent the serial port with the specified name.

The name should have a specific format; see the setPort() method.

Definition at line 342 of file qserialport.cpp.

References setPortName().

◆ QSerialPort() [3/3]

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

Constructs a new serial port object with the given parent to represent the serial port with the specified helper class serialPortInfo.

Definition at line 352 of file qserialport.cpp.

References setPort().

◆ ~QSerialPort()

QSerialPort::~QSerialPort ( )
virtual

Closes the serial port, if necessary, and then destroys object.

Definition at line 361 of file qserialport.cpp.

References close().

Referenced by setBaudRate().

Member Function Documentation

◆ baudRate()

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

the data baud rate for the desired direction

If the setting is successful or set before opening the port, returns true; otherwise returns false and sets an error code which can be obtained by accessing the value of the QSerialPort::error property. To set the baud rate, use the enumeration QSerialPort::BaudRate or any positive qint32 value.

Note
If the setting is set before opening the port, the actual serial port setting is done automatically in the \l{QSerialPort::open()} method right after that the opening of the port succeeds.
Warning
Setting the AllDirections flag is supported on all platforms. Windows supports only this mode.
Returns equal baud rate in any direction on Windows.

The default value is Baud9600, i.e. 9600 bits per second.

Definition at line 530 of file qserialport.cpp.

References AllDirections, and Input.

Referenced by setBaudRate().

◆ baudRateChanged

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

◆ bindableDataBits()

QBindable< QSerialPort::DataBits > QSerialPort::bindableDataBits ( )

Definition at line 583 of file qserialport.cpp.

◆ bindableError()

QBindable< QSerialPort::SerialPortError > QSerialPort::bindableError ( ) const

Definition at line 962 of file qserialport.cpp.

◆ bindableFlowControl()

QBindable< QSerialPort::FlowControl > QSerialPort::bindableFlowControl ( )

Definition at line 733 of file qserialport.cpp.

◆ bindableIsBreakEnabled()

QBindable< bool > QSerialPort::bindableIsBreakEnabled ( )

Definition at line 1159 of file qserialport.cpp.

◆ bindableParity()

QBindable< QSerialPort::Parity > QSerialPort::bindableParity ( )

Definition at line 633 of file qserialport.cpp.

◆ bindableStopBits()

QBindable< QSerialPort::StopBits > QSerialPort::bindableStopBits ( )

Definition at line 683 of file qserialport.cpp.

◆ breakEnabledChanged

void QSerialPort::breakEnabledChanged ( bool  set)
signal

Referenced by setBreakEnabled().

◆ bytesAvailable()

qint64 QSerialPort::bytesAvailable ( ) const
override

\reimp

Returns the number of incoming bytes that are waiting to be read.

See also
bytesToWrite(), read()

Definition at line 1034 of file qserialport.cpp.

Referenced by GPSProvider::callback().

◆ bytesToWrite()

qint64 QSerialPort::bytesToWrite ( ) const
override

\reimp

Returns the number of bytes that are waiting to be written. The bytes are written when control goes back to the event loop or when flush() is called.

See also
bytesAvailable(), flush()

Definition at line 1048 of file qserialport.cpp.

◆ canReadLine()

bool QSerialPort::canReadLine ( ) const
override

\reimp

Returns true if a line of data can be read from the serial port; otherwise returns false.

See also
readLine()

Definition at line 1062 of file qserialport.cpp.

◆ clear()

bool QSerialPort::clear ( Directions  directions = AllDirections)

Discards all characters from the output or input buffer, depending on given directions directions. This includes clearing the internal class buffers and the UART (driver) buffers. Also terminate pending read or write operations. If successful, returns true; otherwise returns false.

Note
The serial port has to be open before trying to clear any buffered data; otherwise returns false and sets the NotOpenError error code.

Definition at line 918 of file qserialport.cpp.

References Input, NotOpenError, and Output.

◆ clearError()

void QSerialPort::clearError ( )

Definition at line 956 of file qserialport.cpp.

References NoError.

Referenced by open().

◆ close()

void QSerialPort::close ( )
override

\reimp

Note
The serial port has to be open before trying to close it; otherwise sets the NotOpenError error code.
See also
QIODevice::close()

Definition at line 468 of file qserialport.cpp.

References NotOpenError.

Referenced by Bootloader::close(), SerialWorker::disconnectFromPort(), and ~QSerialPort().

◆ dataBits()

QSerialPort::DataBits QSerialPort::dataBits ( ) const

the data bits in a frame

If the setting is successful or set before opening the port, returns true; otherwise returns false and sets an error code which can be obtained by accessing the value of the QSerialPort::error property.

Note
If the setting is set before opening the port, the actual serial port setting is done automatically in the \l{QSerialPort::open()} method right after that the opening of the port succeeds.

The default value is Data8, i.e. 8 data bits.

Definition at line 577 of file qserialport.cpp.

Referenced by setDataBits().

◆ dataBitsChanged

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

This signal is emitted after the data bits in a frame has been changed. The new data bits in a frame is passed as dataBits.

See also
QSerialPort::dataBits

Referenced by setDataBits().

◆ dataTerminalReadyChanged

void QSerialPort::dataTerminalReadyChanged ( bool  set)
signal

This signal is emitted after the state (high or low) of the line signal DTR has been changed. The new the state (high or low) of the line signal DTR is passed as set.

See also
QSerialPort::dataTerminalReady

Referenced by setDataTerminalReady().

◆ error()

QSerialPort::SerialPortError QSerialPort::error ( ) const

the error status of the serial port

The I/O device status returns an error code. For example, if open() returns false, or a read/write operation returns -1, this property can be used to figure out the reason why the operation failed.

The error code is set to the default QSerialPort::NoError after a call to clearError()

Definition at line 950 of file qserialport.cpp.

Referenced by SerialWorker::connectToPort().

◆ errorOccurred

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

This signal is emitted when an error occurs in the serial port. The specified error describes the type of error that occurred.

See also
QSerialPort::error

Referenced by SerialWorker::setupPort().

◆ flowControl()

QSerialPort::FlowControl QSerialPort::flowControl ( ) const

the desired flow control mode

If the setting is successful or set before opening the port, returns true; otherwise returns false and sets an error code which can be obtained by accessing the value of the QSerialPort::error property.

Note
If the setting is set before opening the port, the actual serial port setting is done automatically in the \l{QSerialPort::open()} method right after that the opening of the port succeeds.

The default value is NoFlowControl, i.e. no flow control.

Definition at line 727 of file qserialport.cpp.

Referenced by setFlowControl().

◆ flowControlChanged

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

This signal is emitted after the flow control mode has been changed. The new flow control mode is passed as flow.

See also
QSerialPort::flowControl

Referenced by setFlowControl().

◆ flush()

bool QSerialPort::flush ( )

This function writes as much as possible from the internal write buffer to the underlying serial port without blocking. If any data was written, this function returns true; otherwise returns false.

Call this function for sending the buffered data immediately to the serial port. The number of bytes successfully written depends on the operating system. In most cases, this function does not need to be called, because the QSerialPort class will start sending data automatically once control is returned to the event loop. In the absence of an event loop, call waitForBytesWritten() instead.

Note
The serial port has to be open before trying to flush any buffered data; otherwise returns false and sets the NotOpenError error code.
See also
write(), waitForBytesWritten()

Definition at line 896 of file qserialport.cpp.

References NotOpenError.

Referenced by Bootloader::reboot().

◆ handle()

QSerialPort::Handle QSerialPort::handle ( ) const
Since
5.2

If the platform is supported and the serial port is open, returns the native serial port handle; otherwise returns -1.

Warning
This function is for expert use only; use it at your own risk. Furthermore, this function carries no compatibility promise between minor Qt releases.

Definition at line 597 of file qserialport_android.cpp.

◆ isBreakEnabled()

bool QSerialPort::isBreakEnabled ( ) const

Definition at line 1153 of file qserialport.cpp.

◆ isDataTerminalReady()

bool QSerialPort::isDataTerminalReady ( )

Definition at line 778 of file qserialport.cpp.

References DataTerminalReadySignal.

Referenced by setDataTerminalReady().

◆ isRequestToSend()

bool QSerialPort::isRequestToSend ( )

Definition at line 834 of file qserialport.cpp.

References RequestToSendSignal.

Referenced by setRequestToSend().

◆ isSequential()

bool QSerialPort::isSequential ( ) const
override

\reimp

Always returns true. The serial port is a sequential device.

Definition at line 1022 of file qserialport.cpp.

◆ open()

bool QSerialPort::open ( OpenMode  mode)
override

\reimp

Opens the serial port using OpenMode mode, and then returns true if successful; otherwise returns false and sets an error code which can be obtained by calling the error() method.

Note
The method returns false if opening the port is successful, but could not set any of the port settings successfully. In that case, the port is closed automatically not to leave the port around with incorrect settings.
Warning
The mode has to be QIODeviceBase::ReadOnly, QIODeviceBase::WriteOnly, or QIODeviceBase::ReadWrite. Other modes are unsupported.
See also
QIODeviceBase::OpenMode, setPort()

Definition at line 436 of file qserialport.cpp.

References clearError(), OpenError, and UnsupportedOperationError.

Referenced by SerialWorker::connectToPort(), and Bootloader::open().

◆ parity()

QSerialPort::Parity QSerialPort::parity ( ) const

the parity checking mode

If the setting is successful or set before opening the port, returns true; otherwise returns false and sets an error code which can be obtained by accessing the value of the QSerialPort::error property.

Note
If the setting is set before opening the port, the actual serial port setting is done automatically in the \l{QSerialPort::open()} method right after that the opening of the port succeeds.

The default value is NoParity, i.e. no parity.

Definition at line 627 of file qserialport.cpp.

Referenced by setParity().

◆ parityChanged

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

This signal is emitted after the parity checking mode has been changed. The new parity checking mode is passed as parity.

See also
QSerialPort::parity

Referenced by setParity().

◆ pinoutSignals()

QSerialPort::PinoutSignals QSerialPort::pinoutSignals ( )

Returns the state of the line signals in a bitmap format.

From this result, it is possible to allocate the state of the desired signal by applying a mask "AND", where the mask is the desired enumeration value from QSerialPort::PinoutSignals.

Note
This method performs a system call, thus ensuring that the line signal states are returned properly. This is necessary when the underlying operating systems cannot provide proper notifications about the changes.
The serial port has to be open before trying to get the pinout signals; otherwise returns NoSignal and sets the NotOpenError error code.
See also
QSerialPort::dataTerminalReady, QSerialPort::requestToSend

Definition at line 866 of file qserialport.cpp.

References NoSignal, and NotOpenError.

◆ portName()

QString QSerialPort::portName ( ) const

Returns the name set by setPort() or passed to the QSerialPort constructor. This name is short, i.e. it is extracted and converted from the internal variable system location of the device. The conversion algorithm is platform specific: \table \header

  • Platform
  • Brief Description \row
  • Windows
  • Removes the prefix "\\\\.\\" or "//./" from the system location and returns the remainder of the string. \row \li Unix, BSD \li Removes the prefix "/dev/" from the system location and returns the remainder of the string. \endtable
See also
setPort(), QSerialPortInfo::portName()

Definition at line 414 of file qserialport.cpp.

References QSerialPortInfoPrivate::portNameFromSystemLocation().

Referenced by SerialWorker::connectToPort(), and SerialWorker::disconnectFromPort().

◆ readBufferSize()

qint64 QSerialPort::readBufferSize ( ) const

Returns the size of the internal read buffer. This limits the amount of data that the client can receive before calling the read() or readAll() methods.

A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.

See also
setReadBufferSize(), read()

Definition at line 987 of file qserialport.cpp.

◆ readData()

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

\reimp

\omit This function does not really read anything, as we use QIODevicePrivate's buffer. The buffer will be read inside of QIODevice before this method will be called. \endomit

Definition at line 1173 of file qserialport.cpp.

◆ readLineData()

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

\reimp

Definition at line 1193 of file qserialport.cpp.

◆ requestToSendChanged

void QSerialPort::requestToSendChanged ( bool  set)
signal

This signal is emitted after the state (high or low) of the line signal RTS has been changed. The new the state (high or low) of the line signal RTS is passed as set.

See also
QSerialPort::requestToSend

Referenced by setRequestToSend().

◆ setBaudRate()

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

◆ setBreakEnabled()

bool QSerialPort::setBreakEnabled ( bool  set = true)

Definition at line 1132 of file qserialport.cpp.

References breakEnabledChanged(), and NotOpenError.

◆ setDataBits()

bool QSerialPort::setDataBits ( DataBits  dataBits)

Definition at line 561 of file qserialport.cpp.

References dataBits(), and dataBitsChanged().

Referenced by Bootloader::open().

◆ setDataTerminalReady()

bool QSerialPort::setDataTerminalReady ( bool  set)

Definition at line 760 of file qserialport.cpp.

References dataTerminalReadyChanged(), isDataTerminalReady(), and NotOpenError.

◆ setFlowControl()

bool QSerialPort::setFlowControl ( FlowControl  flowControl)

Definition at line 711 of file qserialport.cpp.

References flowControl(), and flowControlChanged().

Referenced by Bootloader::open().

◆ setParity()

bool QSerialPort::setParity ( Parity  parity)

Definition at line 611 of file qserialport.cpp.

References parity(), and parityChanged().

Referenced by Bootloader::open().

◆ setPort()

void QSerialPort::setPort ( const QSerialPortInfo serialPortInfo)

Sets the port stored in the serial port info instance serialPortInfo.

See also
portName(), QSerialPortInfo

Definition at line 387 of file qserialport.cpp.

References QSerialPortInfo::systemLocation().

Referenced by QSerialPort().

◆ setPortName()

void QSerialPort::setPortName ( const QString &  name)

Sets the name of the serial port.

The name of the serial port can be passed as either a short name or the long system location if necessary.

See also
portName(), QSerialPortInfo

Definition at line 376 of file qserialport.cpp.

References QSerialPortInfoPrivate::portNameToSystemLocation().

Referenced by SerialWorker::connectToPort(), Bootloader::open(), and QSerialPort().

◆ setReadBufferSize()

void QSerialPort::setReadBufferSize ( qint64  size)

Sets the size of QSerialPort's internal read buffer to be size bytes.

If the buffer size is limited to a certain size, QSerialPort will not buffer more than this size of data. The special case of a buffer size of 0 means that the read buffer is unlimited and all incoming data is buffered. This is the default.

This option is useful if the data is only read at certain points in time (for instance in a real-time streaming application) or if the serial port should be protected against receiving too much data, which may eventually cause the application to run out of memory.

See also
readBufferSize(), read()

Definition at line 1009 of file qserialport.cpp.

◆ setRequestToSend()

bool QSerialPort::setRequestToSend ( bool  set)

◆ setStopBits()

bool QSerialPort::setStopBits ( StopBits  stopBits)

Definition at line 661 of file qserialport.cpp.

References stopBits(), and stopBitsChanged().

Referenced by Bootloader::open().

◆ stopBits()

QSerialPort::StopBits QSerialPort::stopBits ( ) const

the number of stop bits in a frame

If the setting is successful or set before opening the port, returns true; otherwise returns false and sets an error code which can be obtained by accessing the value of the QSerialPort::error property.

Note
If the setting is set before opening the port, the actual serial port setting is done automatically in the \l{QSerialPort::open()} method right after that the opening of the port succeeds.

The default value is OneStop, i.e. 1 stop bit.

Definition at line 677 of file qserialport.cpp.

Referenced by setStopBits().

◆ stopBitsChanged

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

This signal is emitted after the number of stop bits in a frame has been changed. The new number of stop bits in a frame is passed as stopBits.

See also
QSerialPort::stopBits

Referenced by setStopBits().

◆ waitForBytesWritten()

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

\reimp

This function blocks until at least one byte has been written to the serial port and the \l{QIODevice::}{bytesWritten()} signal has been emitted. The function will timeout after msecs milliseconds; the default timeout is 30000 milliseconds. If msecs is -1, this function will not time out.

The function returns true if the bytesWritten() signal is emitted; otherwise it returns false (if an error occurred or the operation timed out).

Definition at line 1110 of file qserialport.cpp.

Referenced by GPSProvider::callback().

◆ waitForReadyRead()

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

\reimp

This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted. The function will timeout after msecs milliseconds; the default timeout is 30000 milliseconds. If msecs is -1, this function will not time out.

The function returns true if the readyRead() signal is emitted and there is new data available for reading; otherwise it returns false (if an error occurred or the operation timed out).

See also
waitForBytesWritten()

Definition at line 1081 of file qserialport.cpp.

Referenced by GPSProvider::callback(), Bootloader::getBoardInfo(), and Bootloader::initFlashSequence().

◆ writeData()

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

\reimp

Definition at line 1201 of file qserialport.cpp.


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