summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-09-09 15:29:06 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-09-10 08:40:53 +0000
commit9be50642172b1fcb8c539e534b64afc063dc42ba (patch)
treeb7d9351d0ef20cc1bd98b4ff97453811b6b45c23
parent2ab0a814dcd050e6cfb278a450549482400d5f73 (diff)
downloadqtserialport-9be50642172b1fcb8c539e534b64afc063dc42ba.tar.gz
Return an error at trying to set custom speed for separate direction
It is impossible to use a custom speed on Linux and OS X for the separate direction; the custom speed always sets for all directions at once. (cherry-picked from fbb9851fcf4a52220045f98a5e552ec5c04a978a) Change-Id: I3cc0df6c5fba6c6fde38e0d49987b632f1aa571f Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_unix.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 7954cc3..284dc76 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -501,17 +501,20 @@ bool QSerialPortPrivate::setStandardBaudRate(qint32 baudRate, QSerialPort::Direc
bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
+ if (directions != QSerialPort::AllDirections) {
+ setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError,
+ QSerialPort::tr("Cannot set custom speed for one direction")));
+ return false;
+ }
+
struct termios2 tio2;
if (::ioctl(descriptor, TCGETS2, &tio2) != -1) {
tio2.c_cflag &= ~CBAUD;
tio2.c_cflag |= BOTHER;
- if (directions & QSerialPort::Input)
- tio2.c_ispeed = baudRate;
-
- if (directions & QSerialPort::Output)
- tio2.c_ospeed = baudRate;
+ tio2.c_ispeed = baudRate;
+ tio2.c_ospeed = baudRate;
if (::ioctl(descriptor, TCSETS2, &tio2) != -1
&& ::ioctl(descriptor, TCGETS2, &tio2) != -1) {
@@ -555,7 +558,11 @@ bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directi
bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
- Q_UNUSED(directions);
+ if (directions != QSerialPort::AllDirections) {
+ setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError,
+ QSerialPort::tr("Cannot set custom speed for one direction")));
+ return false;
+ }
#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
if (::ioctl(descriptor, IOSSIOSPEED, &baudRate) == -1) {