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

Change to "sync client" in forwarder example #1625

Merged
merged 1 commit into from
Jun 23, 2023
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
8 changes: 4 additions & 4 deletions examples/modbus_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging

from examples import helper
from pymodbus.client import AsyncModbusTcpClient
from pymodbus.client import ModbusTcpClient
from pymodbus.datastore import ModbusServerContext
from pymodbus.datastore.remote import RemoteSlaveContext
from pymodbus.server import StartAsyncTcpServer
Expand All @@ -40,11 +40,11 @@ async def run_forwarder(args):
txt = f"### start forwarder, listen {args.port}, connect to {args.client_port}"
_logger.info(txt)

args.client = AsyncModbusTcpClient(
args.client = ModbusTcpClient(
host="localhost",
port=args.client_port,
)
await args.client.connect()
args.client.connect()
assert args.client.connected
# If required to communicate with a specified client use slave=<slave_id>
# in RemoteSlaveContext
Expand All @@ -58,7 +58,7 @@ async def run_forwarder(args):
store = RemoteSlaveContext(args.client, slave=1)
args.context = ModbusServerContext(slaves=store, single=True)

await StartAsyncTcpServer(context=args.context, address=("localhost", args.port))
await StartAsyncTcpServer(context=args.context, address=("", args.port))
# loop forever


Expand Down
3 changes: 1 addition & 2 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __init__(
**kwargs: Any,
) -> None:
"""Initialize Modbus TCP Client."""
self.transport = None
super().__init__(framer=framer, **kwargs)
self.params.host = host
self.params.port = port
Expand All @@ -123,7 +122,7 @@ def __init__(
@property
def connected(self):
"""Connect internal."""
return self.transport is not None
return self.socket is not None

def connect(self): # pylint: disable=invalid-overridden-method
"""Connect to the modbus tcp server."""
Expand Down