Skip to content

Commit

Permalink
2nd try.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Dec 26, 2023
1 parent 7334db8 commit 81df5b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pymodbus/framer/rtu_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def resetFrame(self):
end of the message (python just doesn't have the resolution to
check for millisecond delays).
"""
# x = self._buffer
x = self._buffer
super().resetFrame()
# self._buffer = x
self._buffer = x

def isFrameReady(self):
"""Check if we should continue decode logic.
Expand Down Expand Up @@ -247,6 +247,7 @@ def sendPacket(self, message):
:param message: Message to be sent over the bus
:return:
"""
super().resetFrame()
start = time.time()
timeout = start + self.client.comm_params.timeout_connect
while self.client.state != ModbusTransactionState.IDLE:
Expand Down
9 changes: 8 additions & 1 deletion test/sub_client/test_client_faulty_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pymodbus.exceptions import ModbusIOException
from pymodbus.factory import ClientDecoder
from pymodbus.framer import ModbusSocketFramer
from pymodbus.framer import ModbusRtuFramer, ModbusSocketFramer


class TestFaultyResponses:
Expand All @@ -30,6 +30,13 @@ def test_ok_frame(self, framer, callback):
framer.processIncomingPacket(self.good_frame, callback, self.slaves)
callback.assert_called_once()

def test_1917_frame(self, callback):
"""Test invalid frame in issue 1917."""
recv = b"\x01\x86\x02\x00\x01"
framer = ModbusRtuFramer(ClientDecoder())
framer.processIncomingPacket(recv, callback, self.slaves)
callback.assert_not_called()

def test_faulty_frame1(self, framer, callback):
"""Test ok frame."""
faulty_frame = b"\x00\x04\x00\x00\x00\x05\x00\x03\x0a\x00\x04"
Expand Down

0 comments on commit 81df5b1

Please sign in to comment.