Skip to content

Commit

Permalink
Change to "sync client" in forwarder example (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredo70 authored Jun 23, 2023
1 parent 2be46d0 commit 5273bf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
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

0 comments on commit 5273bf1

Please sign in to comment.