Skip to content

Commit e5a82d5

Browse files
committed
Merge branch 'dev'
2 parents 46bcb7a + 1c7dd05 commit e5a82d5

File tree

9 files changed

+113
-8
lines changed

9 files changed

+113
-8
lines changed

API_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PyModbus - API changes.
66
Version 3.6.0 (future)
77
-------------
88

9+
-------------
10+
Version 3.5.2
11+
-------------
12+
No changes.
913

1014
-------------
1115
Version 3.5.1

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
All these version were not possible without volunteers!
22
`AUTHORS` contains a complete list for each major version.
33

4+
version 3.5.2
5+
----------------------------------------------------------
6+
- server tracer example. (#1773)
7+
- sync connect missing. (#1772)
8+
- simulator future problem. (#1771)
9+
410
version 3.5.1
511
----------------------------------------------------------
612
- Always close socket on error (reset_sock). (#1767)

MAKE_RELEASE.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ Making a release.
88
------------------------------------------------------------
99
Prepare/make release on dev.
1010
------------------------------------------------------------
11-
* Make pull request "prepare v3.4.x", with the following:
11+
* Make pull request "prepare v3.5.x", with the following:
1212
* Update pymodbus/__init__.py with version number (__version__ X.Y.Zpre)
1313
* Update README.rst "Supported versions"
14+
* Control / Update API_changes.rst
1415
* Update CHANGELOG.rst
15-
* Add commits from last release, but kselectively !
16+
* Add commits from last release, but selectively !
1617
git log --oneline v3.5.1..HEAD > commit.log
17-
git log --pretty="%an" v3.5.1..HEAD | sort -uf >> AUTHORS
18+
git log --pretty="%an" v3.0.0..HEAD | sort -uf >> AUTHORS
1819
update AUTHORS
1920
* Commit, push and merge.
2021
* Checkout master locally

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Supported versions
1919

2020
Version `2.5.3 <https://github.com/pymodbus-dev/pymodbus/releases/tag/v2.5.3>`_ is the last 2.x release (python >= 2.7, no longer supported).
2121

22-
Version `3.5.0 <https://github.com/pymodbus-dev/pymodbus/releases/tag/v3.5.0>`_ is the current release (Tested with Python >= 3.8).
22+
Version `3.5.2 <https://github.com/pymodbus-dev/pymodbus/releases/tag/v3.5.2>`_ is the current release (Tested with Python >= 3.8).
2323

2424
.. important::
2525
All API changes after 3.0.0 are documented in `API_changes.rst <https://github.com/pymodbus-dev/pymodbus/blob/dev/API_changes.rst>`_

doc/source/examples.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Callback Server example
6464
^^^^^^^^^^^^^^^^^^^^^^^
6565
.. literalinclude:: ../../examples/server_callback.py
6666

67+
Server tracer example
68+
^^^^^^^^^^^^^^^^^^^^^
69+
.. literalinclude:: ../../examples/server_hook.py
70+
6771
Custom Message client
6872
^^^^^^^^^^^^^^^^^^^^^
6973
.. literalinclude:: ../../examples/client_custom_msg.py
@@ -107,6 +111,10 @@ Examples contributions
107111
These examples are supplied by users of pymodbus.
108112
The pymodbus team thanks for sharing the examples.
109113

114+
Solar
115+
^^^^^
116+
.. literalinclude:: ../../examples/contrib/solar.py
117+
110118
Redis datastore
111119
^^^^^^^^^^^^^^^
112120
.. literalinclude:: ../../examples/contrib/redis_datastore.py

examples/server_hook.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
"""Pymodbus Server With request/response manipulator.
3+
4+
This is an example of using the builtin request/response tracer to
5+
manipulate the messages to/from the modbus server
6+
"""
7+
import asyncio
8+
import logging
9+
10+
from pymodbus import pymodbus_apply_logging_config
11+
from pymodbus.datastore import (
12+
ModbusSequentialDataBlock,
13+
ModbusServerContext,
14+
ModbusSlaveContext,
15+
)
16+
from pymodbus.server import ModbusTcpServer
17+
from pymodbus.transaction import ModbusSocketFramer
18+
19+
20+
class Manipulator:
21+
"""A Class to run the server.
22+
23+
Using a class allows the easy use of global variables, but
24+
are not strictly needed
25+
"""
26+
27+
message_count: int = 1
28+
server: ModbusTcpServer = None
29+
30+
def server_request_tracer(self, request, *_addr):
31+
"""Trace requests.
32+
33+
All server requests passes this filter before being handled.
34+
"""
35+
print(f"---> REQUEST: {request}")
36+
37+
def server_response_manipulator(self, response):
38+
"""Manipulate responses.
39+
40+
All server responses passes this filter before being sent.
41+
The filter returns:
42+
43+
- response, either original or modified
44+
- skip_encoding, signals whether or not to encode the response
45+
"""
46+
if not self.message_count:
47+
print(f"---> RESPONSE: {response}")
48+
self.message_count = 3
49+
else:
50+
print("---> RESPONSE: NONE")
51+
response.should_respond = False
52+
self.message_count -= 1
53+
return response, False
54+
55+
async def setup(self):
56+
"""Prepare server."""
57+
pymodbus_apply_logging_config(logging.DEBUG)
58+
datablock = ModbusSequentialDataBlock(0x00, [17] * 100)
59+
context = ModbusServerContext(
60+
slaves=ModbusSlaveContext(
61+
di=datablock, co=datablock, hr=datablock, ir=datablock
62+
),
63+
single=True,
64+
)
65+
self.server = ModbusTcpServer(
66+
context,
67+
ModbusSocketFramer,
68+
None,
69+
("127.0.0.1", 5020),
70+
request_tracer=self.server_request_tracer,
71+
response_manipulator=self.server_response_manipulator,
72+
)
73+
74+
async def run(self):
75+
"""Attach Run server"""
76+
await self.server.serve_forever()
77+
78+
79+
async def main():
80+
"""Run example."""
81+
server = Manipulator()
82+
await server.setup()
83+
await server.run()
84+
85+
86+
if __name__ == "__main__":
87+
asyncio.run(main(), debug=True) # pragma: no cover

pymodbus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
from pymodbus.logging import pymodbus_apply_logging_config
1313

1414

15-
__version__ = "3.5.1"
15+
__version__ = "3.5.2"
1616
__version_full__ = f"[pymodbus, version {__version__}]"

pymodbus/client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def execute(self, request: ModbusRequest = None) -> ModbusResponse:
175175
:raises ConnectionException: Check exception text.
176176
"""
177177
if self.use_sync:
178-
if not self.connected:
178+
if not self.connect():
179179
raise ConnectionException(f"Failed to connect[{self!s}]")
180180
return self.transaction.execute(request)
181181
if not self.transport:

pymodbus/server/simulator/http_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ async def run_forever(self, only_start=False):
254254
Log.info("HTTP server started on ({}:{})", self.http_host, self.http_port)
255255
if only_start:
256256
return
257-
while True:
258-
await self.serving()
257+
await self.serving
259258

260259
async def stop(self):
261260
"""Stop modbus and http servers."""

0 commit comments

Comments
 (0)