Skip to content

Commit c7d5f59

Browse files
committed
update datastore simulator.
1 parent 59c06b7 commit c7d5f59

File tree

11 files changed

+191
-102
lines changed

11 files changed

+191
-102
lines changed

examples/server_simulator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@
8080
{"addr": [19, 20], "value": 14661, "action": "increment"},
8181
],
8282
"uint32": [
83-
{"addr": 21, "value": 3124},
84-
{"addr": [23, 25], "value": 5678},
85-
{"addr": [27, 29], "value": 345000, "action": "increment"},
83+
{"addr": [21, 22], "value": 3124},
84+
{"addr": [23, 26], "value": 5678},
85+
{"addr": [27, 30], "value": 345000, "action": "increment"},
8686
],
8787
"float32": [
88-
{"addr": 31, "value": 3124.17},
89-
{"addr": [33, 35], "value": 5678.19},
90-
{"addr": [37, 39], "value": 345000.18, "action": "increment"},
88+
{"addr": [31, 32], "value": 3124.17},
89+
{"addr": [33, 36], "value": 5678.19},
90+
{"addr": [37, 40], "value": 345000.18, "action": "increment"},
9191
],
9292
"string": [
9393
{"addr": [41, 42], "value": "Str"},
94-
{"addr": [43, 44], "value": "Strxyz"},
94+
{"addr": [43, 44], "value": "Strx"},
9595
],
9696
"repeat": [{"addr": [0, 45], "to": [46, 138]}],
9797
}

pymodbus/server/reactive/default_config.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"tcp": {
33
"handler": "ModbusConnectedRequestHandler",
44
"allow_reuse_address": true,
5-
"allow_reuse_port": true,
65
"backlog": 20,
76
"ignore_missing_slaves": false
87
},
@@ -21,7 +20,6 @@
2120
"certfile": null,
2221
"keyfile": null,
2322
"allow_reuse_address": true,
24-
"allow_reuse_port": true,
2523
"backlog": 20,
2624
"ignore_missing_slaves": false
2725
},
@@ -64,4 +62,4 @@
6462

6563

6664
}
67-
}
65+
}

pymodbus/server/simulator/jix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pymodbus/datastore/simulator.py
2+
pymodbus/server/async_io.py
3+
pymodbus/server/simulator/OLD.py
4+
pymodbus/server/simulator/TODO.md
5+
pymodbus/server/simulator/http_server.py
6+
pymodbus/server/simulator/main.py
7+
test/test_simulator.py

pymodbus/server/simulator/setup.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"host": "0.0.0.0",
66
"port": 5020,
77
"allow_reuse_address": true,
8-
"allow_reuse_port": true,
98
"ignore_missing_slaves": false,
109
"framer": "socket",
1110
"identity": {
@@ -44,7 +43,6 @@
4443
"certfile": "certificates/pymodbus.crt",
4544
"keyfile": "certificates/pymodbus.key",
4645
"allow_reuse_address": true,
47-
"allow_reuse_port": true,
4846
"backlog": 20,
4947
"ignore_missing_slaves": false,
5048
"framer": "tls",
@@ -92,9 +90,9 @@
9290
},
9391
"action": {
9492
"bits": null,
95-
"uint16": "register",
96-
"uint32": "register",
97-
"float32": "register",
93+
"uint16": "increment",
94+
"uint32": "increment",
95+
"float32": "increment",
9896
"string": null
9997
}
10098
}
@@ -103,7 +101,7 @@
103101
1
104102
],
105103
"write": [
106-
5
104+
3
107105
],
108106
"bits": [
109107
{"addr": 2, "value": 7}
@@ -113,12 +111,12 @@
113111
2100
114112
],
115113
"uint32": [
116-
{"addr": 4, "value": 617001},
117-
3037
114+
{"addr": [4, 5], "value": 617001},
115+
[3037, 3038]
118116
],
119117
"float32": [
120-
{"addr": 6, "value": 404.17},
121-
4100
118+
{"addr": [6, 7], "value": 404.17},
119+
[4100, 4101]
122120
],
123121
"string": [
124122
5047,
@@ -177,22 +175,22 @@
177175
{"addr": [2208, 2306], "action": null}
178176
],
179177
"uint32": [
180-
12,
181-
3037,
178+
[12, 13],
179+
[3037, 3038],
182180
[3136, 3139],
183-
{"addr": 3174, "value": 1},
181+
{"addr": [3174, 3175], "value": 1},
184182
{"addr": [3188,3189], "value": 32514},
185-
{"addr": [3308, 3406], "action": null},
186-
{"addr": [3688, 3878], "value": 115, "action": "increment"}
183+
{"addr": [3308, 3407], "action": null},
184+
{"addr": [3688, 3879], "value": 115, "action": "increment"}
187185
],
188186
"float32": [
189-
14,
190-
4047,
187+
[14, 15],
188+
[4047, 4048],
191189
[4146, 4149],
192-
{"addr": 4184, "value": 1},
193-
{"addr": [4198,4191], "value": 32514.1},
194-
{"addr": [4308, 4406], "action": null},
195-
{"addr": [4688, 4878], "value": 115.7, "action": "increment"}
190+
{"addr": [4184, 4185], "value": 1},
191+
{"addr": [4188, 4191], "value": 32514.1},
192+
{"addr": [4308, 4407], "action": null},
193+
{"addr": [4688, 4879], "value": 115.7, "action": "increment"}
196194
],
197195
"string": [
198196
{"addr": [16, 20], "value": "A_B_C_D_E_"},
Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<title>Modbus simulator.</title>
4+
<title>Modbus simulator</title>
55
<link rel="icon" type="image/x-icon" href="/favicon.ico">
66
<link rel="apple-touch-icon" href="/apple60.png">
77
<link rel="apple-touch-icon" sizes="76x76" href="/apple76.png">
@@ -11,10 +11,73 @@
1111
<!--REFRESH-->
1212
</head>
1313
<body>
14-
<center><h1>Func monitor</h1></center>
15-
16-
<a href="formdata/requests/monitor.html">Monitor</a>
17-
<a href="formdata/requests/set.html">Set response</a>
18-
14+
<h1><center>Calls</center></h1>
15+
<table width="80%">
16+
<thead>
17+
<tr>
18+
<th width="10%">C/R</th>
19+
<th width="10%">Code</th>
20+
<th width="10%">Address</th>
21+
<th width="10%">Count</th>
22+
<th width="60%">Data</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
<!--FC_ROWS-->
27+
</tbody>
28+
<tfoot>
29+
<tr>
30+
<th colspan="5"><!--FC_FOOT--></th>
31+
</tr>
32+
</tfoot>
33+
</table>
34+
<fieldset class="tools_fieldset">
35+
<legend>Monitor</legend>
36+
<form action="/api/calls" method="get">
37+
<label>Register range</label>
38+
<input type="number" value="FUNCTION_RANGE_START" name="range_start" />
39+
<input type="number" value="FUNCTION_RANGE_STOP" name="range_stop" /><br>
40+
<label>Function</label>
41+
<input type="number" value="FUNCTION_CODE" name="function" /><br>
42+
<label>Show as</label>
43+
<input type="checkbox" FUNCTION_SHOW_HEX_CHECKED name="show_hex">Hex</input>
44+
<input type="checkbox" FUNCTION_SHOW_DECODED_CHECKED name="show_decode">Decoded</input><br>
45+
<br><br>
46+
<b><!--FUNCTION_MONITORING_ACTIVE--></b>
47+
<br><br>
48+
<input type="submit" value="Monitor" name="submit" />
49+
<input type="submit" value="Clear" name="submit" />
50+
<input type="submit" value="Stop" name="submit" />
51+
</form>
52+
</fieldset>
53+
<fieldset class="tools_fieldset">
54+
<legend>Set</legend>
55+
<form action="/api/calls" method="get">
56+
<label>Response</label>
57+
<input type="radio" name="response_type" value="0" FUNCTION_RESPONSE_NORMAL_CHECKED>Normal</input>
58+
<input type="radio" name="response_type" value="1" FUNCTION_RESPONSE_ERROR_CHECKED>Error</input>
59+
<input type="radio" name="response_type" value="2" FUNCTION_RESPONSE_EMPTY_CHECKED>Empty</input>
60+
<input type="radio" name="response_type" value="3" FUNCTION_RESPONSE_JUNK_CHECKED>Junk</input><br>
61+
<Label>Split response</Label>
62+
<input type="checkbox" name="response_split" FUNCTION_RESPONSE_SPLIT_CHECKED/>
63+
<Label>Delay</Label>
64+
<input type="number" name="split_delay" value="FUNCTION_RESPONSE_SPLIT_DELAY"/>seconds<br>
65+
<Label>Change rate</Label>
66+
<input type="checkbox" name="response_cr" FUNCTION_RESPONSE_CR_CHECKED/>
67+
<input type="number" name="response_cr_pct" value="FUNCTION_RESPONSE_CR_PCT"/>%<br>
68+
<Label>Delay response</Label>
69+
<input type="number" name="response_delay" value="FUNCTION_RESPONSE_DELAY"/>seconds<br>
70+
<Label>Junk datalength</Label>
71+
<input type="number" name="response_junk_datalen" value="FUNCTION_RESPONSE_JUNK" />bytes<br>
72+
<Label>Error response</Label>
73+
<select name="response_error">
74+
<!--FUNCTION_ERROR-->
75+
</select><br>
76+
<Label>Clear after</Label>
77+
<input type="number" name="response_clear_after" value="FUNCTION_RESPONSE_CLEAR_AFTER" />requests<br>
78+
<input type="submit" value="Set" name="submit" />
79+
<input type="submit" value="Reset" name="submit" />
80+
</form>
81+
</fieldset>
1982
</body>
2083
</html>

pymodbus/server/simulator/web/generator/log

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,29 @@
1111
<!--REFRESH-->
1212
</head>
1313
<body>
14-
<center><h1>Log clear</h1></center>
15-
16-
<a href="formdata/log/get_raw.html">Get raw</a>
17-
<a href="formdata/log/monitor.html">Monitor</a>
18-
<a href="formdata/log/save.html">Save</a>
19-
<a href="formdata/log/clear.html">Clear</a>
20-
14+
<center><h1>Log</h1></center>
15+
<table width="80%">
16+
<thead>
17+
<tr>
18+
<th width="10%">Log entries</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<!--LOG_ROWS-->
23+
</tbody>
24+
<tfoot>
25+
<tr>
26+
<th colspan="7"><!--LOG_FOOT--></th>
27+
</tr>
28+
</tfoot>
29+
</table>
30+
<fieldset class="tools_fieldset" width="30%">
31+
<legend>Log</legend>
32+
<form action="/api/log" method="get">
33+
<input type="submit" value="Download" name="submit" />
34+
<input type="submit" value="Monitor" name="submit" />
35+
<input type="submit" value="Clear" name="submit" />
36+
</form>
37+
</fieldset>
2138
</body>
2239
</html>

pymodbus/server/simulator/web/generator/registers

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,51 @@
2323
<th width="10%"># read</th>
2424
<th width="10%"># write</th>
2525
</tr>
26-
</thead>
27-
<tbody>
28-
<!--REGISTER_ROWS-->
29-
</tbody>
30-
<tfoot>
31-
<tr>
32-
<th colspan="7"><!--REGISTER_FOOT--></th>
33-
</tr>
34-
</tfoot>
35-
</table>
36-
<fieldset class="tools_fieldset">
37-
<legend>Filter</legend>
38-
<form action="/api/registers" method="get">
39-
<label>Register range</label>
40-
<input type="number" name="range_start">
41-
<input type="number" name="range_stop"><br>
42-
<label>Type</label>
43-
<select name="type">
44-
<!--REGISTER_TYPES-->
45-
</select><br>
46-
<label>Action</label>
47-
<select name="action">
48-
<!--REGISTER_ACTIONS-->
49-
</select><br>
50-
<label>Writeable</label>
51-
<input type="checkbox" name="writeable"><br>
52-
<input type="submit" value="Add" name="submit">
53-
<input type="submit" value="Clear" name="submit">
54-
</form>
55-
</fieldset>
56-
<fieldset class="tools_fieldset">
57-
<legend>Set</legend>
58-
<form action="/api/registers" method="get">
59-
<br>
60-
<label>Register</label>
61-
<input type="number" name="register"><br>
62-
<label>Value</label>
63-
<input type="text" name="value"><br>
64-
<label>Writeable</label>
65-
<input type="checkbox" name="writeable"><br>
66-
<input type="submit" value="Set" name="submit">
26+
</thead>
27+
<tbody>
28+
<!--REGISTER_ROWS-->
29+
</tbody>
30+
<tfoot>
31+
<tr>
32+
<th colspan="7"><!--REGISTER_FOOT--></th>
33+
</tr>
34+
</tfoot>
35+
</table>
36+
<fieldset class="tools_fieldset" width="40%">
37+
<legend>Filter</legend>
38+
<form action="/api/registers" method="get">
39+
<label>Register range</label>
40+
<input type="number" name="range_start" />
41+
<input type="number" name="range_stop" /><br>
42+
<label>Type</label>
43+
<select name="type">
44+
<option value=-1 selected>Any</option>
45+
<!--REGISTER_TYPES-->
46+
</select><br>
47+
<label>Action</label>
48+
<select name="action">
49+
<option value=-1 selected>Any</option>
50+
<!--REGISTER_ACTIONS-->
51+
</select><br>
52+
<label>Writeable</label>
53+
<input type="checkbox" name="writeable" /><br>
54+
<input type="submit" value="Add" name="submit" />
55+
<input type="submit" value="Clear" name="submit" />
56+
</form>
57+
</fieldset>
58+
<fieldset class="tools_fieldset" width="20%">
59+
<legend>Set</legend>
60+
<form action="/api/registers" method="get">
61+
<br>
62+
<label>Register</label>
63+
<input type="number" name="register" /><br>
64+
<label>Value</label>
65+
<input type="text" name="value" /><br>
66+
<label>Writeable</label>
67+
<input type="checkbox" name="writeable" /><br>
68+
<input type="submit" value="Set" name="submit" />
6769
</form>
68-
</fieldset><br>
69-
<p>Result of last command: <!--RESULT--></p>
70+
</fieldset><br>
71+
<p>Result of last command: <!--RESULT--></p>
7072
</body>
7173
</html>

pymodbus/server/simulator/web/generator/server

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
<!--REFRESH-->
1212
</head>
1313
<body>
14-
<center><h1>Server clear</h1></center>
15-
16-
<a href="formdata/server/status.html">Status</a>
17-
<a href="formdata/server/clear.html">Clear</a>
18-
<a href="formdata/server/restart.html">Restart</a>
19-
20-
</body>
14+
<body>
15+
<center><h1>Server</h1></center>
16+
<fieldset class="tools_fieldset" width="30%">
17+
<legend>Status</legend>
18+
Uptime: <!--UPTIME-->
19+
</fieldset>
20+
<fieldset class="tools_fieldset" width="30%">
21+
<legend>Status</legend>
22+
<form action="/api/server" method="get">
23+
<input type="submit" value="Restart" name="submit" />
24+
</form>
25+
</fieldset>
26+
</body>
2127
</html>

0 commit comments

Comments
 (0)