Skip to content

Commit 975809c

Browse files
authored
Extend TransactionManager to handle sync. (#2457)
1 parent 3378a73 commit 975809c

File tree

11 files changed

+209
-382
lines changed

11 files changed

+209
-382
lines changed

pymodbus/client/base.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pymodbus.framer import FRAMER_NAME_TO_CLASS, FramerBase, FramerType
1212
from pymodbus.logging import Log
1313
from pymodbus.pdu import DecodePDU, ModbusPDU
14-
from pymodbus.transaction import SyncModbusTransactionManager
14+
from pymodbus.transaction import TransactionManager
1515
from pymodbus.transport import CommParams
1616
from pymodbus.utilities import ModbusTransactionState
1717

@@ -27,15 +27,14 @@ def __init__(
2727
framer: FramerType,
2828
retries: int,
2929
on_connect_callback: Callable[[bool], None] | None,
30-
comm_params: CommParams | None = None,
30+
comm_params: CommParams,
3131
) -> None:
3232
"""Initialize a client instance.
3333
3434
:meta private:
3535
"""
3636
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
37-
if comm_params:
38-
self.comm_params = comm_params
37+
self.comm_params = comm_params
3938
self.ctx = ModbusClientProtocol(
4039
(FRAMER_NAME_TO_CLASS[framer])(DecodePDU(False)),
4140
self.comm_params,
@@ -116,23 +115,25 @@ def __init__(
116115
self,
117116
framer: FramerType,
118117
retries: int,
119-
comm_params: CommParams | None = None,
118+
comm_params: CommParams,
120119
) -> None:
121120
"""Initialize a client instance.
122121
123122
:meta private:
124123
"""
125124
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
126-
if comm_params:
127-
self.comm_params = comm_params
125+
self.comm_params = comm_params
128126
self.retries = retries
129127
self.slaves: list[int] = []
130128

131129
# Common variables.
132130
self.framer: FramerBase = (FRAMER_NAME_TO_CLASS[framer])(DecodePDU(False))
133-
self.transaction = SyncModbusTransactionManager(
131+
self.transaction = TransactionManager(
132+
self.comm_params,
133+
self.framer,
134+
retries,
135+
False,
134136
self,
135-
self.retries,
136137
)
137138
self.reconnect_delay_current = self.comm_params.reconnect_delay or 0
138139
self.use_udp = False
@@ -177,7 +178,7 @@ def execute(self, no_response_expected: bool, request: ModbusPDU) -> ModbusPDU:
177178
"""
178179
if not self.connect():
179180
raise ConnectionException(f"Failed to connect[{self!s}]")
180-
return self.transaction.execute(no_response_expected, request)
181+
return self.transaction.sync_execute(no_response_expected, request)
181182

182183
# ----------------------------------------------------------------------- #
183184
# Internal methods

pymodbus/client/serial.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__( # pylint: disable=too-many-arguments
103103
framer,
104104
retries,
105105
on_connect_callback,
106+
self.comm_params,
106107
)
107108

108109

@@ -185,6 +186,7 @@ def __init__( # pylint: disable=too-many-arguments
185186
super().__init__(
186187
framer,
187188
retries,
189+
self.comm_params,
188190
)
189191
if "serial" not in sys.modules:
190192
raise RuntimeError(

pymodbus/client/tcp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__( # pylint: disable=too-many-arguments
8484
framer,
8585
retries,
8686
on_connect_callback,
87+
self.comm_params,
8788
)
8889

8990

@@ -154,7 +155,7 @@ def __init__(
154155
reconnect_delay_max=reconnect_delay_max,
155156
timeout_connect=timeout,
156157
)
157-
super().__init__(framer, retries)
158+
super().__init__(framer, retries, self.comm_params)
158159
self.socket = None
159160

160161
@property

pymodbus/client/udp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__( # pylint: disable=too-many-arguments
8585
framer,
8686
retries,
8787
on_connect_callback,
88+
self.comm_params,
8889
)
8990
self.source_address = source_address
9091

@@ -155,7 +156,7 @@ def __init__(
155156
reconnect_delay_max=reconnect_delay_max,
156157
timeout_connect=timeout,
157158
)
158-
super().__init__(framer, retries)
159+
super().__init__(framer, retries, self.comm_params)
159160
self.socket = None
160161

161162
@property

pymodbus/transaction/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
"""Transaction."""
22
__all__ = [
3-
"ModbusTransactionManager",
4-
"SyncModbusTransactionManager",
53
"TransactionManager",
64
]
75

8-
from pymodbus.transaction.old_transaction import (
9-
ModbusTransactionManager,
10-
SyncModbusTransactionManager,
11-
)
126
from pymodbus.transaction.transaction import TransactionManager

pymodbus/transaction/old_transaction.py

Lines changed: 0 additions & 213 deletions
This file was deleted.

0 commit comments

Comments
 (0)