def _recv(self, expected_length=-1):
    """Receive the response from the slave"""
response = ''
read_bytes = 'dummy'
iterCnt = 0
while read_bytes:
    if iterCnt == 0:
        read_bytes = self._serial.read(expected_length)
else:
    read_bytes = self._serial.read(1)
response += read_bytes
if len(response) >= expected_length >= 0:
    break
iterCnt += 1
Python modbus library