Skip to content

Commit

Permalink
Merge master v3.6.8 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Apr 14, 2024
2 parents 9fa913a + dfe7a38 commit 681fd2c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ helps make pymodbus a better product.

:ref:`Authors`: contains a complete list of volunteers have contributed to each major version.

Version 3.6.8
-------------
* Allow socket exception response with wrong length


Version 3.6.7
-------------
* Add lock to async requests, correct logging and length calc. (FIX, not on dev)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PyModbus - A Python Modbus Stack

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is `3.6.7 <https://github.com/pymodbus-dev/pymodbus/releases/tag/v3.6.7>`_.
Current release is `3.6.8 <https://github.com/pymodbus-dev/pymodbus/releases/tag/v3.6.8>`_.

Bleeding edge (not released) is `dev <https://github.com/pymodbus-dev/pymodbus/tree/dev>`_.

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
from pymodbus.pdu import ExceptionResponse


__version__ = "3.7.0dev1"
__version__ = "3.7.0dev2"
__version_full__ = f"[pymodbus, version {__version__}]"
29 changes: 15 additions & 14 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,21 @@ async def async_execute(self, request) -> ModbusResponse:

count = 0
while count <= self.retries:
req = self.build_response(request.transaction_id)
if not count or not self.no_resend_on_retry:
self.ctx.framer.resetFrame()
self.ctx.send(packet)
if self.broadcast_enable and not request.slave_id:
resp = None
break
try:
resp = await asyncio.wait_for(
req, timeout=self.ctx.comm_params.timeout_connect
)
break
except asyncio.exceptions.TimeoutError:
count += 1
async with self._lock:
req = self.build_response(request.transaction_id)
if not count or not self.no_resend_on_retry:
self.framer.resetFrame()
self.send(packet)
if self.broadcast_enable and not request.slave_id:
resp = None
break
try:
resp = await asyncio.wait_for(
req, timeout=self.comm_params.timeout_connect
)
break
except asyncio.exceptions.TimeoutError:
count += 1
if count > self.retries:
self.close(reconnect=True)
raise ModbusIOException(
Expand Down
2 changes: 2 additions & 0 deletions pymodbus/framer/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def decode(self, data: bytes) -> tuple[int, int, int, bytes]:
if used_len < msg_len:
Log.debug("Short frame: {} wait for more data", data, ":hex")
return 0, 0, 0, self.EMPTY
if msg_len == 2 and used_len >= self.MIN_SIZE:
msg_len = 3
return msg_len, msg_tid, msg_dev, data[7:msg_len]

def encode(self, pdu: bytes, device_id: int, tid: int) -> bytes:
Expand Down
15 changes: 15 additions & 0 deletions test/framers/test_old_framers.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ def _handle_response(_reply):
framer.processIncomingPacket(message, _handle_response, slave=0)
assert response_ok, "Response is valid, but not accepted"

def test_recv_socket_exception_faulty(self):
"""Test receive packet."""
response_ok = False

def _handle_response(_reply):
"""Handle response."""
nonlocal response_ok
response_ok = True

message = bytearray(b"\x00\x02\x00\x00\x00\x02\x01\x84\x02")
response_ok = False
framer = ModbusSocketFramer(ClientDecoder())
framer.processIncomingPacket(message, _handle_response, slave=0)
assert response_ok, "Response is valid, but not accepted"

# ---- 100% coverage
@pytest.mark.parametrize(
("framer", "message"),
Expand Down

0 comments on commit 681fd2c

Please sign in to comment.