Skip to content

Commit 8fcbbf4

Browse files
authored
Do not initialize framer twice. (#1153)
1 parent 08106d6 commit 8fcbbf4

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ 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(
79+
framer=self.params.framer, xframer=self.framer, **self.params.kwargs
80+
)
7981
protocol.factory = self
8082
return protocol
8183

pymodbus/client/udp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ 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,
100+
framer=self.params.framer,
101+
xframer=self.framer,
102+
**self.params.kwargs,
100103
)
101104
protocol.params.host = host
102105
protocol.params.port = port

0 commit comments

Comments
 (0)