Skip to content

Commit

Permalink
Extend TransactionManager to handle sync. (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Nov 17, 2024
1 parent 3378a73 commit 975809c
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 382 deletions.
21 changes: 11 additions & 10 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pymodbus.framer import FRAMER_NAME_TO_CLASS, FramerBase, FramerType
from pymodbus.logging import Log
from pymodbus.pdu import DecodePDU, ModbusPDU
from pymodbus.transaction import SyncModbusTransactionManager
from pymodbus.transaction import TransactionManager
from pymodbus.transport import CommParams
from pymodbus.utilities import ModbusTransactionState

Expand All @@ -27,15 +27,14 @@ def __init__(
framer: FramerType,
retries: int,
on_connect_callback: Callable[[bool], None] | None,
comm_params: CommParams | None = None,
comm_params: CommParams,
) -> None:
"""Initialize a client instance.
:meta private:
"""
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
if comm_params:
self.comm_params = comm_params
self.comm_params = comm_params
self.ctx = ModbusClientProtocol(
(FRAMER_NAME_TO_CLASS[framer])(DecodePDU(False)),
self.comm_params,
Expand Down Expand Up @@ -116,23 +115,25 @@ def __init__(
self,
framer: FramerType,
retries: int,
comm_params: CommParams | None = None,
comm_params: CommParams,
) -> None:
"""Initialize a client instance.
:meta private:
"""
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
if comm_params:
self.comm_params = comm_params
self.comm_params = comm_params
self.retries = retries
self.slaves: list[int] = []

# Common variables.
self.framer: FramerBase = (FRAMER_NAME_TO_CLASS[framer])(DecodePDU(False))
self.transaction = SyncModbusTransactionManager(
self.transaction = TransactionManager(
self.comm_params,
self.framer,
retries,
False,
self,
self.retries,
)
self.reconnect_delay_current = self.comm_params.reconnect_delay or 0
self.use_udp = False
Expand Down Expand Up @@ -177,7 +178,7 @@ def execute(self, no_response_expected: bool, request: ModbusPDU) -> ModbusPDU:
"""
if not self.connect():
raise ConnectionException(f"Failed to connect[{self!s}]")
return self.transaction.execute(no_response_expected, request)
return self.transaction.sync_execute(no_response_expected, request)

# ----------------------------------------------------------------------- #
# Internal methods
Expand Down
2 changes: 2 additions & 0 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__( # pylint: disable=too-many-arguments
framer,
retries,
on_connect_callback,
self.comm_params,
)


Expand Down Expand Up @@ -185,6 +186,7 @@ def __init__( # pylint: disable=too-many-arguments
super().__init__(
framer,
retries,
self.comm_params,
)
if "serial" not in sys.modules:
raise RuntimeError(
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__( # pylint: disable=too-many-arguments
framer,
retries,
on_connect_callback,
self.comm_params,
)


Expand Down Expand Up @@ -154,7 +155,7 @@ def __init__(
reconnect_delay_max=reconnect_delay_max,
timeout_connect=timeout,
)
super().__init__(framer, retries)
super().__init__(framer, retries, self.comm_params)
self.socket = None

@property
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__( # pylint: disable=too-many-arguments
framer,
retries,
on_connect_callback,
self.comm_params,
)
self.source_address = source_address

Expand Down Expand Up @@ -155,7 +156,7 @@ def __init__(
reconnect_delay_max=reconnect_delay_max,
timeout_connect=timeout,
)
super().__init__(framer, retries)
super().__init__(framer, retries, self.comm_params)
self.socket = None

@property
Expand Down
6 changes: 0 additions & 6 deletions pymodbus/transaction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
"""Transaction."""
__all__ = [
"ModbusTransactionManager",
"SyncModbusTransactionManager",
"TransactionManager",
]

from pymodbus.transaction.old_transaction import (
ModbusTransactionManager,
SyncModbusTransactionManager,
)
from pymodbus.transaction.transaction import TransactionManager
213 changes: 0 additions & 213 deletions pymodbus/transaction/old_transaction.py

This file was deleted.

Loading

0 comments on commit 975809c

Please sign in to comment.