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);
478 (void) d->flushBeforeClose();
481 d->isBreakEnabled.setValue(
false);
510 if (!isOpen() || d->setBaudRate(
baudRate, directions)) {
538 return d->inputBaudRate == d->outputBaudRate ? d->inputBaudRate : -1;
568 d->dataBits.removeBindingUnlessInWrapper();
569 const auto currentDataBits = d->dataBits.valueBypassingBindings();
570 if (!isOpen() || d->setDataBits(
dataBits)) {
571 d->dataBits.setValueBypassingBindings(
dataBits);
573 d->dataBits.notify();
589 return &d_func()->dataBits;
618 d->parity.removeBindingUnlessInWrapper();
619 const auto currentParity = d->parity.valueBypassingBindings();
620 if (!isOpen() || d->setParity(
parity)) {
621 d->parity.setValueBypassingBindings(
parity);
622 if (currentParity !=
parity) {
639 return &d_func()->parity;
668 d->stopBits.removeBindingUnlessInWrapper();
669 const auto currentStopBits = d->stopBits.valueBypassingBindings();
670 if (!isOpen() || d->setStopBits(
stopBits)) {
671 d->stopBits.setValueBypassingBindings(
stopBits);
673 d->stopBits.notify();
689 return &d_func()->stopBits;
718 d->flowControl.removeBindingUnlessInWrapper();
719 const auto currentFlowControl = d->flowControl.valueBypassingBindings();
721 d->flowControl.setValueBypassingBindings(
flowControl);
723 d->flowControl.notify();
734 return d->flowControl;
739 return &d_func()->flowControl;
770 qWarning(
"%s: device not open", Q_FUNC_INFO);
775 const bool retval = d->setDataTerminalReady(set);
776 if (retval && (dataTerminalReady != set))
821 qWarning(
"%s: device not open", Q_FUNC_INFO);
831 const bool retval = d->setRequestToSend(set);
832 if (retval && (requestToSend != set))
876 qWarning(
"%s: device not open", Q_FUNC_INFO);
880 return d->pinoutSignals();
906 qWarning(
"%s: device not open", Q_FUNC_INFO);
928 qWarning(
"%s: device not open", Q_FUNC_INFO);
932 if (directions &
Input) {
933 QMutexLocker locker(&d->_readMutex);
935 d->_pendingData.clear();
936 d->_bufferBytesEstimate.store(0, std::memory_order_relaxed);
939 d->writeBuffer.clear();
940 return d->clear(directions);
968 return &d_func()->error;
994 return d->readBufferMaxSize;
1016 d->readBufferMaxSize = size;
1018 d->startAsyncRead();
1040 return QIODevice::bytesAvailable();
1054 qint64 pendingBytes = QIODevice::bytesToWrite();
1055 return pendingBytes;
1068 return QIODevice::canReadLine();
1088 return d->waitForReadyRead(msecs);
1117 return d->waitForBytesWritten(msecs);
1139 d->isBreakEnabled.removeBindingUnlessInWrapper();
1140 const auto currentSet = d->isBreakEnabled.valueBypassingBindings();
1142 if (d->setBreakEnabled(set)) {
1143 d->isBreakEnabled.setValueBypassingBindings(set);
1144 if (currentSet != set) {
1145 d->isBreakEnabled.notify();
1152 qWarning(
"%s: device not open", Q_FUNC_INFO);
1160 return d->isBreakEnabled;
1165 return &d_func()->isBreakEnabled;
1184 d_func()->_bufferBytesEstimate.store(d_func()->buffer.size(), std::memory_order_relaxed);
1188 d_func()->startAsyncRead();
1199 return QIODevice::readLineData(data, maxSize);
1208 return d->writeData(data, maxSize);
1213#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
Returns the system location of the serial port.
void setError(const QSerialPortErrorInfo &errorInfo)
Provides functions to access serial ports.
qint64 readData(char *data, qint64 maxSize) override
\reimp
qint64 readLineData(char *data, qint64 maxSize) override
\reimp
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)
This signal is emitted after the state (high or low) of the line signal RTS has been changed.
qint64 readBufferSize() const
Returns the size of the internal read buffer.
void dataTerminalReadyChanged(bool set)
This signal is emitted after the state (high or low) of the line signal DTR has been changed.
bool isSequential() const override
\reimp
bool open(OpenMode mode) override
\reimp
void close() override
\reimp
bool setStopBits(StopBits stopBits)
void setPortName(const QString &name)
Sets the name of the serial port.
void baudRateChanged(qint32 baudRate, QSerialPort::Directions directions)
This signal is emitted after the baud rate has been changed.
void parityChanged(QSerialPort::Parity parity)
This signal is emitted after the parity checking mode has been changed.
qint64 writeData(const char *data, qint64 maxSize) override
\reimp
QBindable< StopBits > bindableStopBits()
bool waitForBytesWritten(int msecs=30000) override
\reimp
void setPort(const QSerialPortInfo &info)
Sets the port stored in the serial port info instance serialPortInfo.
bool waitForReadyRead(int msecs=30000) override
\reimp
DataBits
This enum describes the number of data bits used.
qint64 bytesToWrite() const override
\reimp
void breakEnabledChanged(bool set)
bool clear(Directions directions=AllDirections)
Discards all characters from the output or input buffer, depending on given directions directions.
bool setRequestToSend(bool set)
bool canReadLine() const override
\reimp
QSerialPort(QObject *parent=nullptr)
Constructs a new serial port object with the given parent.
void stopBitsChanged(QSerialPort::StopBits stopBits)
This signal is emitted after the number of stop bits in a frame has been changed.
void dataBitsChanged(QSerialPort::DataBits dataBits)
This signal is emitted after the data bits in a frame has been changed.
bool flush()
This function writes as much as possible from the internal write buffer to the underlying serial port...
Parity
This enum describes the parity scheme used.
StopBits stopBits() const
the number of stop bits in a frame
PinoutSignals pinoutSignals()
Returns the state of the line signals in a bitmap format.
DataBits dataBits() const
the data bits in a frame
QBindable< SerialPortError > bindableError() const
virtual ~QSerialPort()
Closes the serial port, if necessary, and then destroys object.
QBindable< DataBits > bindableDataBits()
SerialPortError error() const
the error status of the serial port
SerialPortError
This enum describes the errors that may be contained by the QSerialPort::error property.
@ UnsupportedOperationError
@ DataTerminalReadySignal
QString portName() const
Returns the name set by setPort() or passed to the QSerialPort constructor.
void flowControlChanged(QSerialPort::FlowControl flowControl)
This signal is emitted after the flow control mode has been changed.
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()
StopBits
This enum describes the number of stop bits used.
FlowControl flowControl() const
the desired flow control mode
bool isDataTerminalReady()
bool setDataBits(DataBits dataBits)
FlowControl
This enum describes the flow control used.
bool setParity(Parity parity)
bool isBreakEnabled() const
qint64 bytesAvailable() const override
\reimp
bool setFlowControl(FlowControl flowControl)
void setReadBufferSize(qint64 size)
Sets the size of QSerialPort's internal read buffer to be size bytes.
#define QSERIALPORT_BUFFERSIZE