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-09 17:30:19 +0000
commitfbb9851fcf4a52220045f98a5e552ec5c04a978a (patch)
tree0670b7c9e0053eeef08736510503cfcb2cc4aba2
parenteb0535c9701202d5f74fe1fc9b3b094bbecb8043 (diff)
downloadqtserialport-fbb9851fcf4a52220045f98a5e552ec5c04a978a.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. Change-Id: I3cc0df6c5fba6c6fde38e0d49987b632f1aa571f Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> 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 9b560be..f058acf 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -483,17 +483,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) {
@@ -537,7 +540,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) {