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 Oct 24, 2024
2 parents e3671bf + 82b0021 commit 9bc6e09
Show file tree
Hide file tree
Showing 37 changed files with 1,054 additions and 422 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Open ModScan
Open ModScan is a free implimentation of modbus master (client) utility for modbus-tcp and modbus-rtu protocols.

![image](https://github.com/sanny32/OpenModScan/assets/13627951/c2df0ea1-0f27-4d4b-8cc0-b6268caf8f11)
![image](https://github.com/user-attachments/assets/71563b34-3d85-404b-9d36-03ad5da76684)


![image](https://github.com/user-attachments/assets/aeae5869-b0a1-469f-9e30-3e68a85b23e1)
![image](https://github.com/user-attachments/assets/1a7f45f9-66a8-4591-975f-4ea3b623ac31)



Expand All @@ -27,20 +27,19 @@ Registers
0x10 - Write Multiple Registers
0x16 - Mask Write Register

Modbus Logging

![image](https://github.com/sanny32/OpenModScan/assets/13627951/69de27f0-b09b-4587-8493-6d1908610735)
## Modbus Logging

![image](https://github.com/user-attachments/assets/1cc38a65-7631-4122-b975-6a01781131e4)


## Extended Featues
- Modbus Address Scan

![image](https://github.com/sanny32/OpenModScan/assets/13627951/8989fbde-09f1-435c-a9a7-31e27a0ec576)
![image](https://github.com/user-attachments/assets/dfbe062f-d696-4e38-a75f-d5d53182df58)

- Modbus Scanner (supports both Modbus RTU and Modbus TCP scanning)

![image](https://github.com/sanny32/OpenModScan/assets/13627951/cd35c0c4-ca9c-41fe-872c-1c2bb2286fc7)
![image](https://github.com/user-attachments/assets/17d5f43d-c341-455d-a9b8-67db50a35699)

- Modbus Message Parser

Expand Down
76 changes: 76 additions & 0 deletions omodscan/controls/addressbasecombobox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <QEvent>
#include "addressbasecombobox.h"

///
/// \brief AddressBaseComboBox::AddressBaseComboBox
/// \param parent
///
AddressBaseComboBox::AddressBaseComboBox(QWidget* parent)
: QComboBox(parent)
{
addItem(tr("0-based"), QVariant::fromValue(AddressBase::Base0));
addItem(tr("1-based"), QVariant::fromValue(AddressBase::Base1));

connect(this, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &AddressBaseComboBox::on_currentIndexChanged);
}

///
/// \brief AddressBaseComboBox::changeEvent
/// \param event
///
void AddressBaseComboBox::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
{
for(int i = 0; i < count(); i++)
{
switch(itemData(i).value<AddressBase>())
{
case AddressBase::Base0:
setItemText(i, tr("0-based"));
break;

case AddressBase::Base1:
setItemText(i, tr("1-based"));
break;
}
}
}

QComboBox::changeEvent(event);
}

///
/// \brief AddressBaseComboBox::currentAddressBase
/// \return
///
AddressBase AddressBaseComboBox::currentAddressBase() const
{
return currentData().value<AddressBase>();
}

///
/// \brief AddressBaseComboBox::setCurrentAddressBase
/// \param pointType
///
void AddressBaseComboBox::setCurrentAddressBase(AddressBase base)
{
const auto idx = findData(QVariant::fromValue(base));
if(idx == currentIndex())
{
emit currentIndexChanged(idx);
}
else if(idx != -1)
{
setCurrentIndex(idx);
}
}

///
/// \brief AddressBaseComboBox::on_currentIndexChanged
/// \param index
///
void AddressBaseComboBox::on_currentIndexChanged(int index)
{
emit addressBaseChanged(itemData(index).value<AddressBase>());
}
29 changes: 29 additions & 0 deletions omodscan/controls/addressbasecombobox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef ADDRESSBASECOMBOBOX_H
#define ADDRESSBASECOMBOBOX_H

#include <QComboBox>
#include "enums.h"

///
/// \brief The AddressBaseComboBox class
///
class AddressBaseComboBox : public QComboBox
{
Q_OBJECT
public:
explicit AddressBaseComboBox(QWidget *parent = nullptr);

AddressBase currentAddressBase() const;
void setCurrentAddressBase(AddressBase base);

signals:
void addressBaseChanged(AddressBase base);

protected:
void changeEvent(QEvent* event) override;

private slots:
void on_currentIndexChanged(int);
};

#endif // ADDRESSBASECOMBOBOX_H
7 changes: 4 additions & 3 deletions omodscan/controls/outputwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ QModelIndex OutputListModel::find(QModbusDataUnit::RegisterType type, quint16 ad
if(_parentWidget->_displayDefinition.PointType != type)
return QModelIndex();

const int row = addr - _parentWidget->_displayDefinition.PointAddress;
const auto dd = _parentWidget->_displayDefinition;
const int row = addr - (dd.PointAddress - (dd.ZeroBasedAddress ? 0 : 1));
if(row >= 0 && row < rowCount())
return index(row);

Expand Down Expand Up @@ -653,8 +654,8 @@ AddressDescriptionMap OutputWidget::descriptionMap() const
for(int i = 0; i < _listModel->rowCount(); i++)
{
const auto desc = _listModel->data(_listModel->index(i), DescriptionRole).toString();
const quint16 addr = _listModel->data(_listModel->index(i), AddressRole).toUInt();
descriptionMap[{_displayDefinition.PointType, addr}] = desc;
const quint16 addr = _listModel->data(_listModel->index(i), AddressRole).toUInt() - (_displayDefinition.ZeroBasedAddress ? 0 : 1);
descriptionMap[{_displayDefinition.PointType, addr }] = desc;
}
return descriptionMap;
}
Expand Down
5 changes: 3 additions & 2 deletions omodscan/controls/outputwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class OutputWidget : public QWidget
int logViewLimit() const;
void setLogViewLimit(int l);

void clearLogView();

void setStatus(const QString& status);

void paint(const QRect& rc, QPainter& painter);
Expand All @@ -126,6 +124,9 @@ class OutputWidget : public QWidget

void setSimulated(QModbusDataUnit::RegisterType type, quint16 addr, bool on);

public slots:
void clearLogView();

signals:
void itemDoubleClicked(quint16 address, const QVariant& value);

Expand Down
1 change: 1 addition & 0 deletions omodscan/controls/statisticwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void StatisticWidget::resetCtrs()
void StatisticWidget::on_pushButtonResetCtrs_clicked()
{
resetCtrs();
emit ctrsReseted();
}

///
Expand Down
1 change: 1 addition & 0 deletions omodscan/controls/statisticwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class StatisticWidget : public QWidget
signals:
void numberOfPollsChanged(uint value);
void validSlaveResposesChanged(uint value);
void ctrsReseted();

protected:
void changeEvent(QEvent* event) override;
Expand Down
4 changes: 2 additions & 2 deletions omodscan/controls/statisticwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>6</height>
<height>40</height>
</size>
</property>
</spacer>
Expand Down
2 changes: 1 addition & 1 deletion omodscan/datasimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void DataSimulator::startSimulation(DataDisplayMode mode, QModbusDataUnit::Regis
break;
}

_simulationMap[{ type, addr, deviceId}] = { mode, params, value };
_simulationMap.insert({ type, addr, deviceId}, { mode, params, value });
resumeSimulations();

emit simulationStarted(type, addr, deviceId);
Expand Down
3 changes: 2 additions & 1 deletion omodscan/datasimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private slots:
quint16 Address;
quint8 DeviceId;
bool operator<(const SimulationKey& key) const{
return Type < key.Type && Address < key.Address && DeviceId < key.DeviceId;
return Type < key.Type || (!(Type < key.Type) && (Address < key.Address)) ||
(!(Type < key.Type) && !(Address < key.Address) && (DeviceId < key.DeviceId));
}
};

Expand Down
Loading

0 comments on commit 9bc6e09

Please sign in to comment.