1414from pymodbus .client import AsyncModbusTcpClient
1515from pymodbus .client .mixin import ModbusClientMixin
1616from pymodbus .exceptions import ConnectionException , ModbusIOException
17- from pymodbus .pdu import ExceptionResponse
17+
18+ try :
19+ # for pymodbus 3.11.1 and newer
20+ from pymodbus .pdu .pdu import ExceptionResponse
21+ except ImportError :
22+ # or backwards compatibility
23+ from pymodbus .pdu import ExceptionResponse
1824
1925from .const import (
2026 BATTERY_REG_BASE ,
@@ -528,6 +534,11 @@ async def modbus_read_holding_registers(self, unit, address, rcount):
528534
529535 sig = inspect .signature (self ._client .read_holding_registers )
530536
537+ _LOGGER .debug (
538+ f"I{ self ._rr_unit } : modbus_read_holding_registers "
539+ f"address={ self ._rr_address } count={ self ._rr_count } "
540+ )
541+
531542 if "device_id" in sig .parameters :
532543 result = await self ._client .read_holding_registers (
533544 address = self ._rr_address , count = self ._rr_count , device_id = self ._rr_unit
@@ -537,7 +548,11 @@ async def modbus_read_holding_registers(self, unit, address, rcount):
537548 address = self ._rr_address , count = self ._rr_count , slave = self ._rr_unit
538549 )
539550
551+ _LOGGER .debug (f"I{ self ._rr_unit } : result is error: { result .isError ()} " )
552+
540553 if result .isError ():
554+ _LOGGER .debug (f"I{ self ._rr_unit } : error result: { type (result )} " )
555+
541556 if type (result ) is ModbusIOException :
542557 raise ModbusIOError (result )
543558
0 commit comments