9#include <QtCore/qdebug.h>
18 : errorCode(newErrorCode),
errorString(newErrorString)
26 errorString = QSerialPort::tr(
"Device is already open");
29 errorString = QSerialPort::tr(
"Device is not open");
32 errorString = QSerialPort::tr(
"Operation timed out");
35 errorString = QSerialPort::tr(
"Error reading from device");
38 errorString = QSerialPort::tr(
"Error writing to device");
41 errorString = QSerialPort::tr(
"Device disappeared from the system");
64 emit q->errorOccurred(
error);
446 static const OpenMode unsupportedModes = Append | Truncate | Text | Unbuffered;
447 if ((mode & unsupportedModes) || mode == NotOpen) {
456 QIODevice::open(mode);
477 d->isBreakEnabled.setValue(
false);
506 if (!isOpen() || d->setBaudRate(
baudRate, directions)) {
522 emit baudRateChanged(
baudRate, directions);
534 return d->inputBaudRate == d->outputBaudRate ? d->inputBaudRate : -1;
564 d->dataBits.removeBindingUnlessInWrapper();
565 const auto currentDataBits = d->dataBits.valueBypassingBindings();
566 if (!isOpen() || d->setDataBits(
dataBits)) {
567 d->dataBits.setValueBypassingBindings(
dataBits);
569 d->dataBits.notify();
585 return &d_func()->dataBits;
614 d->parity.removeBindingUnlessInWrapper();
615 const auto currentParity = d->parity.valueBypassingBindings();
616 if (!isOpen() || d->setParity(
parity)) {
617 d->parity.setValueBypassingBindings(
parity);
618 if (currentParity !=
parity) {
635 return &d_func()->parity;
664 d->stopBits.removeBindingUnlessInWrapper();
665 const auto currentStopBits = d->stopBits.valueBypassingBindings();
666 if (!isOpen() || d->setStopBits(
stopBits)) {
667 d->stopBits.setValueBypassingBindings(
stopBits);
669 d->stopBits.notify();
685 return &d_func()->stopBits;
714 d->flowControl.removeBindingUnlessInWrapper();
715 const auto currentFlowControl = d->flowControl.valueBypassingBindings();
717 d->flowControl.setValueBypassingBindings(
flowControl);
719 d->flowControl.notify();
730 return d->flowControl;
735 return &d_func()->flowControl;
766 qWarning(
"%s: device not open", Q_FUNC_INFO);
771 const bool retval = d->setDataTerminalReady(set);
772 if (retval && (dataTerminalReady != set))
817 qWarning(
"%s: device not open", Q_FUNC_INFO);
827 const bool retval = d->setRequestToSend(set);
828 if (retval && (requestToSend != set))
872 qWarning(
"%s: device not open", Q_FUNC_INFO);
876 return d->pinoutSignals();
902 qWarning(
"%s: device not open", Q_FUNC_INFO);
924 qWarning(
"%s: device not open", Q_FUNC_INFO);
928 if (directions &
Input) {
929 QMutexLocker locker(&d->_readMutex);
931 d->_pendingData.clear();
932 d->_bufferBytesEstimate.store(0, std::memory_order_relaxed);
935 d->writeBuffer.clear();
936 return d->clear(directions);
964 return &d_func()->error;
990 return d->readBufferMaxSize;
1012 d->readBufferMaxSize = size;
1014 d->startAsyncRead();
1036 return QIODevice::bytesAvailable();
1050 qint64 pendingBytes = QIODevice::bytesToWrite();
1051 return pendingBytes;
1064 return QIODevice::canReadLine();
1084 return d->waitForReadyRead(msecs);
1113 return d->waitForBytesWritten(msecs);
1135 d->isBreakEnabled.removeBindingUnlessInWrapper();
1136 const auto currentSet = d->isBreakEnabled.valueBypassingBindings();
1138 if (d->setBreakEnabled(set)) {
1139 d->isBreakEnabled.setValueBypassingBindings(set);
1140 if (currentSet != set) {
1141 d->isBreakEnabled.notify();
1148 qWarning(
"%s: device not open", Q_FUNC_INFO);
1156 return d->isBreakEnabled;
1161 return &d_func()->isBreakEnabled;
1180 d_func()->_bufferBytesEstimate.store(d_func()->buffer.size(), std::memory_order_relaxed);
1184 d_func()->startAsyncRead();
1195 return QIODevice::readLineData(data, maxSize);
1204 return d->writeData(data, maxSize);
1209#include "moc_qserialport.cpp"
QSerialPort::SerialPortError errorCode
QSerialPortErrorInfo(QSerialPort::SerialPortError newErrorCode=QSerialPort::UnknownError, const QString &newErrorString=QString())
static QString portNameFromSystemLocation(const QString &source)
static QString portNameToSystemLocation(const QString &source)
Provides information about existing serial ports.
QString systemLocation() const
void setError(const QSerialPortErrorInfo &errorInfo)
Provides functions to access serial ports.
qint64 readData(char *data, qint64 maxSize) override
qint64 readLineData(char *data, qint64 maxSize) override
qint32 baudRate(Directions directions=AllDirections) const
the data baud rate for the desired direction
bool setDataTerminalReady(bool set)
QBindable< Parity > bindableParity()
void requestToSendChanged(bool set)
qint64 readBufferSize() const
void dataTerminalReadyChanged(bool set)
bool isSequential() const override
bool open(OpenMode mode) override
bool setStopBits(StopBits stopBits)
void setPortName(const QString &name)
void parityChanged(QSerialPort::Parity parity)
qint64 writeData(const char *data, qint64 maxSize) override
QBindable< StopBits > bindableStopBits()
bool waitForBytesWritten(int msecs=30000) override
void setPort(const QSerialPortInfo &info)
bool waitForReadyRead(int msecs=30000) override
qint64 bytesToWrite() const override
void breakEnabledChanged(bool set)
bool clear(Directions directions=AllDirections)
bool setRequestToSend(bool set)
bool canReadLine() const override
QSerialPort(QObject *parent=nullptr)
void stopBitsChanged(QSerialPort::StopBits stopBits)
void dataBitsChanged(QSerialPort::DataBits dataBits)
StopBits stopBits() const
the number of stop bits in a frame
PinoutSignals pinoutSignals()
DataBits dataBits() const
the data bits in a frame
QBindable< SerialPortError > bindableError() const
QBindable< DataBits > bindableDataBits()
SerialPortError error() const
the error status of the serial port
@ UnsupportedOperationError
@ DataTerminalReadySignal
void flowControlChanged(QSerialPort::FlowControl flowControl)
bool setBreakEnabled(bool set=true)
QBindable< bool > bindableIsBreakEnabled()
bool setBaudRate(qint32 baudRate, Directions directions=AllDirections)
Parity parity() const
the parity checking mode
QBindable< FlowControl > bindableFlowControl()
FlowControl flowControl() const
the desired flow control mode
bool isDataTerminalReady()
bool setDataBits(DataBits dataBits)
bool setParity(Parity parity)
bool isBreakEnabled() const
qint64 bytesAvailable() const override
bool setFlowControl(FlowControl flowControl)
void setReadBufferSize(qint64 size)
#define QSERIALPORT_BUFFERSIZE