Skip to content

Commit 9a8e4a2

Browse files
author
Ананьев Александр
committed
Merge remote-tracking branch 'origin/dev'
2 parents 7ab18db + 1fe9723 commit 9a8e4a2

75 files changed

Lines changed: 7077 additions & 797 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ qrc_*.cpp
2828
ui_*.h
2929
*.qmlc
3030
*.jsc
31+
*.qch
32+
*.qhc
3133
Makefile*
3234
*build-*
3335
debug

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Open ModSim
22
Open ModSim is a free implimentation of modbus slave (server) utility for modbus-tcp and modbus-rtu protocols.
33

4-
![image](https://user-images.githubusercontent.com/13627951/217724115-6281e1dc-9f62-4b83-a945-156ee190b8c6.png)
4+
![image](https://user-images.githubusercontent.com/13627951/230102997-d6578945-bac0-4ca4-9210-da80e4f8783c.png)
5+
6+
![image](https://user-images.githubusercontent.com/13627951/230103505-f446cf6d-a925-4a51-bbde-8bb77d3da5b1.png)
57

6-
![image](https://user-images.githubusercontent.com/13627951/217725531-81d2994c-d40c-474b-90bc-6f40695a6daa.png)
78

89

910
## Features
@@ -37,6 +38,55 @@ Registers
3738
Random - simulate register randomly
3839
Increment - simulate register from Low Limit to High Limit with a given Step
3940
Decrement - simulate register from High Limit to Low Limit with a given Step
41+
42+
## Scripting
43+
From version 1.2.0 Open ModSim supports scripting. Qt runtime implements the [ECMAScript Language Specification](http://www.ecma-international.org/publications/standards/Ecma-262.htm) standard, so Javascript is used to write code.
44+
45+
![image](https://user-images.githubusercontent.com/13627951/230098131-55b4ef69-e01f-459f-a6d4-11f755978bcb.png)
46+
47+
Scripts can be launched in two modes: Once or Periodically. If you run script in Once mode the script will stop after it finishes executing. In Periodically mode, the script will start after a certain period of time until the user stops it or the method is called
48+
```javascript
49+
Script.stop();
50+
```
51+
Here is an example of using the script in the Periodically mode
52+
```javascript
53+
/**************************************************************************/
54+
/*
55+
/* Example script that store value after 3 seconds
56+
/*
57+
***************************************************************************/
58+
59+
function clear()
60+
{
61+
/* Write to a Holding register at address 1 zero value */
62+
Server.writeHolding(1, 0);
63+
}
64+
65+
/* init function */
66+
function init()
67+
{
68+
clear();
69+
70+
/* Runs when Hodling register value at address 1 was changed */
71+
Server.onChange(Register.Holding, 1, (value)=>
72+
{
73+
if(value === 1)
74+
{
75+
/* Runs after 3 seconds and increase Holding register value at address 10
76+
* Then stop script execution
77+
*/
78+
Script.setTimeout(function()
79+
{
80+
Server.writeHolding(10, Server.readHolding(10) + 1);
81+
Script.stop();
82+
}, 3000);
83+
}
84+
});
85+
}
86+
87+
/* Runs once when script started */
88+
Script.onInit(init);
89+
```
4090

4191
## Building
4292
Now building is available with Qt/qmake (version 5.15 and above) or Qt Creator. Supports both OS Microsoft Windows and Linux.

omodsim/controls/consoleoutput.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <QMenu>
2+
#include "consoleoutput.h"
3+
4+
///
5+
/// \brief ConsoleOutput::ConsoleOutput
6+
/// \param parent
7+
///
8+
ConsoleOutput::ConsoleOutput(QWidget* parent)
9+
: QPlainTextEdit(parent)
10+
{
11+
setReadOnly(true);
12+
setUndoRedoEnabled(false);
13+
}
14+
15+
///
16+
/// \brief ConsoleOutput::contextMenuEvent
17+
/// \param event
18+
///
19+
void ConsoleOutput::contextMenuEvent(QContextMenuEvent* event)
20+
{
21+
auto menu = new QMenu(this);
22+
auto action = menu->addAction(tr("Clear"), this, [this]()
23+
{
24+
setPlainText(QString());
25+
});
26+
action->setEnabled(!toPlainText().isEmpty());
27+
menu->exec(event->globalPos());
28+
delete menu;
29+
}

omodsim/controls/consoleoutput.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef CONSOLEOUTPUT_H
2+
#define CONSOLEOUTPUT_H
3+
4+
#include <QPlainTextEdit>
5+
6+
///
7+
/// \brief The ConsoleOutput class
8+
///
9+
class ConsoleOutput : public QPlainTextEdit
10+
{
11+
Q_OBJECT
12+
public:
13+
explicit ConsoleOutput(QWidget* parent = nullptr);
14+
15+
protected:
16+
void contextMenuEvent(QContextMenuEvent* event);
17+
};
18+
19+
#endif // CONSOLEOUTPUT_H

omodsim/controls/helpwidget.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <QEvent>
2+
#include <QHelpContentWidget>
3+
#include "helpwidget.h"
4+
5+
///
6+
/// \brief HelpWidget::HelpWidget
7+
/// \param parent
8+
///
9+
HelpWidget::HelpWidget(QWidget *parent)
10+
: QTextBrowser(parent)
11+
,_helpEngine(nullptr)
12+
{
13+
}
14+
15+
///
16+
/// \brief HelpWidget::~HelpWidget
17+
///
18+
HelpWidget::~HelpWidget()
19+
{
20+
}
21+
22+
///
23+
/// \brief SearchLineEdit::changeEvent
24+
/// \param event
25+
///
26+
void HelpWidget::changeEvent(QEvent* event)
27+
{
28+
if (event->type() == QEvent::LanguageChange)
29+
{
30+
setSource(QUrl(tr("qthelp://omodsim/doc/index.html")));
31+
}
32+
33+
QTextBrowser::changeEvent(event);
34+
}
35+
36+
///
37+
/// \brief HelpWidget::loadResource
38+
/// \param type
39+
/// \param name
40+
/// \return
41+
///
42+
QVariant HelpWidget::loadResource (int type, const QUrl& name)
43+
{
44+
if (name.scheme() == "qthelp" && _helpEngine)
45+
return QVariant(_helpEngine->fileData(name));
46+
else
47+
return QTextBrowser::loadResource(type, name);
48+
}
49+
50+
///
51+
/// \brief HelpWidget::setHelp
52+
/// \param helpFile
53+
///
54+
void HelpWidget::setHelp(const QString& helpFile)
55+
{
56+
_helpEngine = QSharedPointer<QHelpEngine>(new QHelpEngine(helpFile, this));
57+
_helpEngine->setupData();
58+
59+
setSource(QUrl(tr("qthelp://omodsim/doc/index.html")));
60+
}
61+
62+
///
63+
/// \brief HelpWidget::showHelp
64+
/// \param helpKey
65+
///
66+
void HelpWidget::showHelp(const QString& helpKey)
67+
{
68+
const auto url = QString(tr("qthelp://omodsim/doc/index.html#%1")).arg(helpKey.toLower());
69+
setSource(QUrl(url));
70+
}

omodsim/controls/helpwidget.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef HELPWIDGET_H
2+
#define HELPWIDGET_H
3+
4+
#include <QHelpEngine>
5+
#include <QTextBrowser>
6+
7+
///
8+
/// \brief The HelpWidget class
9+
///
10+
class HelpWidget : public QTextBrowser
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit HelpWidget(QWidget *parent = nullptr);
16+
~HelpWidget();
17+
18+
void setHelp(const QString& helpFile);
19+
QVariant loadResource (int type, const QUrl& name) override;
20+
21+
void showHelp(const QString& helpKey);
22+
23+
protected:
24+
void changeEvent(QEvent* event) override;
25+
26+
private:
27+
QSharedPointer<QHelpEngine> _helpEngine;
28+
};
29+
30+
#endif // HELPWIDGET_H

0 commit comments

Comments
 (0)