summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <scapig@yandex.ru>2012-10-24 23:38:48 +0400
committerDenis Shienkov <scapig@yandex.ru>2012-10-29 13:21:41 +0100
commiteca1a6d30a98861cb811cb2faf8d01334e60dd7c (patch)
tree9b97eaf6bed57ecd35a72e648dba64258d5d5556
parentc930cd46da565ee9abdf92dc83dd053b5f304a47 (diff)
downloadqtserialport-eca1a6d30a98861cb811cb2faf8d01334e60dd7c.tar.gz
Windows: fix write for Bluetooth serial ports
Bluetooth serial ports (at least from the Microsoft stack) do not support the event EV_TXEMPTY. Therefore, for this reason, the writing to the port was stopped after transmission of the first chunk of data from the internal ring buffer of class. Because further write the chunk of data to the port should be called after triggered EV_TXEMPTY event. The solution is to abandon the EV_TXEMPTY from design in library. Now, for the launch to send of the next chunk of data to the port is the event from write completion overlapped structure. Asynchronous transmission is performed as long as the internal ring buffer is not empty. This solution also reduces the load on the CPU because the deleted event processing for EV_TXEMPTY. Task-number: QTPLAYGROUND-8 Change-Id: Ib4e21824ea783e1fe64ce0fa0be49ef0e69a99a6 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Aleksei Timofeyev <aleksei.timofeyev@gmail.com> Reviewed-by: Denis Shienkov <scapig@yandex.ru>
-rw-r--r--src/serialport_win.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/serialport_win.cpp b/src/serialport_win.cpp
index 8caba50..af43f79 100644
--- a/src/serialport_win.cpp
+++ b/src/serialport_win.cpp
@@ -107,8 +107,6 @@ protected:
if (!dptr->readSequenceStarted)
dptr->startAsyncRead();
}
- if (EV_TXEMPTY & dptr->eventMask)
- dptr->startAsyncWrite(SerialPortPrivateData::WriteChunkSize);
::WaitCommEvent(dptr->descriptor, &dptr->eventMask, &dptr->eventOverlapped);
}
return ret;
@@ -248,6 +246,10 @@ bool SerialPortPrivate::open(QIODevice::OpenMode mode)
}
if (eventMask & EV_TXEMPTY) {
+ // Disable EV_TXEMPTY for CommEventNotifier because not all serial ports
+ // (such as from Bluetooth stack of Microsoft) supported this feature.
+ // I.e. now do not use this event to write to the port.
+ eventMask &= ~EV_TXEMPTY;
::memset(&writeOverlapped, 0, sizeof(writeOverlapped));
writeOverlapped.hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
writeCompletionNotifier = new WriteCompletionNotifier(this, q_ptr);
@@ -804,8 +806,11 @@ bool SerialPortPrivate::completeAsyncWrite(DWORD numberOfBytes)
if (numberOfBytes > 0)
emit q_ptr->bytesWritten(numberOfBytes);
- else
+
+ if (writeBuffer.isEmpty())
writeSequenceStarted = false;
+ else
+ startAsyncWrite(WriteChunkSize);
return true;
}