From e365a2839d327c9f6e3836e7f4c5e552522df425 Mon Sep 17 00:00:00 2001 From: heikobihr Date: Sun, 28 Jun 2020 22:45:43 +0200 Subject: [PATCH] fix: Windows serialport detection (fix #836) (#837) * use QSerialPortInfo do detect presence of a serial port (fix #836) * checking for existence of device file does not work on windows * instead: construct QSerialPortInfo from device name and check, if it is not null When constructing QSerialPortInfo from device name, this constructor finds the relevant serial port among the available ones according to the port name name, and constructs the serial port info instance for that port. (https://doc.qt.io/qt-5/qserialportinfo.html#QSerialPortInfo-2) * serial port: set device in error with a failure text, if device name is invalid Co-authored-by: heiko --- libsrc/leddevice/dev_serial/ProviderRs232.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_serial/ProviderRs232.cpp b/libsrc/leddevice/dev_serial/ProviderRs232.cpp index 295dc491..711a5353 100644 --- a/libsrc/leddevice/dev_serial/ProviderRs232.cpp +++ b/libsrc/leddevice/dev_serial/ProviderRs232.cpp @@ -201,7 +201,9 @@ bool ProviderRs232::tryOpen(const int delayAfterConnect_ms) if ( ! _rs232Port.isOpen() ) { _frameDropCounter = 0; - if (QFile::exists(_deviceName)) + + QSerialPortInfo serialPortInfo(_deviceName); + if (! serialPortInfo.isNull()) { if ( _preOpenDelayTimeOut > QDateTime::currentMSecsSinceEpoch() ) { @@ -223,6 +225,8 @@ bool ProviderRs232::tryOpen(const int delayAfterConnect_ms) } else { + QString errortext = QString("Invalid serial device name: [%1]!").arg(_deviceName); + this->setInError(errortext); _preOpenDelayTimeOut = QDateTime::currentMSecsSinceEpoch() + _preOpenDelay; return false; }