From a70bd287206706da6e3dedc0a0c46d7f3d08c7a5 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 12 Jan 2024 15:41:38 +0100 Subject: [PATCH] Correct expected length for udp sync client. --- pymodbus/transaction.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index fded324d8..d85fc9563 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -100,7 +100,7 @@ def _calculate_exception_length(self): return self.base_adu_size + 2 # Fcode(1), ExceptionCode(1) return None - def _validate_response(self, request, response, exp_resp_len): + def _validate_response(self, request, response, exp_resp_len, is_udp=False): """Validate Incoming response against request. :param request: Request sent @@ -118,7 +118,7 @@ def _validate_response(self, request, response, exp_resp_len): ): return False - if "length" in mbap and exp_resp_len: + if "length" in mbap and exp_resp_len and not is_udp: return mbap.get("length") == exp_resp_len return True @@ -161,7 +161,9 @@ def execute(self, request): # noqa: C901 else: full = False c_str = str(self.client) + is_udp = False if "modbusudpclient" in c_str.lower().strip(): + is_udp = True full = True if not expected_response_length: expected_response_length = 1024 @@ -173,7 +175,8 @@ def execute(self, request): # noqa: C901 ) while retries > 0: valid_response = self._validate_response( - request, response, expected_response_length + request, response, expected_response_length, + is_udp=is_udp ) if valid_response: if (