Skip to content

Commit

Permalink
fix: Windows serialport detection (fix #836) (#837)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
heikobihr and heiko authored Jun 28, 2020
1 parent 2562787 commit e365a28
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libsrc/leddevice/dev_serial/ProviderRs232.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand All @@ -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;
}
Expand Down

0 comments on commit e365a28

Please sign in to comment.