Skip to content

Commit 432e61c

Browse files
committed
Implement error recurrence
1 parent f4a9438 commit 432e61c

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/mainwindow.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,27 @@ MainWindow::MainWindow(QWidget *parent) :
3636
_exceptionGroup.addButton(_pUi->chkTargetNoResponse, QModbusPdu::GatewayTargetDeviceFailedToRespond);
3737
_exceptionGroup.addButton(_pUi->chkGatewayPathUnavailable, QModbusPdu::GatewayPathUnavailable);
3838

39-
connect(&_exceptionGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
39+
connect(&_exceptionGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),
40+
[=](int id, bool checked){
41+
if (checked)
42+
{
43+
_pSlaveModbus->setException(static_cast<QModbusPdu::ExceptionCode>(id));
44+
}
45+
});
46+
47+
/** Handle error recurrence group **/
48+
_bErrorOnce = true;
49+
_errorRecurrenceGroup.addButton(_pUi->optErrorOnce, true);
50+
_errorRecurrenceGroup.addButton(_pUi->optErrorPersistent, false);
51+
52+
connect(&_errorRecurrenceGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
4053
[=](int id){
41-
_pSlaveModbus->setException(static_cast<QModbusPdu::ExceptionCode>(id));
54+
_bErrorOnce = static_cast<bool>(id);
4255
});
4356

44-
/*** Auto increment ***/
57+
connect(_pSlaveModbus, &TestSlaveModbus::requestProcessed, this, &MainWindow::handleRequestProcessed);
58+
59+
/** Auto increment **/
4560
connect(&_autoIncTimer, &QTimer::timeout, this, &MainWindow::handleAutoIncTick);
4661
_autoIncTimer.start(1000);
4762
_bAutoInc = false;
@@ -50,7 +65,7 @@ MainWindow::MainWindow(QWidget *parent) :
5065
_bAutoInc = (state == Qt::Checked);
5166
});
5267

53-
/*** Setup registerView **/
68+
/** Setup registerView **/
5469
_pUi->tblRegData->setModel(_pRegisterDataModel);
5570
_pUi->tblRegData->verticalHeader()->show();
5671
_pUi->tblRegData->horizontalHeader()->show(); // Not sure yet (show or not to show?)
@@ -126,3 +141,11 @@ void MainWindow::handleAutoIncTick()
126141
_pSlaveData->incrementAllEnabledRegisters();
127142
}
128143
}
144+
145+
void MainWindow::handleRequestProcessed()
146+
{
147+
if (_bErrorOnce)
148+
{
149+
_pUi->chkNone->animateClick(Qt::Checked);
150+
}
151+
}

src/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private slots:
3131
void onStateChanged(QModbusDevice::State state);
3232

3333
void handleAutoIncTick();
34+
void handleRequestProcessed();
3435

3536
private:
3637

@@ -39,7 +40,10 @@ private slots:
3940
QTimer _autoIncTimer;
4041
bool _bAutoInc;
4142

43+
bool _bErrorOnce;
44+
4245
QButtonGroup _exceptionGroup;
46+
QButtonGroup _errorRecurrenceGroup;
4347

4448
TestSlaveModbus *_pSlaveModbus;
4549
TestSlaveData *_pSlaveData;

src/mainwindow.ui

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>700</width>
10-
<height>584</height>
10+
<height>628</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -33,6 +33,9 @@
3333
<property name="text">
3434
<string>Once</string>
3535
</property>
36+
<property name="checked">
37+
<bool>true</bool>
38+
</property>
3639
</widget>
3740
</item>
3841
<item>
@@ -86,6 +89,9 @@
8689
<property name="text">
8790
<string>None</string>
8891
</property>
92+
<property name="checked">
93+
<bool>true</bool>
94+
</property>
8995
</widget>
9096
</item>
9197
<item row="0" column="0">

0 commit comments

Comments
 (0)