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)) {
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
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