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 <heiko@bihr.internal>
This commit is contained in:
heikobihr 2020-06-28 22:45:43 +02:00 committed by GitHub
parent 2562787dae
commit e365a2839d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -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;
}