19#include <QtCore/QLoggingCategory>
20#include <QtCore/QMutex>
21#include <QtCore/QWaitCondition>
22#include <QtCore/private/qiodevice_p.h>
23#include <QtCore/private/qproperty_p.h>
39#ifndef QSERIALPORT_BUFFERSIZE
40#define QSERIALPORT_BUFFERSIZE DEFAULT_WRITE_BUFFER_SIZE
43Q_DECLARE_LOGGING_CATEGORY(AndroidSerialPortLog)
53 const QString& newErrorString = QString());
65 bool open(QIODevice::OpenMode mode);
69 bool clear(QSerialPort::Directions directions);
77 bool setBaudRate(qint32 baudRate, QSerialPort::Directions directions);
96 return q_func()->setDataBits(dataBits_);
103 return q_func()->setParity(parity_);
110 return q_func()->setStopBits(stopBits_);
117 return q_func()->setFlowControl(flowControl_);
122 bool setBindableBreakEnabled(
bool isBreakEnabled_)
124 return q_func()->setBreakEnabled(isBreakEnabled_);
127 &QSerialPortPrivate::setBindableBreakEnabled,
false)
129 bool waitForReadyRead(
int msec);
134 qint64
writeData(const
char* data, qint64 maxSize);
148 qint64 _writeToPort(const
char* data, qint64 maxSize,
int timeout =
DEFAULT_WRITE_TIMEOUT,
bool async = false);
149 bool _stopAsyncRead();
150 void _scheduleReadyRead();
151 qsizetype _pendingSizeLocked() const;
152 void _compactPendingDataLocked();
153 qint64 _drainPendingDataLocked(qint64 maxBytes = -1);
158 static
int _stopBitsToAndroidStopBits(
QSerialPort::StopBits stopBits);
159 static
int _dataBitsToAndroidDataBits(
QSerialPort::DataBits dataBits);
160 static
int _parityToAndroidParity(
QSerialPort::Parity parity);
161 static
int _flowControlToAndroidFlowControl(
QSerialPort::FlowControl flowControl);
164 bool _posixOpen(QIODevice::OpenMode mode);
166 bool _posixStartAsyncRead();
167 bool _posixStopAsyncRead();
168 qint64 _posixWrite(const
char* data, qint64 maxSize,
int timeoutMs);
169 bool _posixApplyPortSettings(qint32 baudRate,
QSerialPort::DataBits dataBits,
172 bool _posixClear(
QSerialPort::Directions directions);
174 bool _posixSetDataTerminalReady(
bool set);
175 bool _posixSetRequestToSend(
bool set);
176 bool _posixSetBreakEnabled(
bool set);
177 bool _posixWaitForReadyRead(
int msecs);
178 void _posixReadActivated();
180 QSocketNotifier* _posixReadNotifier =
nullptr;
184 std::atomic<
bool> _readyReadPending{
false};
185 std::atomic<qint64> _bufferBytesEstimate{0};
187 QWaitCondition _readWaitCondition;
188 QByteArray _pendingData;
189 qsizetype _pendingDataOffset = 0;
QSerialPort::SerialPortError errorCode
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::Parity, parity, &QSerialPortPrivate::setBindableParity, QSerialPort::NoParity) bool setBindableStopBits(QSerialPort
bool waitForBytesWritten(int msec)
void setError(const QSerialPortErrorInfo &errorInfo)
bool setDataTerminalReady(bool set)
bool setStopBits(QSerialPort::StopBits stopBits)
bool setFlowControl(QSerialPort::FlowControl flowControl)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::StopBits, stopBits, &QSerialPortPrivate::setBindableStopBits, QSerialPort::OneStop) bool setBindableFlowControl(QSerialPort
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::DataBits, dataBits, &QSerialPortPrivate::setBindableDataBits, QSerialPort::Data8) bool setBindableParity(QSerialPort
QSerialPort::PinoutSignals pinoutSignals()
bool clear(QSerialPort::Directions directions)
bool setDataBits(QSerialPort::DataBits dataBits)
bool open(QIODevice::OpenMode mode)
void setBindableError(QSerialPort::SerialPortError error_)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::SerialPortError, error, &QSerialPortPrivate::setBindableError, QSerialPort::NoError) bool setBindableDataBits(QSerialPort
static QList< qint32 > standardBaudRates()
qint64 writeData(const char *data, qint64 maxSize)
bool setRequestToSend(bool set)
void exceptionArrived(const QString &ex)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, bool, isBreakEnabled, &QSerialPortPrivate::setBindableBreakEnabled, false) bool waitForReadyRead(int msec)
bool setParity(QSerialPort::Parity parity)
void newDataArrived(const char *bytes, int length)
bool setBreakEnabled(bool set)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QSerialPortPrivate, QSerialPort::FlowControl, flowControl, &QSerialPortPrivate::setBindableFlowControl, QSerialPort::NoFlowControl) bool setBindableBreakEnabled(bool isBreakEnabled_)
Provides functions to access serial ports.
DataBits
This enum describes the number of data bits used.
Parity
This enum describes the parity scheme used.
SerialPortError
This enum describes the errors that may be contained by the QSerialPort::error property.
StopBits
This enum describes the number of stop bits used.
FlowControl
This enum describes the flow control used.
constexpr qint64 DEFAULT_WRITE_BUFFER_SIZE
constexpr qint64 MAX_READ_SIZE
constexpr int MIN_READ_TIMEOUT
constexpr int DEFAULT_READ_TIMEOUT
constexpr int EMIT_THRESHOLD
constexpr int INVALID_DEVICE_ID
constexpr qint64 DEFAULT_READ_BUFFER_SIZE
constexpr int DEFAULT_WRITE_TIMEOUT