@@ -343,7 +343,7 @@ def _recv(self, expected_response_length, full): # NOSONAR
343343 if isinstance (self .client .framer , ModbusSocketFramer ):
344344 min_size = 8
345345 elif isinstance (self .client .framer , ModbusRtuFramer ):
346- min_size = 2
346+ min_size = 4
347347 elif isinstance (self .client .framer , ModbusAsciiFramer ):
348348 min_size = 5
349349 elif isinstance (self .client .framer , ModbusBinaryFramer ):
@@ -362,7 +362,7 @@ def _recv(self, expected_response_length, full): # NOSONAR
362362 if isinstance (self .client .framer , ModbusSocketFramer ):
363363 func_code = int (read_min [- 1 ])
364364 elif isinstance (self .client .framer , ModbusRtuFramer ):
365- func_code = int (read_min [- 1 ])
365+ func_code = int (read_min [1 ])
366366 elif isinstance (self .client .framer , ModbusAsciiFramer ):
367367 func_code = int (read_min [3 :5 ], 16 )
368368 elif isinstance (self .client .framer , ModbusBinaryFramer ):
@@ -378,6 +378,12 @@ def _recv(self, expected_response_length, full): # NOSONAR
378378 )
379379 length = struct .unpack (">H" , read_min [4 :6 ])[0 ] - 1
380380 expected_response_length = h_size + length
381+ elif expected_response_length is None and isinstance (self .client .framer , ModbusRtuFramer ):
382+ try :
383+ expected_response_length = self .client .framer .get_expected_response_length (read_min )
384+ except IndexError :
385+ # Could not determine response length with available bytes
386+ pass
381387 if expected_response_length is not None :
382388 expected_response_length -= min_size
383389 total = expected_response_length + min_size
0 commit comments