Skip to content

Commit 2ac85da

Browse files
Szewcsonjaniversen
authored andcommitted
Fix exception error message for decoding response (#2618)
1 parent d537f87 commit 2ac85da

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pymodbus/pdu/pdu.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from pymodbus.datastore import ModbusSlaveContext
99
from pymodbus.exceptions import NotImplementedException
10-
from pymodbus.logging import Log
1110

1211

1312
class ModbusPDU:
@@ -57,7 +56,7 @@ def verifyAddress(self, address: int = -1) -> None:
5756
raise ValueError(f"0 < address {address} < 65535 !")
5857

5958
def __str__(self) -> str:
60-
"""Build a representation of an exception response."""
59+
"""Build a representation of a Modbus response."""
6160
return (
6261
f"{self.__class__.__name__}("
6362
f"dev_id={self.dev_id}, "
@@ -126,7 +125,15 @@ def __init__(
126125
super().__init__(transaction_id=transaction, dev_id=slave)
127126
self.function_code = function_code | 0x80
128127
self.exception_code = exception_code
129-
Log.error(f"Exception response {self.function_code} / {self.exception_code}")
128+
129+
def __str__(self) -> str:
130+
"""Build a representation of an exception response."""
131+
return (
132+
f"{self.__class__.__name__}("
133+
f"dev_id={self.dev_id}, "
134+
f"function_code={self.function_code}, "
135+
f"exception_code={self.exception_code})"
136+
)
130137

131138
def encode(self) -> bytes:
132139
"""Encode a modbus exception response."""

0 commit comments

Comments
 (0)