summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-05-05 17:43:54 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-20 20:26:03 +0200
commitd27ce6689855550ff89c5f84d38bded3c3da1dca (patch)
treec2d39ee4dc2fe05a3e7313d92278dc54cb07c136
parentc74b2e2336662c9f0b5fb01b979b93ea0b99803d (diff)
downloadqtserialport-d27ce6689855550ff89c5f84d38bded3c3da1dca.tar.gz
Move the WinCE implementation into separate module
WinCE implementation was mixed a common code with the Win32 implementation that caused some problems with maintenance. More correct decision is moving a common code which was used in *win.cpp into *wince.cpp module without modifications. Now the Win32 and the WinCE implementation are independent from each other. Tested build with Qt5 on "win32-msvc2012" and then with Qt4 on "wincewm50pocket-msvc2008" configurations. Change-Id: I63f687468beffa9a75b534a4fbe536b854b12210 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport.cpp4
-rw-r--r--src/serialport/qserialport_win.cpp28
-rw-r--r--src/serialport/qserialport_win_p.h28
-rw-r--r--src/serialport/qserialport_wince.cpp437
-rw-r--r--src/serialport/qserialport_wince_p.h126
-rw-r--r--src/serialport/qserialportinfo_win.cpp6
-rw-r--r--src/serialport/qserialportinfo_wince.cpp35
-rw-r--r--src/serialport/serialport-lib.pri19
8 files changed, 587 insertions, 96 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index 6508940..7d3863c 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -45,7 +45,9 @@
#include "qserialport.h"
#include "qserialportinfo.h"
-#ifdef Q_OS_WIN
+#ifdef Q_OS_WINCE
+#include "qserialport_wince_p.h"
+#elif defined (Q_OS_WIN)
#include "qserialport_win_p.h"
#elif defined (Q_OS_SYMBIAN)
#include "qserialport_symbian_p.h"
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index e319863..63d0a6d 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -44,13 +44,9 @@
#include "qserialport_win_p.h"
#include <QtCore/qcoreevent.h>
-
-#ifndef Q_OS_WINCE
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qvector.h>
#include <QtCore/qtimer.h>
-#endif
-
#include <QtCore/qwineventnotifier.h>
#include <algorithm>
@@ -87,8 +83,6 @@
QT_BEGIN_NAMESPACE
-#ifndef Q_OS_WINCE
-
static void initializeOverlappedStructure(OVERLAPPED &overlapped)
{
overlapped.Internal = 0;
@@ -245,8 +239,6 @@ void QSerialPortPrivate::close()
handle = INVALID_HANDLE_VALUE;
}
-#endif // #ifndef Q_OS_WINCE
-
QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
{
Q_Q(QSerialPort);
@@ -310,8 +302,6 @@ bool QSerialPortPrivate::setRequestToSend(bool set)
return true;
}
-#ifndef Q_OS_WINCE
-
bool QSerialPortPrivate::flush()
{
Q_Q(QSerialPort);
@@ -349,8 +339,6 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions)
return true;
}
-#endif
-
bool QSerialPortPrivate::sendBreak(int duration)
{
if (!setBreakEnabled(true))
@@ -376,8 +364,6 @@ bool QSerialPortPrivate::setBreakEnabled(bool set)
return true;
}
-#ifndef Q_OS_WINCE
-
void QSerialPortPrivate::startWriting()
{
Q_Q(QSerialPort);
@@ -471,8 +457,6 @@ bool QSerialPortPrivate::waitForBytesWritten(int msecs)
return false;
}
-#endif // #ifndef Q_OS_WINCE
-
bool QSerialPortPrivate::setBaudRate()
{
return setBaudRate(inputBaudRate, QSerialPort::AllDirections);
@@ -572,8 +556,6 @@ bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy)
return true;
}
-#ifndef Q_OS_WINCE
-
void QSerialPortPrivate::_q_completeAsyncCommunication()
{
Q_Q(QSerialPort);
@@ -758,8 +740,6 @@ void QSerialPortPrivate::emitReadyRead()
emit q->readyRead();
}
-#endif // #ifndef Q_OS_WINCE
-
void QSerialPortPrivate::processIoErrors(bool error)
{
Q_Q(QSerialPort);
@@ -787,8 +767,6 @@ void QSerialPortPrivate::processIoErrors(bool error)
}
}
-#ifndef Q_OS_WINCE
-
bool QSerialPortPrivate::updateDcb()
{
Q_Q(QSerialPort);
@@ -811,8 +789,6 @@ bool QSerialPortPrivate::updateCommTimeouts()
return true;
}
-#endif // #ifndef Q_OS_WINCE
-
QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError() const
{
QSerialPort::SerialPortError error;
@@ -851,8 +827,6 @@ QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError() const
return error;
}
-#ifndef Q_OS_WINCE
-
bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut, HANDLE *triggeredEvent)
{
Q_Q(QSerialPort);
@@ -899,8 +873,6 @@ QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location)
return ret;
}
-#endif // #ifndef Q_OS_WINCE
-
// This table contains standard values of baud rates that
// are defined in MSDN and/or in Win SDK file winbase.h
diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h
index 461226b..f6c3b0a 100644
--- a/src/serialport/qserialport_win_p.h
+++ b/src/serialport/qserialport_win_p.h
@@ -45,18 +45,14 @@
#include "qserialport_p.h"
+#include <QtCore/qhash.h>
+
#include <qt_windows.h>
-#ifndef Q_OS_WINCE
-#include <QtCore/qhash.h>
QT_BEGIN_NAMESPACE
+
class QWinEventNotifier;
class QTimer;
-#else
-#include <QtCore/qmutex.h>
-QT_BEGIN_NAMESPACE
-class QThread;
-#endif
class QSerialPortPrivate : public QSerialPortPrivateData
{
@@ -94,7 +90,7 @@ public:
void processIoErrors(bool error);
QSerialPort::SerialPortError decodeSystemError() const;
-#ifndef Q_OS_WINCE
+
void _q_completeAsyncCommunication();
void _q_completeAsyncRead();
void _q_completeAsyncWrite();
@@ -105,10 +101,6 @@ public:
bool emulateErrorPolicy();
void emitReadyRead();
-#else
- bool notifyRead();
- bool notifyWrite();
-#endif
static QString portNameToSystemLocation(const QString &port);
static QString portNameFromSystemLocation(const QString &location);
@@ -124,8 +116,6 @@ public:
COMMTIMEOUTS restoredCommTimeouts;
HANDLE handle;
bool parityErrorOccurred;
-
-#ifndef Q_OS_WINCE
QByteArray readChunkBuffer;
bool readyReadEmitted;
bool writeStarted;
@@ -138,23 +128,13 @@ public:
OVERLAPPED writeCompletionOverlapped;
DWORD originalEventMask;
DWORD triggeredEventMask;
-#else
- QThread *eventNotifier;
- QMutex settingsChangeMutex;
-#endif
private:
bool updateDcb();
bool updateCommTimeouts();
-#ifndef Q_OS_WINCE
bool waitAnyEvent(int msecs, bool *timedOut, HANDLE *triggeredEvent);
-#else
- bool waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
- bool checkRead, bool checkWrite,
- int msecs, bool *timedOut);
-#endif
};
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index 9ccc361..4a523ae 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -41,12 +41,43 @@
**
****************************************************************************/
-#include "qserialport_win_p.h"
+#include "qserialport_wince_p.h"
#include <QtCore/qelapsedtimer.h>
-
#include <QtCore/qthread.h>
#include <QtCore/qtimer.h>
+#include <algorithm>
+
+#ifndef CTL_CODE
+# define CTL_CODE(DeviceType, Function, Method, Access) ( \
+ ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
+ )
+#endif
+
+#ifndef FILE_DEVICE_SERIAL_PORT
+# define FILE_DEVICE_SERIAL_PORT 27
+#endif
+
+#ifndef METHOD_BUFFERED
+# define METHOD_BUFFERED 0
+#endif
+
+#ifndef FILE_ANY_ACCESS
+# define FILE_ANY_ACCESS 0x00000000
+#endif
+
+#ifndef IOCTL_SERIAL_GET_DTRRTS
+# define IOCTL_SERIAL_GET_DTRRTS \
+ CTL_CODE(FILE_DEVICE_SERIAL_PORT, 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#endif
+
+#ifndef SERIAL_DTR_STATE
+# define SERIAL_DTR_STATE 0x00000001
+#endif
+
+#ifndef SERIAL_RTS_STATE
+# define SERIAL_RTS_STATE 0x00000002
+#endif
QT_BEGIN_NAMESPACE
@@ -243,6 +274,69 @@ void QSerialPortPrivate::close()
handle = INVALID_HANDLE_VALUE;
}
+QSerialPort::PinoutSignals QSerialPortPrivate::pinoutSignals()
+{
+ Q_Q(QSerialPort);
+
+ DWORD modemStat = 0;
+
+ if (!::GetCommModemStatus(handle, &modemStat)) {
+ q->setError(decodeSystemError());
+ return QSerialPort::NoSignal;
+ }
+
+ QSerialPort::PinoutSignals ret = QSerialPort::NoSignal;
+
+ if (modemStat & MS_CTS_ON)
+ ret |= QSerialPort::ClearToSendSignal;
+ if (modemStat & MS_DSR_ON)
+ ret |= QSerialPort::DataSetReadySignal;
+ if (modemStat & MS_RING_ON)
+ ret |= QSerialPort::RingIndicatorSignal;
+ if (modemStat & MS_RLSD_ON)
+ ret |= QSerialPort::DataCarrierDetectSignal;
+
+ DWORD bytesReturned = 0;
+ if (!::DeviceIoControl(handle, IOCTL_SERIAL_GET_DTRRTS, NULL, 0,
+ &modemStat, sizeof(modemStat),
+ &bytesReturned, NULL)) {
+ q->setError(decodeSystemError());
+ return ret;
+ }
+
+ if (modemStat & SERIAL_DTR_STATE)
+ ret |= QSerialPort::DataTerminalReadySignal;
+ if (modemStat & SERIAL_RTS_STATE)
+ ret |= QSerialPort::RequestToSendSignal;
+
+ return ret;
+}
+
+bool QSerialPortPrivate::setDataTerminalReady(bool set)
+{
+ Q_Q(QSerialPort);
+
+ if (!::EscapeCommFunction(handle, set ? SETDTR : CLRDTR)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ currentDcb.fDtrControl = set ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;
+ return true;
+}
+
+bool QSerialPortPrivate::setRequestToSend(bool set)
+{
+ Q_Q(QSerialPort);
+
+ if (!::EscapeCommFunction(handle, set ? SETRTS : CLRRTS)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ return true;
+}
+
bool QSerialPortPrivate::flush()
{
return notifyWrite() && ::FlushFileBuffers(handle);
@@ -258,6 +352,31 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions)
return ::PurgeComm(handle, flags);
}
+bool QSerialPortPrivate::sendBreak(int duration)
+{
+ if (!setBreakEnabled(true))
+ return false;
+
+ ::Sleep(duration);
+
+ if (!setBreakEnabled(false))
+ return false;
+
+ return true;
+}
+
+bool QSerialPortPrivate::setBreakEnabled(bool set)
+{
+ Q_Q(QSerialPort);
+
+ if (set ? !::SetCommBreak(handle) : !::ClearCommBreak(handle)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ return true;
+}
+
void QSerialPortPrivate::startWriting()
{
// trigger write sequence
@@ -324,6 +443,105 @@ bool QSerialPortPrivate::waitForBytesWritten(int msec)
return false;
}
+bool QSerialPortPrivate::setBaudRate()
+{
+ return setBaudRate(inputBaudRate, QSerialPort::AllDirections);
+}
+
+bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions)
+{
+ Q_Q(QSerialPort);
+
+ if (directions != QSerialPort::AllDirections) {
+ q->setError(QSerialPort::UnsupportedOperationError);
+ return false;
+ }
+ currentDcb.BaudRate = baudRate;
+ return updateDcb();
+}
+
+bool QSerialPortPrivate::setDataBits(QSerialPort::DataBits dataBits)
+{
+ currentDcb.ByteSize = dataBits;
+ return updateDcb();
+}
+
+bool QSerialPortPrivate::setParity(QSerialPort::Parity parity)
+{
+ currentDcb.fParity = TRUE;
+ switch (parity) {
+ case QSerialPort::NoParity:
+ currentDcb.Parity = NOPARITY;
+ currentDcb.fParity = FALSE;
+ break;
+ case QSerialPort::OddParity:
+ currentDcb.Parity = ODDPARITY;
+ break;
+ case QSerialPort::EvenParity:
+ currentDcb.Parity = EVENPARITY;
+ break;
+ case QSerialPort::MarkParity:
+ currentDcb.Parity = MARKPARITY;
+ break;
+ case QSerialPort::SpaceParity:
+ currentDcb.Parity = SPACEPARITY;
+ break;
+ default:
+ currentDcb.Parity = NOPARITY;
+ currentDcb.fParity = FALSE;
+ break;
+ }
+ return updateDcb();
+}
+
+bool QSerialPortPrivate::setStopBits(QSerialPort::StopBits stopBits)
+{
+ switch (stopBits) {
+ case QSerialPort::OneStop:
+ currentDcb.StopBits = ONESTOPBIT;
+ break;
+ case QSerialPort::OneAndHalfStop:
+ currentDcb.StopBits = ONE5STOPBITS;
+ break;
+ case QSerialPort::TwoStop:
+ currentDcb.StopBits = TWOSTOPBITS;
+ break;
+ default:
+ currentDcb.StopBits = ONESTOPBIT;
+ break;
+ }
+ return updateDcb();
+}
+
+bool QSerialPortPrivate::setFlowControl(QSerialPort::FlowControl flowControl)
+{
+ currentDcb.fInX = FALSE;
+ currentDcb.fOutX = FALSE;
+ currentDcb.fOutxCtsFlow = FALSE;
+ currentDcb.fRtsControl = RTS_CONTROL_DISABLE;
+ switch (flowControl) {
+ case QSerialPort::NoFlowControl:
+ break;
+ case QSerialPort::SoftwareControl:
+ currentDcb.fInX = TRUE;
+ currentDcb.fOutX = TRUE;
+ break;
+ case QSerialPort::HardwareControl:
+ currentDcb.fOutxCtsFlow = TRUE;
+ currentDcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
+ break;
+ default:
+ break;
+ }
+ return updateDcb();
+}
+
+bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy)
+{
+ policy = policy;
+ return true;
+}
+
bool QSerialPortPrivate::notifyRead()
{
Q_Q(QSerialPort);
@@ -401,39 +619,31 @@ bool QSerialPortPrivate::notifyWrite()
return true;
}
-bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
- bool checkRead, bool checkWrite,
- int msecs, bool *timedOut)
+void QSerialPortPrivate::processIoErrors(bool error)
{
Q_Q(QSerialPort);
- DWORD eventMask = 0;
- // FIXME: Here the situation is not properly handled with zero timeout:
- // breaker can work out before you call a method WaitCommEvent()
- // and so it will loop forever!
- WaitCommEventBreaker breaker(handle, qMax(msecs, 0));
- ::WaitCommEvent(handle, &eventMask, NULL);
- breaker.stop();
-
- if (breaker.isWorked()) {
- *timedOut = true;
- q->setError(QSerialPort::TimeoutError);
+ if (error) {
+ q->setError(QSerialPort::ResourceError);
+ return;
}
- if (!breaker.isWorked()) {
- if (checkRead) {
- Q_ASSERT(selectForRead);
- *selectForRead = eventMask & EV_RXCHAR;
- }
- if (checkWrite) {
- Q_ASSERT(selectForWrite);
- *selectForWrite = eventMask & EV_TXEMPTY;
- }
-
- return true;
+ DWORD errors = 0;
+ if (!::ClearCommError(handle, &errors, NULL)) {
+ q->setError(decodeSystemError());
+ return;
}
- return false;
+ if (errors & CE_FRAME) {
+ q->setError(QSerialPort::FramingError);
+ } else if (errors & CE_RXPARITY) {
+ q->setError(QSerialPort::ParityError);
+ parityErrorOccurred = true;
+ } else if (errors & CE_BREAK) {
+ q->setError(QSerialPort::BreakConditionError);
+ } else {
+ q->setError(QSerialPort::UnknownError);
+ }
}
bool QSerialPortPrivate::updateDcb()
@@ -470,6 +680,79 @@ bool QSerialPortPrivate::updateCommTimeouts()
return true;
}
+QSerialPort::SerialPortError QSerialPortPrivate::decodeSystemError() const
+{
+ QSerialPort::SerialPortError error;
+ switch (::GetLastError()) {
+ case ERROR_IO_PENDING:
+ error = QSerialPort::NoError;
+ break;
+ case ERROR_MORE_DATA:
+ error = QSerialPort::NoError;
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ error = QSerialPort::DeviceNotFoundError;
+ break;
+ case ERROR_INVALID_NAME:
+ error = QSerialPort::DeviceNotFoundError;
+ break;
+ case ERROR_ACCESS_DENIED:
+ error = QSerialPort::PermissionError;
+ break;
+ case ERROR_INVALID_HANDLE:
+ error = QSerialPort::ResourceError;
+ break;
+ case ERROR_INVALID_PARAMETER:
+ error = QSerialPort::UnsupportedOperationError;
+ break;
+ case ERROR_BAD_COMMAND:
+ error = QSerialPort::ResourceError;
+ break;
+ case ERROR_DEVICE_REMOVED:
+ error = QSerialPort::ResourceError;
+ break;
+ default:
+ error = QSerialPort::UnknownError;
+ break;
+ }
+ return error;
+}
+
+bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
+ bool checkRead, bool checkWrite,
+ int msecs, bool *timedOut)
+{
+ Q_Q(QSerialPort);
+
+ DWORD eventMask = 0;
+ // FIXME: Here the situation is not properly handled with zero timeout:
+ // breaker can work out before you call a method WaitCommEvent()
+ // and so it will loop forever!
+ WaitCommEventBreaker breaker(handle, qMax(msecs, 0));
+ ::WaitCommEvent(handle, &eventMask, NULL);
+ breaker.stop();
+
+ if (breaker.isWorked()) {
+ *timedOut = true;
+ q->setError(QSerialPort::TimeoutError);
+ }
+
+ if (!breaker.isWorked()) {
+ if (checkRead) {
+ Q_ASSERT(selectForRead);
+ *selectForRead = eventMask & EV_RXCHAR;
+ }
+ if (checkWrite) {
+ Q_ASSERT(selectForWrite);
+ *selectForWrite = eventMask & EV_TXEMPTY;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
QString QSerialPortPrivate::portNameToSystemLocation(const QString &port)
{
QString ret = port;
@@ -486,4 +769,102 @@ QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location)
return ret;
}
+static const QList<qint32> standardBaudRatePairList()
+{
+
+ static const QList<qint32> standardBaudRatesTable = QList<qint32>()
+
+ #ifdef CBR_110
+ << CBR_110
+ #endif
+
+ #ifdef CBR_300
+ << CBR_300
+ #endif
+
+ #ifdef CBR_600
+ << CBR_600
+ #endif
+
+ #ifdef CBR_1200
+ << CBR_1200
+ #endif
+
+ #ifdef CBR_2400
+ << CBR_2400
+ #endif
+
+ #ifdef CBR_4800
+ << CBR_4800
+ #endif
+
+ #ifdef CBR_9600
+ << CBR_9600
+ #endif
+
+ #ifdef CBR_14400
+ << CBR_14400
+ #endif
+
+ #ifdef CBR_19200
+ << CBR_19200
+ #endif
+
+ #ifdef CBR_38400
+ << CBR_38400
+ #endif
+
+ #ifdef CBR_56000
+ << CBR_56000
+ #endif
+
+ #ifdef CBR_57600
+ << CBR_57600
+ #endif
+
+ #ifdef CBR_115200
+ << CBR_115200
+ #endif
+
+ #ifdef CBR_128000
+ << CBR_128000
+ #endif
+
+ #ifdef CBR_256000
+ << CBR_256000
+ #endif
+ ;
+
+ return standardBaudRatesTable;
+};
+
+qint32 QSerialPortPrivate::baudRateFromSetting(qint32 setting)
+{
+ const QList<qint32> baudRatePairs = standardBaudRatePairList();
+ const QList<qint32>::const_iterator baudRatePairListConstIterator
+ = std::find(baudRatePairs.constBegin(), baudRatePairs.constEnd(), setting);
+
+ return (baudRatePairListConstIterator != baudRatePairs.constEnd()) ? *baudRatePairListConstIterator : 0;
+}
+
+qint32 QSerialPortPrivate::settingFromBaudRate(qint32 baudRate)
+{
+ const QList<qint32> baudRatePairList = standardBaudRatePairList();
+ const QList<qint32>::const_iterator baudRatePairListConstIterator
+ = std::find(baudRatePairList.constBegin(), baudRatePairList.constEnd(), baudRate);
+
+ return (baudRatePairListConstIterator != baudRatePairList.constEnd()) ? *baudRatePairListConstIterator : 0;
+}
+
+QList<qint32> QSerialPortPrivate::standardBaudRates()
+{
+ return standardBaudRatePairList();
+}
+
+QSerialPort::Handle QSerialPort::handle() const
+{
+ Q_D(const QSerialPort);
+ return d->handle;
+}
+
QT_END_NAMESPACE
diff --git a/src/serialport/qserialport_wince_p.h b/src/serialport/qserialport_wince_p.h
new file mode 100644
index 0000000..11d0534
--- /dev/null
+++ b/src/serialport/qserialport_wince_p.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSerialPort module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSERIALPORT_WINCE_P_H
+#define QSERIALPORT_WINCE_P_H
+
+#include "qserialport_p.h"
+
+#include <QtCore/qmutex.h>
+
+#include <qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+
+class QThread;
+
+class QSerialPortPrivate : public QSerialPortPrivateData
+{
+ Q_DECLARE_PUBLIC(QSerialPort)
+
+public:
+ QSerialPortPrivate(QSerialPort *q);
+
+ bool open(QIODevice::OpenMode mode);
+ void close();
+
+ QSerialPort::PinoutSignals pinoutSignals();
+
+ bool setDataTerminalReady(bool set);
+ bool setRequestToSend(bool set);
+
+ bool flush();
+ bool clear(QSerialPort::Directions directions);
+
+ bool sendBreak(int duration);
+ bool setBreakEnabled(bool set);
+
+ void startWriting();
+
+ bool waitForReadyRead(int msec);
+ bool waitForBytesWritten(int msec);
+
+ bool setBaudRate();
+ bool setBaudRate(qint32 baudRate, QSerialPort::Directions directions);
+ bool setDataBits(QSerialPort::DataBits dataBits);
+ bool setParity(QSerialPort::Parity parity);
+ bool setStopBits(QSerialPort::StopBits stopBits);
+ bool setFlowControl(QSerialPort::FlowControl flowControl);
+ bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
+
+ void processIoErrors(bool error);
+ QSerialPort::SerialPortError decodeSystemError() const;
+
+ bool notifyRead();
+ bool notifyWrite();
+
+ static QString portNameToSystemLocation(const QString &port);
+ static QString portNameFromSystemLocation(const QString &location);
+
+ static qint32 baudRateFromSetting(qint32 setting);
+ static qint32 settingFromBaudRate(qint32 baudRate);
+
+ static QList<qint32> standardBaudRates();
+
+ DCB currentDcb;
+ DCB restoredDcb;
+ COMMTIMEOUTS currentCommTimeouts;
+ COMMTIMEOUTS restoredCommTimeouts;
+ HANDLE handle;
+ bool parityErrorOccurred;
+
+ QThread *eventNotifier;
+ QMutex settingsChangeMutex;
+
+private:
+ bool updateDcb();
+ bool updateCommTimeouts();
+
+ bool waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
+ bool checkRead, bool checkWrite,
+ int msecs, bool *timedOut);
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QSERIALPORT_WINCE_P_H
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index 448f3ed..8e449c4 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -45,19 +45,15 @@
#include "qserialportinfo_p.h"
#include "qserialport_win_p.h"
-#ifndef Q_OS_WINCE
#include <QtCore/quuid.h>
#include <QtCore/qpair.h>
#include <QtCore/qstringlist.h>
#include <initguid.h>
#include <setupapi.h>
-#endif
QT_BEGIN_NAMESPACE
-#ifndef Q_OS_WINCE
-
typedef QPair<QUuid, DWORD> GuidFlagsPair;
static inline const QList<GuidFlagsPair>& guidFlagsPairs()
@@ -302,8 +298,6 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
return serialPortInfoList;
}
-#endif
-
QList<qint32> QSerialPortInfo::standardBaudRates()
{
return QSerialPortPrivate::standardBaudRates();
diff --git a/src/serialport/qserialportinfo_wince.cpp b/src/serialport/qserialportinfo_wince.cpp
index 27ecb28..a44b99d 100644
--- a/src/serialport/qserialportinfo_wince.cpp
+++ b/src/serialport/qserialportinfo_wince.cpp
@@ -43,7 +43,7 @@
#include "qserialportinfo.h"
#include "qserialportinfo_p.h"
-#include "qserialport_win_p.h"
+#include "qserialport_wince_p.h"
#include <QtCore/qstringlist.h>
@@ -128,4 +128,37 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
return serialPortInfoList;
}
+QList<qint32> QSerialPortInfo::standardBaudRates()
+{
+ return QSerialPortPrivate::standardBaudRates();
+}
+
+bool QSerialPortInfo::isBusy() const
+{
+ const HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()),
+ GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (handle == INVALID_HANDLE_VALUE) {
+ if (::GetLastError() == ERROR_ACCESS_DENIED)
+ return true;
+ } else {
+ ::CloseHandle(handle);
+ }
+ return false;
+}
+
+bool QSerialPortInfo::isValid() const
+{
+ const HANDLE handle = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()),
+ GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (handle == INVALID_HANDLE_VALUE) {
+ if (::GetLastError() != ERROR_ACCESS_DENIED)
+ return false;
+ } else {
+ ::CloseHandle(handle);
+ }
+ return true;
+}
+
QT_END_NAMESPACE
diff --git a/src/serialport/serialport-lib.pri b/src/serialport/serialport-lib.pri
index b228d01..166a6fa 100644
--- a/src/serialport/serialport-lib.pri
+++ b/src/serialport/serialport-lib.pri
@@ -29,7 +29,7 @@ SOURCES += \
$$PWD/qserialport.cpp \
$$PWD/qserialportinfo.cpp
-win32 {
+win32:!wince* {
PRIVATE_HEADERS += \
$$PWD/qserialport_win_p.h
@@ -37,13 +37,16 @@ win32 {
$$PWD/qserialport_win.cpp \
$$PWD/qserialportinfo_win.cpp
- !wince*: {
- LIBS_PRIVATE += -lsetupapi -ladvapi32
- } else {
- SOURCES += \
- $$PWD/qserialport_wince.cpp \
- $$PWD/qserialportinfo_wince.cpp
- }
+ LIBS_PRIVATE += -lsetupapi -ladvapi32
+}
+
+wince* {
+ PRIVATE_HEADERS += \
+ $$PWD/qserialport_wince_p.h
+
+ SOURCES += \
+ $$PWD/qserialport_wince.cpp \
+ $$PWD/qserialportinfo_wince.cpp
}
symbian {