File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -143,17 +143,19 @@ def _exit_read(self, response: bytearray) -> bool:
143143 :param response: The response
144144 :type response: bytearray
145145
146- :returns: State of basic read response evaluation
146+ :returns: State of basic read response evaluation,
147+ True if entire response has been read
147148 :rtype: bool
148149 """
149- if response [1 ] >= Const .ERROR_BIAS :
150- if len (response ) < Const .ERROR_RESP_LEN :
150+ response_len = len (response )
151+ if response_len >= 2 and response [1 ] >= Const .ERROR_BIAS :
152+ if response_len < Const .ERROR_RESP_LEN :
151153 return False
152- elif (Const .READ_COILS <= response [1 ] <= Const .READ_INPUT_REGISTER ):
154+ elif response_len >= 3 and (Const .READ_COILS <= response [1 ] <= Const .READ_INPUT_REGISTER ):
153155 expected_len = Const .RESPONSE_HDR_LENGTH + 1 + response [2 ] + Const .CRC_LENGTH
154- if len ( response ) < expected_len :
156+ if response_len < expected_len :
155157 return False
156- elif len ( response ) < Const .FIXED_RESP_LEN :
158+ elif response_len < Const .FIXED_RESP_LEN :
157159 return False
158160
159161 return True
You can’t perform that action at this time.
0 commit comments