summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialport_wince.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialport/qserialport_wince.cpp')
-rw-r--r--src/serialport/qserialport_wince.cpp83
1 files changed, 47 insertions, 36 deletions
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index 4a523ae6..c06e748c 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -219,43 +219,11 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
return false;
}
- ::ZeroMemory(&restoredDcb, sizeof(restoredDcb));
- restoredDcb.DCBlength = sizeof(restoredDcb);
-
- if (!::GetCommState(handle, &restoredDcb)) {
- q->setError(decodeSystemError());
- return false;
- }
-
- currentDcb = restoredDcb;
- currentDcb.fBinary = true;
- currentDcb.fInX = false;
- currentDcb.fOutX = false;
- currentDcb.fAbortOnError = false;
- currentDcb.fNull = false;
- currentDcb.fErrorChar = false;
-
- if (currentDcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
- currentDcb.fDtrControl = DTR_CONTROL_DISABLE;
-
- if (!updateDcb())
- return false;
-
- if (!::GetCommTimeouts(handle, &restoredCommTimeouts)) {
- q->setError(decodeSystemError());
- return false;
- }
-
- ::memset(&currentCommTimeouts, 0, sizeof(currentCommTimeouts));
- currentCommTimeouts.ReadIntervalTimeout = MAXDWORD;
-
- if (!updateCommTimeouts())
- return false;
-
- eventNotifier = new CommEventNotifier(eventMask, this, q);
- eventNotifier->start();
+ if (initialize(eventMask))
+ return true;
- return true;
+ ::CloseHandle(handle);
+ return false;
}
void QSerialPortPrivate::close()
@@ -646,6 +614,49 @@ void QSerialPortPrivate::processIoErrors(bool error)
}
}
+inline bool QSerialPortPrivate::initialize(DWORD eventMask)
+{
+ Q_Q(QSerialPort);
+
+ ::ZeroMemory(&restoredDcb, sizeof(restoredDcb));
+ restoredDcb.DCBlength = sizeof(restoredDcb);
+
+ if (!::GetCommState(handle, &restoredDcb)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ currentDcb = restoredDcb;
+ currentDcb.fBinary = true;
+ currentDcb.fInX = false;
+ currentDcb.fOutX = false;
+ currentDcb.fAbortOnError = false;
+ currentDcb.fNull = false;
+ currentDcb.fErrorChar = false;
+
+ if (currentDcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
+ currentDcb.fDtrControl = DTR_CONTROL_DISABLE;
+
+ if (!updateDcb())
+ return false;
+
+ if (!::GetCommTimeouts(handle, &restoredCommTimeouts)) {
+ q->setError(decodeSystemError());
+ return false;
+ }
+
+ ::memset(&currentCommTimeouts, 0, sizeof(currentCommTimeouts));
+ currentCommTimeouts.ReadIntervalTimeout = MAXDWORD;
+
+ if (!updateCommTimeouts())
+ return false;
+
+ eventNotifier = new CommEventNotifier(eventMask, this, q);
+ eventNotifier->start();
+
+ return true;
+}
+
bool QSerialPortPrivate::updateDcb()
{
Q_Q(QSerialPort);