From fbb9851fcf4a52220045f98a5e552ec5c04a978a Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Wed, 9 Sep 2015 15:29:06 +0300 Subject: 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 Reviewed-by: Denis Shienkov --- src/serialport/qserialport_unix.cpp | 19 +++++++++++++------ 1 file 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) { -- cgit v1.2.1