Skip to content

Commit 3e20c3b

Browse files
committed
Added script modules support
1 parent 5581dcb commit 3e20c3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1889
-211
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13) # 2.2 - case insensitive syntax
22
# 3.13 included policy CMP0077
33

4-
project(ModbusTools VERSION 0.4.2 LANGUAGES CXX)
4+
project(ModbusTools VERSION 0.4.3 LANGUAGES CXX)
55

66
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
77
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,9 @@ List of changes of new v0.4 version of ModbusTools:
144144
* Added device byte and register order settings support for scripting
145145
* Added get/set string functions for working with strings for scripting
146146
* Improved default project for client and server
147+
148+
# 0.4.3
149+
150+
* Fixed TCP Server delay while connecting (within ModbusLib subproject)
151+
* Added setting 'Max Connections' for max simultanious TCP server connections
152+

src/client/win_resource.rc

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
IDI_ICON1 ICON DISCARDABLE "gui\\icons\\client.ico"
44

55
VS_VERSION_INFO VERSIONINFO
6-
FILEVERSION 0,4,2,0
7-
PRODUCTVERSION 0,4,2,0
6+
FILEVERSION 0,4,3,0
7+
PRODUCTVERSION 0,4,3,0
88
FILEFLAGSMASK 0x3fL
99
#ifdef _DEBUG
1010
FILEFLAGS VS_FF_DEBUG
@@ -21,11 +21,11 @@ VS_VERSION_INFO VERSIONINFO
2121
BEGIN
2222
VALUE "CompanyName", "\0"
2323
VALUE "FileDescription", "\0"
24-
VALUE "FileVersion", "0.4.2.0\0"
24+
VALUE "FileVersion", "0.4.3.0\0"
2525
VALUE "LegalCopyright", "\0"
2626
VALUE "OriginalFilename", "client.exe\0"
2727
VALUE "ProductName", "client\0"
28-
VALUE "ProductVersion", "0.4.2.0\0"
28+
VALUE "ProductVersion", "0.4.3.0\0"
2929
END
3030
END
3131
BLOCK "VarFileInfo"

src/core/sdk/mbcore_config.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#ifndef MBCORE_CONFIG_H
2-
#define MBCORE_CONFIG_H
3-
4-
/*
5-
Major part of mbtools version
6-
*/
7-
#define MBTOOLS_VERSION_MAJOR 0
8-
9-
/*
10-
Minor part of mbtools version
11-
*/
12-
#define MBTOOLS_VERSION_MINOR 4
13-
14-
/*
15-
Patch part of mbtools version
16-
*/
17-
#define MBTOOLS_VERSION_PATCH 2
18-
19-
#endif // MBCORE_CONFIG_H
1+
#ifndef MBCORE_CONFIG_H
2+
#define MBCORE_CONFIG_H
3+
4+
/*
5+
Major part of mbtools version
6+
*/
7+
#define MBTOOLS_VERSION_MAJOR 0
8+
9+
/*
10+
Minor part of mbtools version
11+
*/
12+
#define MBTOOLS_VERSION_MINOR 4
13+
14+
/*
15+
Patch part of mbtools version
16+
*/
17+
#define MBTOOLS_VERSION_PATCH 3
18+
19+
#endif // MBCORE_CONFIG_H

src/core/win_resource.rc

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
VS_VERSION_INFO VERSIONINFO
6-
FILEVERSION 0,4,2,0
7-
PRODUCTVERSION 0,4,2,0
6+
FILEVERSION 0,4,3,0
7+
PRODUCTVERSION 0,4,3,0
88
FILEFLAGSMASK 0x3fL
99
#ifdef _DEBUG
1010
FILEFLAGS VS_FF_DEBUG
@@ -21,11 +21,11 @@ VS_VERSION_INFO VERSIONINFO
2121
BEGIN
2222
VALUE "CompanyName", "\0"
2323
VALUE "FileDescription", "\0"
24-
VALUE "FileVersion", "0.4.2.0\0"
24+
VALUE "FileVersion", "0.4.3.0\0"
2525
VALUE "LegalCopyright", "\0"
2626
VALUE "OriginalFilename", "core.dll\0"
2727
VALUE "ProductName", "core\0"
28-
VALUE "ProductVersion", "0.4.2.0\0"
28+
VALUE "ProductVersion", "0.4.3.0\0"
2929
END
3030
END
3131
BLOCK "VarFileInfo"

src/server/CMakeLists.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(HEADERS
2020
core/server_global.h
2121
core/server.h
2222
${CMAKE_CURRENT_LIST_DIR}/project/server_simaction.h
23+
${CMAKE_CURRENT_LIST_DIR}/project/server_scriptmodule.h
2324
${CMAKE_CURRENT_LIST_DIR}/project/server_builder.h
2425
${CMAKE_CURRENT_LIST_DIR}/project/server_device.h
2526
${CMAKE_CURRENT_LIST_DIR}/project/server_deviceref.h
@@ -32,7 +33,8 @@ set(HEADERS
3233
gui/dialogs/settings/server_modelsettingsscripteditorcolors.h
3334
gui/dialogs/settings/server_modelsettingsscriptinterpreters.h
3435
gui/dialogs/settings/server_widgetsettingsscript.h
35-
gui/dialogs/server_dialogaction.h
36+
gui/dialogs/server_dialogsimaction.h
37+
gui/dialogs/server_dialogscriptmodule.h
3638
gui/dialogs/server_dialogdevice.h
3739
gui/dialogs/server_dialogport.h
3840
gui/dialogs/server_dialogs.h
@@ -51,8 +53,13 @@ set(HEADERS
5153
gui/simactions/server_simactionsdelegate.h
5254
gui/simactions/server_simactionsmodel.h
5355
gui/simactions/server_simactionsui.h
56+
gui/scriptmodules/server_scriptmodulesdelegate.h
57+
gui/scriptmodules/server_scriptmodulesmodel.h
58+
gui/scriptmodules/server_scriptmodulesui.h
5459
gui/script/editor/server_scripthighlighter.h
5560
gui/script/editor/server_scripteditor.h
61+
gui/script/server_basescripteditor.h
62+
gui/script/server_scriptmoduleeditor.h
5663
gui/script/server_devicescripteditor.h
5764
gui/script/server_scriptmanager.h
5865
gui/server_outputview.h
@@ -70,6 +77,7 @@ set(HEADERS
7077
set(SOURCES
7178
core/server.cpp
7279
${CMAKE_CURRENT_LIST_DIR}/project/server_simaction.cpp
80+
${CMAKE_CURRENT_LIST_DIR}/project/server_scriptmodule.cpp
7381
${CMAKE_CURRENT_LIST_DIR}/project/server_builder.cpp
7482
${CMAKE_CURRENT_LIST_DIR}/project/server_device.cpp
7583
${CMAKE_CURRENT_LIST_DIR}/project/server_deviceref.cpp
@@ -82,7 +90,8 @@ set(SOURCES
8290
gui/dialogs/settings/server_modelsettingsscripteditorcolors.cpp
8391
gui/dialogs/settings/server_modelsettingsscriptinterpreters.cpp
8492
gui/dialogs/settings/server_widgetsettingsscript.cpp
85-
gui/dialogs/server_dialogaction.cpp
93+
gui/dialogs/server_dialogsimaction.cpp
94+
gui/dialogs/server_dialogscriptmodule.cpp
8695
gui/dialogs/server_dialogdevice.cpp
8796
gui/dialogs/server_dialogport.cpp
8897
gui/dialogs/server_dialogs.cpp
@@ -101,8 +110,13 @@ set(SOURCES
101110
gui/simactions/server_simactionsdelegate.cpp
102111
gui/simactions/server_simactionsmodel.cpp
103112
gui/simactions/server_simactionsui.cpp
113+
gui/scriptmodules/server_scriptmodulesdelegate.cpp
114+
gui/scriptmodules/server_scriptmodulesmodel.cpp
115+
gui/scriptmodules/server_scriptmodulesui.cpp
104116
gui/script/editor/server_scripthighlighter.cpp
105117
gui/script/editor/server_scripteditor.cpp
118+
gui/script/server_basescripteditor.cpp
119+
gui/script/server_scriptmoduleeditor.cpp
106120
gui/script/server_devicescripteditor.cpp
107121
gui/script/server_scriptmanager.cpp
108122
gui/server_outputview.cpp

src/server/gui/dialogs/dialogs.pri

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
include(settings/settings.pri)
22

33
HEADERS += \
4-
$$PWD/server_dialogaction.h \
54
$$PWD/server_dialogdevice.h \
65
$$PWD/server_dialogport.h \
76
$$PWD/server_dialogs.h \
8-
$$PWD/server_dialogdataviewitem.h
7+
$$PWD/server_dialogdataviewitem.h \
8+
$$PWD/server_dialogsimaction.h \
9+
$$PWD/server_dialogscriptmodule.h
910
#$$PWD/server_dialogtask.h \
1011

1112
SOURCES += \
12-
$$PWD/server_dialogaction.cpp \
1313
$$PWD/server_dialogdevice.cpp \
1414
$$PWD/server_dialogport.cpp \
1515
$$PWD/server_dialogs.cpp \
16-
$$PWD/server_dialogdataviewitem.cpp
16+
$$PWD/server_dialogdataviewitem.cpp \
17+
$$PWD/server_dialogsimaction.cpp \
18+
$$PWD/server_dialogscriptmodule.cpp
1719
#$$PWD/server_dialogtask.cpp \
1820

1921
FORMS += \
20-
$$PWD/server_dialogaction.ui \
2122
$$PWD/server_dialogdevice.ui \
2223
$$PWD/server_dialogport.ui \
23-
$$PWD/server_dialogdataviewitem.ui
24+
$$PWD/server_dialogdataviewitem.ui \
25+
$$PWD/server_dialogsimaction.ui \
26+
$$PWD/server_dialogscriptmodule.ui
2427
#$$PWD/server_dialogtask.ui \

src/server/gui/dialogs/server_dialogs.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#include "server_dialogport.h"
3131
#include "server_dialogdevice.h"
3232
#include "server_dialogdataviewitem.h"
33-
#include "server_dialogaction.h"
33+
#include "server_dialogsimaction.h"
34+
#include "server_dialogscriptmodule.h".h"
3435
3536
mbServerDialogs::mbServerDialogs(QWidget *parent) : mbCoreDialogs (parent)
3637
{
@@ -39,7 +40,8 @@ mbServerDialogs::mbServerDialogs(QWidget *parent) : mbCoreDialogs (parent)
3940
m_port = new mbServerDialogPort(parent);
4041
m_device = new mbServerDialogDevice(parent);
4142
m_dataViewItem = new mbServerDialogDataViewItem(parent);
42-
m_action = new mbServerDialogAction(parent);
43+
m_simaction = new mbServerDialogSimAction(parent);
44+
m_scriptModule = new mbServerDialogScriptModule(parent);
4345
4446
m_projectInfo->setProjectType(QStringLiteral("Server Project"));
4547
}
@@ -51,17 +53,24 @@ mbServerDialogs::~mbServerDialogs()
5153
MBSETTINGS mbServerDialogs::cachedSettings() const
5254
{
5355
MBSETTINGS m = mbCoreDialogs::cachedSettings();
54-
mb::unite(m, m_action->cachedSettings());
56+
mb::unite(m, m_simaction->cachedSettings());
57+
mb::unite(m, m_scriptModule->cachedSettings());
5558
return m;
5659
}
5760
5861
void mbServerDialogs::setCachedSettings(const MBSETTINGS &settings)
5962
{
6063
mbCoreDialogs::setCachedSettings(settings);
61-
m_action->setCachedSettings(settings);
64+
m_simaction->setCachedSettings(settings);
65+
m_scriptModule->setCachedSettings(settings);
6266
}
6367
64-
MBSETTINGS mbServerDialogs::getAction(const MBSETTINGS &settings, const QString &title)
68+
MBSETTINGS mbServerDialogs::getSimAction(const MBSETTINGS &settings, const QString &title)
6569
{
66-
return m_action->getSettings(settings, title);
70+
return m_simaction->getSettings(settings, title);
71+
}
72+
73+
MBSETTINGS mbServerDialogs::getScriptModule(const MBSETTINGS &settings, const QString &title)
74+
{
75+
return m_scriptModule->getSettings(settings, title);
6776
}

src/server/gui/dialogs/server_dialogs.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class mbServerDialogPort;
3232
class mbServerDialogDevice;
3333
class mbServerDialogDataView;
3434
class mbServerDialogDataViewItem;
35-
class mbServerDialogAction;
35+
class mbServerDialogSimAction;
36+
class mbServerDialogScriptModule;
3637

3738
class mbServerDialogs : public mbCoreDialogs
3839
{
@@ -45,10 +46,12 @@ class mbServerDialogs : public mbCoreDialogs
4546
void setCachedSettings(const MBSETTINGS &settings) override;
4647

4748
public:
48-
MBSETTINGS getAction(const MBSETTINGS &settings, const QString &title = QString());
49+
MBSETTINGS getSimAction(const MBSETTINGS &settings, const QString &title = QString());
50+
MBSETTINGS getScriptModule(const MBSETTINGS &settings, const QString &title = QString());
4951

5052
private:
51-
mbServerDialogAction *m_action;
53+
mbServerDialogSimAction *m_simaction;
54+
mbServerDialogScriptModule *m_scriptModule;
5255
};
5356

5457
#endif // SERVER_DIALOGS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
Modbus Tools
3+
4+
Created: 2023
5+
Author: Serhii Marchuk, https://github.com/serhmarch
6+
7+
Copyright (C) 2023 Serhii Marchuk
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
*/
23+
#include "server_dialogscriptmodule.h"
24+
#include "ui_server_dialogscriptmodule.h"
25+
26+
#include <core.h>
27+
#include <project/server_scriptmodule.h>
28+
29+
mbServerDialogScriptModule::Strings::Strings() : mbCoreDialogEdit::Strings(),
30+
title(QStringLiteral("Script Module")),
31+
cachePrefix(QStringLiteral("Ui.Dialogs.ScriptModule."))
32+
{
33+
}
34+
35+
const mbServerDialogScriptModule::Strings &mbServerDialogScriptModule::Strings::instance()
36+
{
37+
static const mbServerDialogScriptModule::Strings s;
38+
return s;
39+
}
40+
41+
mbServerDialogScriptModule::mbServerDialogScriptModule(QWidget *parent) :
42+
mbCoreDialogEdit(Strings::instance().cachePrefix, parent),
43+
ui(new Ui::mbServerDialogScriptModule)
44+
{
45+
ui->setupUi(this);
46+
47+
// ----------------------------------------------------------------------------------
48+
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
49+
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
50+
}
51+
52+
mbServerDialogScriptModule::~mbServerDialogScriptModule()
53+
{
54+
delete ui;
55+
}
56+
57+
MBSETTINGS mbServerDialogScriptModule::cachedSettings() const
58+
{
59+
const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance();
60+
const Strings &ds = Strings::instance();
61+
const QString &prefix = ds.cachePrefix;
62+
63+
MBSETTINGS m = mbCoreDialogEdit::cachedSettings();
64+
m[prefix+vs.name ] = ui->lnName ->text();
65+
m[prefix+vs.comment ] = ui->txtComment->toPlainText();
66+
return m;
67+
}
68+
69+
void mbServerDialogScriptModule::setCachedSettings(const MBSETTINGS &m)
70+
{
71+
mbCoreDialogEdit::setCachedSettings(m);
72+
73+
const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance();
74+
const Strings &ds = Strings::instance();
75+
const QString &prefix = ds.cachePrefix;
76+
77+
MBSETTINGS::const_iterator it;
78+
MBSETTINGS::const_iterator end = m.end();
79+
80+
it = m.find(prefix+vs.name ); if (it != end) ui->lnName ->setText (it.value().toString());
81+
it = m.find(prefix+vs.comment); if (it != end) ui->txtComment->setPlainText(it.value().toString());
82+
}
83+
84+
MBSETTINGS mbServerDialogScriptModule::getSettings(const MBSETTINGS &settings, const QString &title)
85+
{
86+
MBSETTINGS r;
87+
88+
if (title.isEmpty())
89+
setWindowTitle(Strings::instance().title);
90+
else
91+
setWindowTitle(title);
92+
if (settings.count())
93+
fillForm(settings);
94+
switch (QDialog::exec())
95+
{
96+
case QDialog::Accepted:
97+
fillData(r);
98+
}
99+
return r;
100+
}
101+
102+
void mbServerDialogScriptModule::fillForm(const MBSETTINGS &m)
103+
{
104+
const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance();
105+
106+
MBSETTINGS::const_iterator it;
107+
MBSETTINGS::const_iterator end = m.end();
108+
109+
it = m.find(vs.name ); if (it != end) ui->lnName ->setText (it.value().toString());
110+
it = m.find(vs.comment); if (it != end) ui->txtComment->setPlainText(it.value().toString());
111+
}
112+
113+
void mbServerDialogScriptModule::fillData(MBSETTINGS &settings)
114+
{
115+
const mbServerScriptModule::Strings &s = mbServerScriptModule::Strings::instance();
116+
117+
settings[s.name ] = ui->lnName ->text();
118+
settings[s.comment] = ui->txtComment->toPlainText();
119+
}

0 commit comments

Comments
 (0)