Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend TransactionManager to handle sync. #2457

Merged
merged 8 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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