Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanny32 committed Dec 5, 2024
2 parents 9bc6e09 + 2c7ca3e commit de1fce9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
9 changes: 4 additions & 5 deletions omodscan/controls/connectioncombobox.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <algorithm>
#include <QSerialPortInfo>
#include "serialportutils.h"
#include "connectioncombobox.h"

///
Expand All @@ -21,11 +21,10 @@ ConnectionComboBox::ConnectionComboBox(QWidget* parent)
{
addItem(tr("Remote TCP/IP Server"), ConnectionType::Tcp, QString());

QStringList ports;
for(auto&& port: QSerialPortInfo::availablePorts())
for(auto&& port: getAvailableSerialPorts())
{
const auto text = QString(tr("Direct Connection to %1")).arg(port.portName());
addItem(text, ConnectionType::Serial, port.portName());
const auto text = QString(tr("Direct Connection to %1")).arg(port);
addItem(text, ConnectionType::Serial, port);
}
}

Expand Down
4 changes: 2 additions & 2 deletions omodscan/controls/numericlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
{
const int nums = QString::number(top.toInt()).length();
_paddingZeroWidth = qMax(1, nums);
setMaxLength(qMax(1, nums));
setMaxLength(qMax(2, nums + 1));
setValidator(new QIntValidator(bottom.toInt(), top.toInt(), this));

}
Expand Down Expand Up @@ -475,7 +475,7 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
{
const int nums = QString::number(top.toLongLong()).length();
_paddingZeroWidth = qMax(1, nums);
setMaxLength(qMax(1, nums));
setMaxLength(qMax(2, nums + 1));
setValidator(new QInt64Validator(bottom.toLongLong(), top.toLongLong(), this));
}
break;
Expand Down
4 changes: 2 additions & 2 deletions omodscan/dialogs/dialogmodbusscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QNetworkInterface>
#include <QAbstractEventDispatcher>
#include "modbuslimits.h"
#include "serialportutils.h"
#include "modbusrtuscanner.h"
#include "modbustcpscanner.h"
#include "dialogmodbusscanner.h"
Expand Down Expand Up @@ -58,8 +59,7 @@ DialogModbusScanner::DialogModbusScanner(QWidget *parent)
ui->pushButtonScan->setIcon(_iconStart);

ui->radioButtonTCP->click();
for(auto&& port: QSerialPortInfo::availablePorts())
ui->comboBoxSerial->addItem(port.portName());
ui->comboBoxSerial->addItems(getAvailableSerialPorts());

QHostAddress address, mask;
for(auto&& eth : QNetworkInterface::allInterfaces()) {
Expand Down
3 changes: 2 additions & 1 deletion omodscan/omodscan.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CONFIG += c++17
CONFIG -= debug_and_release
CONFIG -= debug_and_release_target

VERSION = 1.8.0
VERSION = 1.8.1

QMAKE_TARGET_PRODUCT = "Open ModScan"
QMAKE_TARGET_DESCRIPTION = "An Open Source Modbus Master (Client) Utility"
Expand Down Expand Up @@ -176,6 +176,7 @@ HEADERS += \
qrange.h \
quintvalidator.h \
recentfileactionlist.h \
serialportutils.h \
windowactionlist.h

FORMS += \
Expand Down
26 changes: 26 additions & 0 deletions omodscan/serialportutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef SERIALPORTUTILS_H
#define SERIALPORTUTILS_H

#include <QSerialPortInfo>
#include <QRegularExpression>

///
/// \brief getAvailableSerialPorts
/// \return
///
inline QStringList getAvailableSerialPorts()
{
QStringList ports;
for(auto&& port: QSerialPortInfo::availablePorts())
ports << port.portName();

static QRegularExpression re( "[^\\d]");
std::sort(ports.begin(), ports.end(), [](QString p1, QString p2)
{
return p1.remove(re).toInt() < p2.remove(re).toInt();
});

return ports;
}

#endif // SERIALPORTUTILS_H

0 comments on commit de1fce9

Please sign in to comment.