pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.21k stars 908 forks source link

AsyncModbusTcpClient: Cannot read after one failed read #1466

Closed 02JanDal closed 1 year ago

02JanDal commented 1 year ago

Versions

Pymodbus Specific

Description

Depending on firmware versions and connection type involved, the set of supported registers varies. Therefore, I'm trying to write some code to detect which registers can be used. The most obvious, calling read_input_registers on each register and catching ModbusExceptions fails by subsequent registers after the failing also failing, even if they should succeed because the failure causes pymodbus to disconnect. Furthermore, calling await client.close() seems to keep some internal state which makes further calls not work, only recreating the client object from scratch works.

As such, I have a working workaround, however it feels a little hacky. Though I don't understand the Modbus protocol sufficiently to say so with confidence, but I suspect that the root cause might be the server in question misbehaving, however, it would be nice if pymodbus could handle this gracefully (either by automatically reconnecting or at least working after a manual re-connect).

Code and Logs

First attempt:

import asyncio
import sys

from pymodbus.client import AsyncModbusTcpClient
from pymodbus.exceptions import ModbusException
import pymodbus

pymodbus.pymodbus_apply_logging_config()

async def main():
    client = AsyncModbusTcpClient("192.168.3.20", 502)
    await client.connect()
    for address, count in [(4949, 2), (4951, 2), (4953, 15), (4968, 15), (4999, 1)]:
        try:
            print("Getting", address, file=sys.stderr)
            res = await client.read_input_registers(address, count, slave=1)
            print(res.registers, file=sys.stderr)
        except ModbusException as e:
            print(e, file=sys.stderr)

if __name__ == "__main__":
    asyncio.run(main())
Log ``` 2023-03-31 05:12:48,976 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:12:48,976 DEBUG logging:102 Connecting. 2023-03-31 05:12:48,989 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:12:48,989 INFO logging:96 Protocol made connection. 2023-03-31 05:12:48,989 INFO logging:96 Connected to 192.168.3.20:502. Getting 4949 2023-03-31 05:12:48,989 DEBUG logging:102 send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x55 0x0 0x2 2023-03-31 05:12:48,989 DEBUG logging:102 Adding transaction 1 2023-03-31 05:12:48,999 DEBUG logging:102 recv: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:12:49,000 DEBUG logging:102 Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:12:49,000 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:12:49,000 DEBUG logging:102 Getting transaction 1 [12592, 16705] Getting 4951 2023-03-31 05:12:49,000 DEBUG logging:102 send: 0x0 0x2 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x57 0x0 0x2 2023-03-31 05:12:49,000 DEBUG logging:102 Adding transaction 2 2023-03-31 05:12:49,007 DEBUG logging:102 recv: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:12:49,007 DEBUG logging:102 Processing: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:12:49,007 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:12:49,007 DEBUG logging:102 Getting transaction 2 [1024, 256] Getting 4953 2023-03-31 05:12:49,008 DEBUG logging:102 send: 0x0 0x3 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x59 0x0 0xf 2023-03-31 05:12:49,008 DEBUG logging:102 Adding transaction 3 2023-03-31 05:12:49,018 DEBUG logging:102 recv: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:12:49,018 DEBUG logging:102 Processing: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:12:49,018 DEBUG logging:102 Factory Response[132] 2023-03-31 05:12:49,019 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:12:49,019 INFO logging:96 Protocol lost connection. 2023-03-31 05:12:49,019 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:12:49,020 DEBUG logging:102 Getting transaction 3 2023-03-31 05:12:49,020 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request Getting 4968 Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.3.20:502] Getting 4999 Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.3.20:502] ```

Second attempt (manually closing and reconnecting with same client):

import asyncio
import sys

from pymodbus.client import AsyncModbusTcpClient
from pymodbus.exceptions import ModbusException
import pymodbus

pymodbus.pymodbus_apply_logging_config()

async def main():
    client = AsyncModbusTcpClient("192.168.3.20", 502)
    await client.connect()
    for address, count in [(4949, 2), (4951, 2), (4953, 15), (4968, 15), (4999, 1)]:
        try:
            print("Getting", address, file=sys.stderr)
            res = await client.read_input_registers(address, count, slave=1)
            print(res.registers, file=sys.stderr)
        except ModbusException as e:
            print(e, file=sys.stderr)
            await client.close()
            await client.connect()

if __name__ == "__main__":
    asyncio.run(main())
Log ``` 2023-03-31 05:16:40,260 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:16:40,260 DEBUG logging:102 Connecting. 2023-03-31 05:16:40,268 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:16:40,269 INFO logging:96 Protocol made connection. 2023-03-31 05:16:40,269 INFO logging:96 Connected to 192.168.3.20:502. Getting 4949 2023-03-31 05:16:40,269 DEBUG logging:102 send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x55 0x0 0x2 2023-03-31 05:16:40,269 DEBUG logging:102 Adding transaction 1 2023-03-31 05:16:40,278 DEBUG logging:102 recv: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:16:40,279 DEBUG logging:102 Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:16:40,279 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:16:40,279 DEBUG logging:102 Getting transaction 1 [12592, 16705] Getting 4951 2023-03-31 05:16:40,279 DEBUG logging:102 send: 0x0 0x2 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x57 0x0 0x2 2023-03-31 05:16:40,279 DEBUG logging:102 Adding transaction 2 2023-03-31 05:16:40,287 DEBUG logging:102 recv: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:16:40,287 DEBUG logging:102 Processing: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:16:40,288 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:16:40,288 DEBUG logging:102 Getting transaction 2 [1024, 256] Getting 4953 2023-03-31 05:16:40,288 DEBUG logging:102 send: 0x0 0x3 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x59 0x0 0xf 2023-03-31 05:16:40,288 DEBUG logging:102 Adding transaction 3 2023-03-31 05:16:40,294 DEBUG logging:102 recv: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:16:40,295 DEBUG logging:102 Processing: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:16:40,295 DEBUG logging:102 Factory Response[132] 2023-03-31 05:16:40,295 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,296 INFO logging:96 Protocol lost connection. 2023-03-31 05:16:40,296 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,296 DEBUG logging:102 Getting transaction 3 2023-03-31 05:16:40,296 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request 2023-03-31 05:16:40,296 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:16:40,296 DEBUG logging:102 Connecting. 2023-03-31 05:16:40,299 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:16:40,300 INFO logging:96 Protocol made connection. 2023-03-31 05:16:40,300 INFO logging:96 Connected to 192.168.3.20:502. Getting 4968 2023-03-31 05:16:40,300 DEBUG logging:102 send: 0x0 0x4 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x68 0x0 0xf 2023-03-31 05:16:40,300 DEBUG logging:102 Adding transaction 4 2023-03-31 05:16:40,309 DEBUG logging:102 recv: 0x0 0x4 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:16:40,309 DEBUG logging:102 Processing: 0x0 0x4 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:16:40,309 DEBUG logging:102 Factory Response[132] 2023-03-31 05:16:40,309 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,310 INFO logging:96 Protocol lost connection. 2023-03-31 05:16:40,310 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,310 DEBUG logging:102 Getting transaction 4 2023-03-31 05:16:40,310 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request 2023-03-31 05:16:40,310 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:16:40,310 DEBUG logging:102 Connecting. 2023-03-31 05:16:40,317 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:16:40,317 INFO logging:96 Protocol made connection. 2023-03-31 05:16:40,317 INFO logging:96 Connected to 192.168.3.20:502. Getting 4999 2023-03-31 05:16:40,317 DEBUG logging:102 send: 0x0 0x5 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x87 0x0 0x1 2023-03-31 05:16:40,317 DEBUG logging:102 Adding transaction 5 2023-03-31 05:16:40,328 DEBUG logging:102 recv: 0x0 0x5 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0xe 0x3 2023-03-31 05:16:40,328 DEBUG logging:102 Processing: 0x0 0x5 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0xe 0x3 2023-03-31 05:16:40,328 DEBUG logging:102 Factory Response[132] 2023-03-31 05:16:40,328 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,329 INFO logging:96 Protocol lost connection. 2023-03-31 05:16:40,329 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:16:40,329 DEBUG logging:102 Getting transaction 5 2023-03-31 05:16:40,329 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request 2023-03-31 05:16:40,329 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:16:40,329 DEBUG logging:102 Connecting. 2023-03-31 05:16:40,334 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:16:40,334 INFO logging:96 Protocol made connection. 2023-03-31 05:16:40,334 INFO logging:96 Connected to 192.168.3.20:502. ```

Third attempt (re-creating the client object):

import asyncio
import sys

from pymodbus.client import AsyncModbusTcpClient
from pymodbus.exceptions import ModbusException
import pymodbus

pymodbus.pymodbus_apply_logging_config()

async def main():
    client = AsyncModbusTcpClient("192.168.3.20", 502)
    await client.connect()
    for address, count in [(4949, 2), (4951, 2), (4953, 15), (4968, 15), (4999, 1)]:
        try:
            print("Getting", address, file=sys.stderr)
            res = await client.read_input_registers(address, count, slave=1)
            print(res.registers, file=sys.stderr)
        except ModbusException as e:
            print(e, file=sys.stderr)
            client = AsyncModbusTcpClient("192.168.3.20", 502)
            await client.connect()

if __name__ == "__main__":
    asyncio.run(main())
Log ``` 2023-03-31 05:18:10,008 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:18:10,009 DEBUG logging:102 Connecting. 2023-03-31 05:18:10,015 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:18:10,015 INFO logging:96 Protocol made connection. 2023-03-31 05:18:10,015 INFO logging:96 Connected to 192.168.3.20:502. Getting 4949 2023-03-31 05:18:10,016 DEBUG logging:102 send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x55 0x0 0x2 2023-03-31 05:18:10,016 DEBUG logging:102 Adding transaction 1 2023-03-31 05:18:10,024 DEBUG logging:102 recv: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:18:10,024 DEBUG logging:102 Processing: 0x0 0x1 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x31 0x30 0x41 0x41 2023-03-31 05:18:10,024 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:18:10,024 DEBUG logging:102 Getting transaction 1 [12592, 16705] Getting 4951 2023-03-31 05:18:10,024 DEBUG logging:102 send: 0x0 0x2 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x57 0x0 0x2 2023-03-31 05:18:10,024 DEBUG logging:102 Adding transaction 2 2023-03-31 05:18:10,031 DEBUG logging:102 recv: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:18:10,031 DEBUG logging:102 Processing: 0x0 0x2 0x0 0x0 0x0 0x7 0x1 0x4 0x4 0x4 0x0 0x1 0x0 2023-03-31 05:18:10,031 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:18:10,031 DEBUG logging:102 Getting transaction 2 [1024, 256] Getting 4953 2023-03-31 05:18:10,031 DEBUG logging:102 send: 0x0 0x3 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x59 0x0 0xf 2023-03-31 05:18:10,031 DEBUG logging:102 Adding transaction 3 2023-03-31 05:18:10,038 DEBUG logging:102 recv: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:18:10,038 DEBUG logging:102 Processing: 0x0 0x3 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:18:10,038 DEBUG logging:102 Factory Response[132] 2023-03-31 05:18:10,038 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:18:10,039 INFO logging:96 Protocol lost connection. 2023-03-31 05:18:10,039 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:18:10,039 DEBUG logging:102 Getting transaction 3 2023-03-31 05:18:10,039 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request 2023-03-31 05:18:10,039 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:18:10,039 DEBUG logging:102 Connecting. 2023-03-31 05:18:10,043 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:18:10,044 INFO logging:96 Protocol made connection. 2023-03-31 05:18:10,044 INFO logging:96 Connected to 192.168.3.20:502. Getting 4968 2023-03-31 05:18:10,044 DEBUG logging:102 send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x68 0x0 0xf 2023-03-31 05:18:10,044 DEBUG logging:102 Adding transaction 1 2023-03-31 05:18:10,054 DEBUG logging:102 recv: 0x0 0x1 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:18:10,054 DEBUG logging:102 Processing: 0x0 0x1 0x0 0x0 0x0 0x2 0x1 0x84 0x2 2023-03-31 05:18:10,054 DEBUG logging:102 Factory Response[132] 2023-03-31 05:18:10,054 ERROR logging:114 General exception: index out of range Fatal error: protocol.data_received() call failed. protocol: transport: <_SelectorSocketTransport fd=6 read=polling write=> Traceback (most recent call last): File "/home/jan/.pyenv/versions/3.10.9/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received self._protocol.data_received(data) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/client/base.py", line 272, in data_received self.framer.processIncomingPacket(data, self._handle_response, slave=0) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 167, in processIncomingPacket self._process(callback) File "/home/jan/projects/homeassistant-core/venv/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 186, in _process raise ModbusIOException("Unable to decode request") pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:18:10,054 INFO logging:96 Protocol lost connection. 2023-03-31 05:18:10,054 DEBUG logging:102 Client disconnected from modbus server: Modbus Error: [Input/Output] Unable to decode request 2023-03-31 05:18:10,055 DEBUG logging:102 Getting transaction 1 2023-03-31 05:18:10,055 DEBUG logging:102 Waiting 100 ms before next connection attempt. Modbus Error: [Connection] Connection lost during request 2023-03-31 05:18:10,055 DEBUG logging:102 Connecting to 192.168.3.20:502. 2023-03-31 05:18:10,055 DEBUG logging:102 Connecting. 2023-03-31 05:18:10,063 DEBUG logging:102 Client connected to modbus server 2023-03-31 05:18:10,063 INFO logging:96 Protocol made connection. 2023-03-31 05:18:10,063 INFO logging:96 Connected to 192.168.3.20:502. Getting 4999 2023-03-31 05:18:10,063 DEBUG logging:102 send: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x4 0x13 0x87 0x0 0x1 2023-03-31 05:18:10,063 DEBUG logging:102 Adding transaction 1 2023-03-31 05:18:10,075 DEBUG logging:102 recv: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0xe 0x3 2023-03-31 05:18:10,076 DEBUG logging:102 Processing: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x4 0x2 0xe 0x3 2023-03-31 05:18:10,076 DEBUG logging:102 Factory Response[ReadInputRegistersResponse': 4] 2023-03-31 05:18:10,076 DEBUG logging:102 Getting transaction 1 [3587] ```
janiversen commented 1 year ago

looks like you found a problem, I will write a test case to verify it.

janiversen commented 1 year ago

The client do reconnect automatically but the app is notified because it might need some handling of the failed call.

janiversen commented 1 year ago

Checked an extra time, reconnect automatically do work, however if you do not use the (relatively) new callback, you do not know the state of the connection.

We are in general in the process of refactoring the whole client, because there are a number of "strange" cases, like the reconnect.