Skip to content

Commit 740e94b

Browse files
committed
Do not initialize framer twice.
1 parent 08106d6 commit 740e94b

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

pymodbus/client/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def __init__(
119119
self.params.kwargs = kwargs
120120

121121
# Common variables.
122-
self.framer = self.params.framer(ClientDecoder(), self)
122+
if xframer := kwargs.get("xframer", None):
123+
self.framer = xframer
124+
else:
125+
self.framer = self.params.framer(ClientDecoder(), self)
123126
self.transaction = DictTransactionManager(self, **kwargs)
124127
self.delay_ms = self.params.reconnect_delay
125128
self.use_protocol = hasattr(self, "protocol")

pymodbus/client/serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def close(self): # pylint: disable=invalid-overridden-method
8181

8282
def _create_protocol(self):
8383
"""Create protocol."""
84-
protocol = ModbusClientProtocol(framer=self.params.framer)
84+
protocol = ModbusClientProtocol(framer=self.params.framer, xframer=self.framer)
8585
protocol.factory = self
8686
return protocol
8787

pymodbus/client/tcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def close(self): # pylint: disable=invalid-overridden-method
7575

7676
def _create_protocol(self):
7777
"""Create initialized protocol instance with factory function."""
78-
protocol = ModbusClientProtocol(framer=self.params.framer, **self.params.kwargs)
78+
protocol = ModbusClientProtocol(framer=self.params.framer, xframer=self.framer, **self.params.kwargs)
7979
protocol.factory = self
8080
return protocol
8181

pymodbus/client/udp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def close(self): # pylint: disable=invalid-overridden-method
9696
def _create_protocol(self, host=None, port=0):
9797
"""Create initialized protocol instance with factory function."""
9898
protocol = ModbusClientProtocol(
99-
use_udp=True, framer=self.params.framer, **self.params.kwargs
99+
use_udp=True, framer=self.params.framer, xframer=self.framer, **self.params.kwargs
100100
)
101101
protocol.params.host = host
102102
protocol.params.port = port

0 commit comments

Comments
 (0)