summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <scapig@yandex.ru>2012-10-05 21:17:15 +0000
committerDenis Shienkov <scapig@yandex.ru>2012-10-09 14:30:04 +0200
commit78c80e52294399e17cacfe6ea5db08d4a5edab24 (patch)
tree77be5210ef26e78173c878b903fafdf48282a19f
parentf25d1da8b502655b7dc00d2534c0e60fc0fbc15a (diff)
downloadqtserialport-78c80e52294399e17cacfe6ea5db08d4a5edab24.tar.gz
*nix: change DTR and RTS directly via TIOCMBIS and TIOCMBIC
Earlier change lines DTR/RTS was produced by a long chain of calls: 1. Get state all lines. 2. Overlay the desired mask AND/OR. 3. Setup back resulting state all lines. Now setup or cleanup any from lines DTR or RTS made ​​directly with the commands TIOCMBIS and TIOCMBIC via ioctl() call. PS: Tested on GNU\Linux Change-Id: I8ac1d408751706e590631c0671b292791b8c2585 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <scapig@yandex.ru>
-rw-r--r--src/serialport_unix.cpp28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/serialport_unix.cpp b/src/serialport_unix.cpp
index 54b1ec4..1e1b75b 100644
--- a/src/serialport_unix.cpp
+++ b/src/serialport_unix.cpp
@@ -306,36 +306,16 @@ SerialPort::Lines SerialPortPrivate::lines() const
return ret;
}
-static bool trigger_out_line(int fd, int bit, bool set)
-{
- int arg = 0;
- bool ret = ::ioctl(fd, TIOCMGET, &arg) != -1;
-
- if (ret) {
- int tmp = arg & bit;
-
- // If line already installed, then it no need change.
- if ((tmp && set) || (!(tmp || set)))
- return true;
-
- if (set)
- arg |= bit;
- else
- arg &= ~bit;
-
- ret = ::ioctl(fd, TIOCMSET, &arg) != -1;
- }
- return ret;
-}
-
bool SerialPortPrivate::setDtr(bool set)
{
- return trigger_out_line(descriptor, TIOCM_DTR, set);
+ int status = TIOCM_DTR;
+ return ::ioctl(descriptor, set ? TIOCMBIS : TIOCMBIC, &status) != -1;
}
bool SerialPortPrivate::setRts(bool set)
{
- return trigger_out_line(descriptor, TIOCM_RTS, set);
+ int status = TIOCM_RTS;
+ return ::ioctl(descriptor, set ? TIOCMBIS : TIOCMBIC, &status) != -1;
}
bool SerialPortPrivate::flush()