summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-10-11 16:15:50 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-10-11 16:15:50 +0200
commit262409454aff59a0595fda5e795a7c3eaa113776 (patch)
tree567e41859add1df4c4df38700973c77db96adb94
parentc02dc937f6eeb99b3fc0712dbbe02cd8fd00cb28 (diff)
parent50ab4d4a8ff5f882b9699cbde26ad9d8824a4824 (diff)
downloadqtserialport-262409454aff59a0595fda5e795a7c3eaa113776.tar.gz
Merge remote-tracking branch 'origin/stable' into dev
Change-Id: Iaef343dd542c8b4b4e62deb481559c7c1345d347
-rw-r--r--examples/serialport/cenumerator/cenumerator.pro2
-rw-r--r--examples/serialport/doc/blockingmaster.qdoc135
-rw-r--r--src/serialport/qserialport.cpp182
-rw-r--r--src/serialport/qserialport.h6
-rw-r--r--src/serialport/qserialport_p.h4
-rw-r--r--src/serialport/qserialport_unix.cpp5
-rw-r--r--src/serialport/qserialport_win.cpp9
-rw-r--r--src/serialport/qt4support/include/QtCore/qwineventnotifier.h (renamed from src/serialport/qt4support/qwineventnotifier_p.h)30
-rw-r--r--src/serialport/qt4support/include/private/qringbuffer_p.h (renamed from src/serialport/qt4support/qringbuffer_p.h)0
-rw-r--r--src/serialport/qt4support/install-helper.pri1
10 files changed, 268 insertions, 106 deletions
diff --git a/examples/serialport/cenumerator/cenumerator.pro b/examples/serialport/cenumerator/cenumerator.pro
index 464e1d9..7f87034 100644
--- a/examples/serialport/cenumerator/cenumerator.pro
+++ b/examples/serialport/cenumerator/cenumerator.pro
@@ -1,3 +1,5 @@
+QT = core
+
greaterThan(QT_MAJOR_VERSION, 4) {
QT += serialport
} else {
diff --git a/examples/serialport/doc/blockingmaster.qdoc b/examples/serialport/doc/blockingmaster.qdoc
index 1ce649a..32176a1 100644
--- a/examples/serialport/doc/blockingmaster.qdoc
+++ b/examples/serialport/doc/blockingmaster.qdoc
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2011 - 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 - 2013 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
@@ -29,40 +30,40 @@
\example blockingmaster
\title Blocking Master Example
\ingroup qtserialport-examples
- \brief Explains how to create an app using QSerialPort's synchronous API.
+ \brief Explains how to use the synchronous API of QSerialPort.
The blocking master example shows how to create an application for a
- serial interface using QSerialPort's synchronous API in a worker thread.
+ serial interface using the synchronous API of QSerialPort in a worker
+ thread.
\image blockingmaster-example.png Screenshot of the blocking master example
- QSerialPort supports two general programming approaches:
+ QSerialPort supports two programming alternatives:
\list
- \li \e{The asynchronous (non-blocking) approach.} Operations are scheduled
- and performed when the control returns to Qt's event loop. QSerialPort emits
- a signal when the operation is finished. For example, QSerialPort::write()
- returns immediately. When the data is sent to the serial port, QSerialPort
- emits \l{QIODevice::bytesWritten()}{bytesWritten()}.
+ \li \e{The asynchronous (non-blocking) alternative.} Operations are scheduled
+ and performed when the control returns to the Qt event loop. The QSerialPort
+ class emits a signal when the operation is finished. For example, the
+ \l{QIODevice::write()}{write()} method returns immediately. When the data is
+ sent to the serial port, the QSerialPort class emits the
+ \l{QIODevice::bytesWritten()}{bytesWritten()} signal.
- \li \e{The synchronous (blocking) approach.} In headless and multithreaded
- applications, the wait functions can be called (in this case,
- QSerialPort::waitForReadyRead()) to suspend the calling thread until the
- operation has completed.
+ \li \e{The synchronous (blocking) alternative.} In headless and multithreaded
+ applications, the wait method can be called (in this case,
+ \l{QSerialPort::waitForReadyRead()}{waitForReadyRead()}) to suspend the
+ calling thread until the operation has completed.
\endlist
- In this example, the synchronous approach is demonstrated. The \l{terminal}{Terminal}
- example illustrates the asynchronous approach.
+ In this example, the synchronous alternative is demonstrated. The
+ \l{terminal}{Terminal} example illustrates the asynchronous alternative.
- The purpose of this example is to demonstrate a pattern that you can use
- to simplify your serial programming code, without losing responsiveness
- in your user interface. Use of Qt's blocking serial programming API often
- leads to simpler code, but because of its blocking behavior, it should only
- be used in non-GUI threads to prevent the user interface from freezing.
- But contrary to what many think, using threads with QThread does not
- necessarily add unmanagable complexity to your application.
+ The purpose of this example is to demonstrate how to simplify your serial
+ programming code without losing the responsiveness of the user interface.
+ The blocking serial programming API often leads to simpler code, but it
+ should only be used in non-GUI threads to keep the user interface
+ responsive.
This application is the master which demonstrates the work paired with the slave
application \l{blockingslave}{Blocking Slave Example}.
@@ -70,55 +71,53 @@
The master application initiates the transfer request via the serial port to
the slave application and waits for response.
- We will start with the MasterThread class, which handles the serial
- programming code.
-
\snippet blockingmaster/masterthread.h 0
- MasterThread is a QThread subclass that provides an API for scheduling
- requests to the slave, and it has signals for delivering responses and reporting
- errors. The transaction() method can be called to startup the new master
- transaction with the desired request data and other parameters. The result
- is delivered by the response() signal. If any error occurs, the error() or
- timeout() signal is emitted.
+ MasterThread is a QThread subclass that provides API for scheduling
+ requests to the slave. This class provides signals for responding and
+ reporting errors. The transaction() method can be called to start up the
+ new master transaction with the desired request. The result is provided by
+ the response() signal. In case of any issues, the error() or timeout()
+ signal is emitted.
- It's important to notice that the transaction() method is called from the main,
- GUI thread, but the request data and other parameters will be accessed from
- MasterThread's thread. Since the MasterThread data members will be read and
- written concurrently from different threads, QMutex is used to synchronize
- the access.
+ Note, the transaction() method is called in the main thread, but the
+ request is provided in the MasterThread thread. The MasterThread
+ data members are read and written concurrently in different threads, thus
+ the QMutex class is used to synchronize the access.
\snippet blockingmaster/masterthread.cpp 2
- The transaction() function stores the serial port name, timeout and request
- data. The mutex can be locked with QMutexLocker to protect this data. Then,
- the thread can be started, unless it is already running. QWaitCondition::wakeOne()
- will be discussed later.
+ The transaction() method stores the serial port name, timeout and request
+ data. The mutex can be locked with QMutexLocker to protect this data. The
+ thread can be started then, unless it is already running. The
+ \l{QWaitCondition::wakeOne()}{wakeOne()} method is discussed later.
\snippet blockingmaster/masterthread.cpp 4
\snippet blockingmaster/masterthread.cpp 5
- In the run() function, start by acquiring the mutex lock, fetch the
- serial port name, timeout and request data from the member data, and then
- release the lock again.
+ In the run() function, the first is to lock the QMutex object, then fetch the
+ serial port name, timeout and request data by using the member data. Having
+ that done, the QMutex lock is released.
- Under no circumstance should the method \c transaction() be called simultaneously
- with a process fetching these data. QString is reentrant but not thread-safe, and
- it is not recommended to read the serial port name from one request,
- and timeout or request data from another. The MasterThread can only handle
- one request at a time.
+ Under no circumstance should the \c transaction() method be called
+ simultaneously with a process fetching the data. Note, while the QString
+ class is reentrant, it is not thread-safe. Thereby, it is not recommended to
+ read the serial port name in a request thread, and timeout or request data
+ in another thread. The MasterThread class can only handle one request at a
+ time.
- The QSerialPort object we construct on stack into run() function before loop
- enter:
+ The QSerialPort object is constructed on stack in the run() method before
+ entering the loop:
\snippet blockingmaster/masterthread.cpp 6
- This allows us once to create an object, while running the loop, and also means
- that all the methods of the object will be executed in the context of the
- run() thread.
+ This makes it possible to create an object while running the loop. It also
+ means that all the object methods are executed in the scope of the run()
+ method.
- In the loop, check whether the name of the serial port for the current trans-
- action has changed or not. If it has, reopen and reconfigure the serial port.
+ It is checked inside the loop whether or not the serial port name of the
+ current transaction has changed. If this has changed, the serial port is
+ reopened and then reconfigured.
\snippet blockingmaster/masterthread.cpp 7
@@ -127,23 +126,27 @@
\snippet blockingmaster/masterthread.cpp 8
- \warning The method waitForBytesWritten() should be used after each write()
- call for the blocking approach, because it processes all the I/O routines
- instead of the Qt event loop.
+ \warning As for the blocking transfer, the
+ \l{QSerialPort::waitForBytesWritten()}{waitForBytesWritten()} method should be
+ used after each \l{QIODevice::write()}{write} method call. This will process all
+ the I/O routines instead of the Qt event loop.
- The timeout() signal is emitted if an error occurs when transferring data.
+ The timeout() signal is emitted if a timeout error occurs when transferring
+ data.
\snippet blockingmaster/masterthread.cpp 9
- After a successful request, wait for a response, and then try to read it.
+ There is a waiting period for response after a successful request, and then
+ it is read again.
\snippet blockingmaster/masterthread.cpp 10
- \warning The method waitForReadyRead() should be used before each read()
- call for the blocking approach, because it processes all the I/O routines
- instead of Qt event loop.
+ \warning As for the blocking alternative, the
+ \l{QSerialPort::waitForReadyRead()}{waitForReadyRead()} method should be
+ used before each read() call. This will processes all the I/O routines
+ instead of the Qt event loop.
- The timeout() signal is emitted if an error occurs when receiving data.
+ The timeout() signal is emitted if a timeout error occurs when receiving data.
\snippet blockingmaster/masterthread.cpp 11
@@ -152,9 +155,9 @@
\snippet blockingmaster/masterthread.cpp 12
- Next, the thread goes to sleep until the next transaction has appeared. On
- waking, the thread re-reads the new data from the members and runs the
- loop from the beginning.
+ Afterwards, the thread goes to sleep until the next transaction appears.
+ The thread reads the new data after waking up by using the members and
+ runs the loop from the beginning.
\snippet blockingmaster/masterthread.cpp 13
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index 531dc39..04f2f9f 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -59,6 +59,8 @@
# define SERIALPORT_BUFFERSIZE 16384
#endif
+#include <QtCore/qdebug.h>
+
QT_BEGIN_NAMESPACE
QSerialPortPrivateData::QSerialPortPrivateData(QSerialPort *q)
@@ -184,8 +186,9 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed)
\enum QSerialPort::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.
+ with.
+
+ \note Only the most common standard baud rates are listed in this enum.
\value Baud1200 1200 baud.
\value Baud2400 2400 baud.
@@ -271,6 +274,7 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed)
\value ClearToSendSignal CTS (Clear To Send).
\value SecondaryTransmittedDataSignal STD (Secondary Transmitted Data).
\value SecondaryReceivedDataSignal SRD (Secondary Received Data).
+ \value UnknownSignal Unknown line state. This value was introduced in QtSerialPort 5.2.
\sa pinoutSignals(), QSerialPort::dataTerminalReady,
QSerialPort::requestToSend
@@ -305,6 +309,10 @@ int QSerialPortPrivateData::timeoutValue(int msecs, int elapsed)
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 ParityError Parity error detected by the hardware while reading data.
\value FramingError Framing error detected by the hardware while reading data.
\value BreakConditionError Break condition detected by the hardware on
@@ -436,9 +444,13 @@ QString QSerialPort::portName() const
\reimp
Opens the serial port using OpenMode \a mode, and then returns true if
- successful; otherwise returns false with and sets an error code which can be
+ successful; otherwise returns false and sets an error code which can be
obtained by calling the error() method.
+ \note This method has to be called before setting certain serial port
+ parameters. See each property documentation for details when it is
+ necessary.
+
\warning The \a mode has to be QIODevice::ReadOnly, QIODevice::WriteOnly,
or QIODevice::ReadWrite. Other modes are unsupported.
@@ -475,12 +487,17 @@ bool QSerialPort::open(OpenMode mode)
/*!
\reimp
+ \note The serial port has to be open before trying to close it; otherwise
+ sets the NotOpenError error code.
+
\sa QIODevice::close()
*/
void QSerialPort::close()
{
Q_D(QSerialPort);
if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
return;
}
@@ -533,6 +550,13 @@ bool QSerialPort::settingsRestoredOnClose() const
QSerialPort::error property. To set the baud rate, use the enumeration
QSerialPort::BaudRate or any positive qint32 value.
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
+
\warning Only the AllDirections flag is support for setting this property on
Windows, Windows CE, and Symbian.
@@ -543,6 +567,12 @@ bool QSerialPort::setBaudRate(qint32 baudRate, Directions directions)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (d->setBaudRate(baudRate, directions)) {
if (directions & QSerialPort::Input) {
if (d->inputBaudRate != baudRate)
@@ -592,11 +622,24 @@ qint32 QSerialPort::baudRate(Directions directions) const
If the setting is successful, returns true; otherwise returns false and sets
an error code which can be obtained by accessing the value of the
QSerialPort::error property.
+
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
*/
bool QSerialPort::setDataBits(DataBits dataBits)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (d->setDataBits(dataBits)) {
if (d->dataBits != dataBits) {
d->dataBits = dataBits;
@@ -631,11 +674,24 @@ QSerialPort::DataBits QSerialPort::dataBits() const
If the setting is successful, returns true; otherwise returns false and sets
an error code which can be obtained by accessing the value of the
QSerialPort::error property.
+
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
*/
bool QSerialPort::setParity(Parity parity)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (d->setParity(parity)) {
if (d->parity != parity) {
d->parity = parity;
@@ -669,11 +725,24 @@ QSerialPort::Parity QSerialPort::parity() const
If the setting is successful, returns true; otherwise returns false and
sets an error code which can be obtained by accessing the value of the
QSerialPort::error property.
+
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
*/
bool QSerialPort::setStopBits(StopBits stopBits)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (d->setStopBits(stopBits)) {
if (d->stopBits != stopBits) {
d->stopBits = stopBits;
@@ -707,11 +776,24 @@ QSerialPort::StopBits QSerialPort::stopBits() const
If the setting is successful, returns true; otherwise returns false and sets
an error code which can be obtained by accessing the value of the
QSerialPort::error property.
+
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
*/
bool QSerialPort::setFlowControl(FlowControl flow)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (d->setFlowControl(flow)) {
if (d->flow != flow) {
d->flow = flow;
@@ -745,12 +827,25 @@ QSerialPort::FlowControl QSerialPort::flowControl() const
If the setting is successful, returns true; otherwise returns false.
If the flag is true then the DTR signal is set to high; otherwise low.
+ \note The serial port has to be open before trying to set or get this
+ property; otherwise returns false and sets the NotOpenError error code. This
+ is a bit unusual as opposed to the regular Qt property settings of a class.
+ However, this is a special use case since the property is set through the
+ interaction with the kernel and hardware. Hence, the two scenarios cannot be
+ completely compared to each other.
+
\sa pinoutSignals()
*/
bool QSerialPort::setDataTerminalReady(bool set)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
bool retval = d->setDataTerminalReady(set);
if (retval && (d->dataTerminalReady != set)) {
d->dataTerminalReady = set;
@@ -783,12 +878,25 @@ bool QSerialPort::isDataTerminalReady()
If the setting is successful, returns true; otherwise returns false.
If the flag is true then the RTS signal is set to high; otherwise low.
+ \note The serial port has to be open before trying to set or get this
+ property; otherwise returns false and sets the NotOpenError error code. This
+ is a bit unusual as opposed to the regular Qt property settings of a class.
+ However, this is a special use case since the property is set through the
+ interaction with the kernel and hardware. Hence, the two scenarios cannot be
+ completely compared to each other.
+
\sa pinoutSignals()
*/
bool QSerialPort::setRequestToSend(bool set)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
bool retval = d->setRequestToSend(set);
if (retval && (d->requestToSend != set)) {
d->requestToSend = set;
@@ -821,16 +929,27 @@ bool QSerialPort::isRequestToSend()
desired signal by applying a mask "AND", where the mask is
the desired enumeration value from QSerialPort::PinoutSignals.
- Note that, this method performs a system call, thus ensuring that the line
- signal states are returned properly. This is necessary when the underlying
+ \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.
+ \note The serial port has to be open before trying to get the pinout
+ signals; otherwise returns UnknownSignal and sets the NotOpenError error
+ code.
+
\sa isDataTerminalReady(), isRequestToSend, setDataTerminalReady(),
setRequestToSend()
*/
QSerialPort::PinoutSignals QSerialPort::pinoutSignals()
{
Q_D(QSerialPort);
+
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return QSerialPort::UnknownSignal;
+ }
+
return d->pinoutSignals();
}
@@ -846,11 +965,21 @@ QSerialPort::PinoutSignals QSerialPort::pinoutSignals()
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.
+
\sa write(), waitForBytesWritten()
*/
bool QSerialPort::flush()
{
Q_D(QSerialPort);
+
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
return d->flush();
}
@@ -859,10 +988,20 @@ bool QSerialPort::flush()
given directions \a directions. Including clear an 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.
*/
bool QSerialPort::clear(Directions directions)
{
Q_D(QSerialPort);
+
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
if (directions & Input)
d->readBuffer.clear();
if (directions & Output)
@@ -905,11 +1044,24 @@ bool QSerialPort::atEnd() const
If the setting is successful, returns true; otherwise returns false. The
default policy set is IgnorePolicy.
+
+ \note The serial port has to be open before trying to set this property;
+ otherwise returns false and sets the NotOpenError error code. This is a bit
+ unusual as opposed to the regular Qt property settings of a class. However,
+ this is a special use case since the property is set through the interaction
+ with the kernel and hardware. Hence, the two scenarios cannot be completely
+ compared to each other.
*/
bool QSerialPort::setDataErrorPolicy(DataErrorPolicy policy)
{
Q_D(QSerialPort);
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
const bool ret = d->policy == policy || d->setDataErrorPolicy(policy);
if (ret && (d->policy != policy)) {
d->policy = policy;
@@ -1112,11 +1264,21 @@ bool QSerialPort::waitForBytesWritten(int msecs)
If the duration is non zero then zero bits are transmitted within a certain
period of time depending on the implementation.
+ \note The serial port has to be open before trying to send a break
+ duration; otherwise returns false and sets the NotOpenError error code.
+
\sa setBreakEnabled()
*/
bool QSerialPort::sendBreak(int duration)
{
Q_D(QSerialPort);
+
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
return d->sendBreak(duration);
}
@@ -1126,11 +1288,21 @@ bool QSerialPort::sendBreak(int duration)
If \a set is true then enables the break transmission; otherwise disables.
+ \note The serial port has to be open before trying to set break enabled;
+ otherwise returns false and sets the NotOpenError error code.
+
\sa sendBreak()
*/
bool QSerialPort::setBreakEnabled(bool set)
{
Q_D(QSerialPort);
+
+ if (!isOpen()) {
+ setError(QSerialPort::NotOpenError);
+ qWarning("%s: device not open", Q_FUNC_INFO);
+ return false;
+ }
+
return d->setBreakEnabled(set);
}
diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h
index 781a98b..e173445 100644
--- a/src/serialport/qserialport.h
+++ b/src/serialport/qserialport.h
@@ -140,7 +140,8 @@ public:
RequestToSendSignal = 0x40,
ClearToSendSignal = 0x80,
SecondaryTransmittedDataSignal = 0x100,
- SecondaryReceivedDataSignal = 0x200
+ SecondaryReceivedDataSignal = 0x200,
+ UnknownSignal = -1
};
Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)
@@ -165,7 +166,8 @@ public:
ResourceError,
UnsupportedOperationError,
UnknownError,
- TimeoutError
+ TimeoutError,
+ NotOpenError
};
explicit QSerialPort(QObject *parent = 0);
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index cb6a748..4140493 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -46,11 +46,7 @@
#include "qserialport.h"
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <private/qringbuffer_p.h>
-#else
-#include "qt4support/qringbuffer_p.h"
-#endif
QT_BEGIN_NAMESPACE
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index f72322f..ad91e1b 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -257,13 +257,14 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
Q_Q(QSerialPort);
int arg = 0;
- QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
if (::ioctl(descriptor, TIOCMGET, &arg) == -1) {
q->setError(decodeSystemError());
- return ret;
+ return QSerialPort::UnknownSignal;
}
+ QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
+
#ifdef TIOCM_LE
if (arg & TIOCM_LE)
ret |= QSerialPort::DataSetReadySignal;
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 3d9e98a..91630fd 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -50,11 +50,7 @@
#include <QtCore/qvector.h>
#endif
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtCore/qwineventnotifier.h>
-#else
-#include "qt4support/qwineventnotifier_p.h"
-#endif
#ifndef CTL_CODE
# define CTL_CODE(DeviceType, Function, Method, Access) ( \
@@ -320,13 +316,14 @@ QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
Q_Q(QSerialPort);
DWORD modemStat = 0;
- QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
if (!::GetCommModemStatus(descriptor, &modemStat)) {
q->setError(decodeSystemError());
- return ret;
+ return QSerialPort::UnknownSignal;
}
+ QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
+
if (modemStat & MS_CTS_ON)
ret |= QSerialPort::ClearToSendSignal;
if (modemStat & MS_DSR_ON)
diff --git a/src/serialport/qt4support/qwineventnotifier_p.h b/src/serialport/qt4support/include/QtCore/qwineventnotifier.h
index bd1203e..ed31e83 100644
--- a/src/serialport/qt4support/qwineventnotifier_p.h
+++ b/src/serialport/qt4support/include/QtCore/qwineventnotifier.h
@@ -39,29 +39,21 @@
**
****************************************************************************/
-#ifndef QWINEVENTNOTIFIER_P_H
-#define QWINEVENTNOTIFIER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
+#ifndef QWINEVENTNOTIFIER_H
+#define QWINEVENTNOTIFIER_H
#include "QtCore/qobject.h"
+
+#ifdef Q_OS_WIN
#include "QtCore/qt_windows.h"
QT_BEGIN_NAMESPACE
+class QWinEventNotifierPrivate;
class Q_CORE_EXPORT QWinEventNotifier : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QObject)
+ Q_DECLARE_PRIVATE(QWinEventNotifier)
public:
explicit QWinEventNotifier(QObject *parent = 0);
@@ -81,14 +73,10 @@ Q_SIGNALS:
protected:
bool event(QEvent * e);
-
-private:
- Q_DISABLE_COPY(QWinEventNotifier)
-
- HANDLE handleToEvent;
- bool enabled;
};
QT_END_NAMESPACE
-#endif // QWINEVENTNOTIFIER_P_H
+#endif // Q_OS_WIN
+
+#endif // QWINEVENTNOTIFIER_H
diff --git a/src/serialport/qt4support/qringbuffer_p.h b/src/serialport/qt4support/include/private/qringbuffer_p.h
index ddd10e5..ddd10e5 100644
--- a/src/serialport/qt4support/qringbuffer_p.h
+++ b/src/serialport/qt4support/include/private/qringbuffer_p.h
diff --git a/src/serialport/qt4support/install-helper.pri b/src/serialport/qt4support/install-helper.pri
index 9ec2e6b..6037caf 100644
--- a/src/serialport/qt4support/install-helper.pri
+++ b/src/serialport/qt4support/install-helper.pri
@@ -36,4 +36,5 @@ target.path = $$[QT_INSTALL_LIBS]
INSTALLS += target
INCLUDEPATH += $$QTSERIALPORT_BUILD_ROOT/include $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
+lessThan(QT_MAJOR_VERSION, 5): INCLUDEPATH += $$QTSERIALPORT_PROJECT_ROOT/src/serialport/qt4support/include
DEFINES += QT_BUILD_SERIALPORT_LIB