From 3ead2c7ec7324f066883cba5f053193cffe2b2de Mon Sep 17 00:00:00 2001 From: Bernard Pratz Date: Mon, 28 Apr 2014 16:12:39 +0200 Subject: [PATCH] Fixed bug on opening any unix serial device on OSX. Instead of removing '/dev/tty.', and always prepending '/dev/cu.' to every device, this patch replaces 'tty.' with 'cu.', and leaves the default unix behaviour of adding '/dev' to character devices that are missing the absolute path. --- 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 0f999bb..fd48903 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -1143,11 +1143,10 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize) return ret; } -#ifdef Q_OS_MAC -static const QString defaultFilePathPrefix = QStringLiteral("/dev/cu."); -static const QString unusedFilePathPrefix = QStringLiteral("/dev/tty."); -#else static const QString defaultFilePathPrefix = QStringLiteral("/dev/"); +#ifdef Q_OS_MAC +static const QString wrongFilePrefix = QStringLiteral("cu."); +static const QString goodFilePrefix = QStringLiteral("tty."); #endif QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) @@ -1155,7 +1154,10 @@ QString QSerialPortPrivate::portNameToSystemLocation(const QString &port) QString ret = port; #ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); + if (ret.contains(wrongFilePrefix)) { + ret.remove(wrongFilePrefix); + ret.prepend(goodFilePrefix); + } #endif if (!ret.contains(defaultFilePathPrefix)) @@ -1168,7 +1170,12 @@ QString QSerialPortPrivate::portNameFromSystemLocation(const QString &location) QString ret = location; #ifdef Q_OS_MAC - ret.remove(unusedFilePathPrefix); + if (ret.contains(wrongFilePrefix)) { + ret.remove(wrongFilePrefix); + } + if (ret.contains(goodFilePrefix)) { + ret.prepend(goodFilePrefix); + } #endif ret.remove(defaultFilePathPrefix); -- 1.8.3.4 (Apple Git-47)