Skip to content

Commit ed920b4

Browse files
author
Mich
committed
Changed how serial port names are selected for better compatibility.
1 parent 2edcfe6 commit ed920b4

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99
"Welcome to QtSerialMonitor, \n" \
1010
"Press F1 to activate \"What's this\" mode. In this mode, clicked widget \r" \
1111
"will display an explanation about its function. \n"
12+
13+
#define RADIO_BUTTON_UPDATE_SERIAL_DEVICES_ON_INTERVAL 100
14+
#define SERIAL_DEVICE_CHECK_TIMER_INTERVAL 500
15+
1216
#endif // CONFIG_H

src/highlighter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050

5151
#include "highlighter.h"
5252

53-
Highlighter::Highlighter(QTextDocument *parent)
54-
: QSyntaxHighlighter(parent)
53+
Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent)
5554
{
5655
HighlightingRule rule;
5756

@@ -107,7 +106,7 @@ void Highlighter::highlightBlock(const QString &text)
107106
{
108107
for (const HighlightingRule &rule : qAsConst(highlightingRules))
109108
{
110-
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text,0,
109+
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text, 0,
111110
QRegularExpression::MatchType::PartialPreferCompleteMatch,
112111
QRegularExpression::MatchOption::NoMatchOption);
113112
if (matchIterator.hasNext())

src/mainwindow.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void MainWindow::setupGUI()
6767
else
6868
ui->textBrowserLogs->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
6969

70-
// highlighter = new Highlighter(ui->textBrowserLogs->document());
70+
// highlighter = new Highlighter(ui->textBrowserLogs->document());
7171
}
7272

7373
// ui->comboBoxBaudRates
@@ -80,7 +80,6 @@ void MainWindow::setupGUI()
8080

8181
connect(ui->comboBoxSend->lineEdit(), SIGNAL(returnPressed()), this, SLOT(on_comboBoxSendReturnPressedSlot()));
8282

83-
8483
ui->comboBoxTracerStyle->addItem("Crosshair");
8584
ui->comboBoxTracerStyle->addItem("Circle");
8685
ui->comboBoxTracerStyle->setCurrentIndex(0);
@@ -134,7 +133,7 @@ void MainWindow::setupGUI()
134133

135134
if (ui->checkBoxAutoRefresh->isChecked())
136135
{
137-
serialDeviceCheckTimer->start(500);
136+
serialDeviceCheckTimer->start(SERIAL_DEVICE_CHECK_TIMER_INTERVAL);
138137
ui->pushButtonRefresh->setEnabled(false);
139138
}
140139
else
@@ -253,7 +252,7 @@ void MainWindow::settingsLoadAll()
253252
}
254253

255254
if (appSettings.value("Info/organizationName").value<QString>() != appSettings.organizationName() ||
256-
appSettings.value("Info/applicationName").value<QString>() != appSettings.applicationName())
255+
appSettings.value("Info/applicationName").value<QString>() != appSettings.applicationName())
257256
{
258257
qDebug() << "Abort loading settings ! organizationName or applicationName incorrect. Config file might be missing.";
259258
addLog("App >>\t Error loading settings. Config file incorrect !");
@@ -781,9 +780,9 @@ void MainWindow::on_tracerShowPointValue(QMouseEvent *event)
781780
"<td>Y: %L3</td>"
782781
"</tr>"
783782
"</table>")
784-
.arg(graph->name())
785-
.arg(QTime::fromMSecsSinceStartOfDay(temp.x() * 1000).toString("hh:mm:ss:zzz"))
786-
.arg(QString::number(temp.y(), 'f', 5)),
783+
.arg(graph->name())
784+
.arg(QTime::fromMSecsSinceStartOfDay(temp.x() * 1000).toString("hh:mm:ss:zzz"))
785+
.arg(QString::number(temp.y(), 'f', 5)),
787786
ui->widgetChart, ui->widgetChart->rect());
788787
}
789788

@@ -821,14 +820,12 @@ void MainWindow::on_chartMouseMoveHandler(QMouseEvent *event)
821820

822821
void MainWindow::on_updateSerialDeviceList()
823822
{
824-
QList<QSerialPortInfo> devices = QSerialPortInfo::availablePorts();
823+
QList<QSerialPortInfo> devices = serial.getAvailiblePorts();
825824
QList<QString> portNames;
826825
static QList<QString> portNamesOld;
827826

828827
foreach (auto item, devices)
829-
{
830828
portNames.append(item.portName());
831-
}
832829

833830
if ((devices.count() >= 1) && (!(portNames.toSet().intersects(portNamesOld.toSet())) || (portNames.count() != portNamesOld.count())))
834831
{
@@ -848,7 +845,7 @@ void MainWindow::on_updateSerialDeviceList()
848845

849846
portNamesOld = portNames;
850847

851-
this->radioButtonTimer->start(100);
848+
this->radioButtonTimer->start(RADIO_BUTTON_UPDATE_SERIAL_DEVICES_ON_INTERVAL);
852849
ui->radioButtonDeviceUpdate->setChecked(true);
853850
}
854851

@@ -1020,7 +1017,7 @@ void MainWindow::sendUDPDatagram(QString message)
10201017
networkUDP.write(message, QHostAddress(ui->lineEditUDPTargetIP->text()), ui->spinBoxUDPTargetPort->value());
10211018
}
10221019

1023-
// addLog("UDP >>\t" + message);
1020+
// addLog("UDP >>\t" + message);
10241021
}
10251022

10261023
void MainWindow::processChart(QStringList labelList, QList<double> numericDataList, QList<long> timeStampsList)
@@ -1046,9 +1043,9 @@ void MainWindow::processChart(QStringList labelList, QList<double> numericDataLi
10461043
}
10471044

10481045
if (canAddGraph && ui->widgetChart->graphCount() < ui->spinBoxMaxGraphs->value() &&
1049-
((ui->comboBoxGraphDisplayMode->currentIndex() == 0) ||
1050-
(ui->comboBoxGraphDisplayMode->currentIndex() == 1 &&
1051-
ui->lineEditCustomParsingRules->text().simplified().contains(label, Qt::CaseSensitivity::CaseSensitive))))
1046+
((ui->comboBoxGraphDisplayMode->currentIndex() == 0) ||
1047+
(ui->comboBoxGraphDisplayMode->currentIndex() == 1 &&
1048+
ui->lineEditCustomParsingRules->text().simplified().contains(label, Qt::CaseSensitivity::CaseSensitive))))
10521049
{
10531050
ui->widgetChart->addGraph();
10541051
ui->widgetChart->graph()->setName(label);
@@ -1294,7 +1291,7 @@ void MainWindow::on_checkBoxAutoRefresh_toggled(bool checked)
12941291
if (checked == true)
12951292
{
12961293
ui->pushButtonRefresh->setEnabled(false);
1297-
serialDeviceCheckTimer->start(500);
1294+
serialDeviceCheckTimer->start(SERIAL_DEVICE_CHECK_TIMER_INTERVAL);
12981295
}
12991296
else
13001297
{
@@ -1554,9 +1551,7 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
15541551
return;
15551552
}
15561553

1557-
// clearGraphData(true);
1558-
1559-
QString parsedPortName = ui->comboBoxDevices->currentText().mid(ui->comboBoxDevices->currentText().indexOf("COM"), ui->comboBoxDevices->currentText().indexOf(")") - 1);
1554+
QString parsedPortName = QSerialPortInfo::availablePorts().at(ui->comboBoxDevices->currentIndex()).portName();
15601555
qint32 parsedBaudRate = ui->comboBoxBaudRates->currentText().toInt();
15611556
QString dataBits = ui->comboBoxDataBits->currentText();
15621557
QString stopBits = ui->comboBoxStopBits->currentText();

src/serial.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ bool Serial::isOpen()
179179
return serialDevice->isOpen();
180180
}
181181

182+
QList<QSerialPortInfo> Serial::getAvailiblePorts()
183+
{
184+
return QSerialPortInfo::availablePorts();
185+
}
186+
182187
int Serial::getAvailiblePortsCount()
183188
{
184189
return QSerialPortInfo::availablePorts().count();

src/serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Serial : public QObject
2727
bool send(QString message);
2828
bool setReadMode(int mode);
2929
int getAvailiblePortsCount();
30+
QList<QSerialPortInfo> getAvailiblePorts();
3031
QString getSerialInfo();
3132
QString getString(bool clearBuffer = true);
3233
void clearAll(bool clearHardwareBuffers = false);

0 commit comments

Comments
 (0)