Skip to content

Commit 3d4f6c7

Browse files
authored
Updates due to examples test. (#1030)
1 parent c9462f7 commit 3d4f6c7

22 files changed

+95
-91
lines changed

examples/client_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ async def run_async_client(modbus_calls=None):
122122
"""Run sync client."""
123123
_logger.info("### Client ready")
124124
client = setup_async_client()
125-
await client.aStart()
125+
await client.aConnect()
126126
if modbus_calls:
127127
await modbus_calls(client.protocol)
128-
await client.aStop()
128+
await client.aClose()
129129
_logger.info("### End of Program")
130130

131131

examples/client_async_extended_calls.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ async def execute_diagnostic_requests(client):
107107
assert rr and not rr.isError() # test that calls was OK
108108

109109
_logger.info("Running ForceListenOnlyModeRequest")
110-
rr = await client.execute(
111-
ForceListenOnlyModeRequest(unit=UNIT)
112-
) # does not send a response
113-
assert rr and not rr.isError() # test that calls was OK
110+
_logger.info("NOT WORKING")
111+
_logger.info(str(ForceListenOnlyModeRequest))
112+
# rr = await client.execute(
113+
# ForceListenOnlyModeRequest(unit=UNIT)
114+
# ) # does not send a response
115+
# assert rr and not rr.isError() # test that calls was OK
114116

115117
_logger.info("Running ClearCountersRequest")
116118
rr = await client.execute(ClearCountersRequest())

examples/client_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def run_sync_client(modbus_calls=None):
119119
"""Run sync client."""
120120
_logger.info("### Client ready")
121121
client = setup_sync_client()
122-
client.start()
122+
client.connect()
123123
if modbus_calls:
124124
modbus_calls(client)
125-
client.stop() # pylint: disable=no-member
125+
client.close()
126126
_logger.info("### End of Program")
127127

128128

examples/client_sync_extended_calls.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ def execute_diagnostic_requests(client):
105105
assert rr and not rr.isError() # test that calls was OK
106106

107107
_logger.info("Running ForceListenOnlyModeRequest")
108-
rr = client.execute(
109-
ForceListenOnlyModeRequest(unit=UNIT)
110-
) # does not send a response
111-
assert rr and not rr.isError() # test that calls was OK
108+
_logger.info("NOT WORKING")
109+
_logger.info(str(ForceListenOnlyModeRequest))
110+
# rr = client.execute(
111+
# ForceListenOnlyModeRequest(unit=UNIT)
112+
# ) # does not send a response
113+
# assert rr and not rr.isError() # test that calls was OK
112114

113115
_logger.info("Running ClearCountersRequest")
114116
rr = client.execute(ClearCountersRequest())

examples/modbus_forwarder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def run_forwarder():
4141
context = ModbusServerContext(slaves=store, single=True)
4242

4343
# start forwarding client and server
44-
client.start()
44+
client.connect()
4545
StartTcpServer(context, address=("localhost", port_server))
4646
# loop forever
4747

examples/server_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def get_commandline():
286286
args.slaves = 0
287287
if not args.framer:
288288
args.framer = comm_defaults[args.comm][0]
289-
args.port = args.port or comm_defaults[args.comm]
289+
args.port = args.port or comm_defaults[args.comm][1]
290290
if args.comm != "serial":
291291
args.port = int(args.port)
292292
args.framer = framers[args.framer]

examples/server_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def get_commandline():
283283
args.slaves = 0
284284
if not args.framer:
285285
args.framer = comm_defaults[args.comm][0]
286-
args.port = args.port or comm_defaults[args.comm]
286+
args.port = args.port or comm_defaults[args.comm][1]
287287
if args.comm != "serial":
288288
args.port = int(args.port)
289289
args.framer = framers[args.framer]

pymodbus/client/async_serial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ async def run():
2525
# handle_local_echo=False,
2626
)
2727
28-
await client.aStart()
28+
await client.aConnect()
2929
...
30-
await client.aStop()
30+
await client.aClose()
3131
"""
3232
import asyncio
3333
import logging
@@ -81,7 +81,7 @@ def __init__(
8181
self.protocol = None
8282
self._connected_event = asyncio.Event()
8383

84-
async def aStop(self): # pylint: disable=invalid-name
84+
async def aClose(self):
8585
"""Stop connection."""
8686
if self._connected and self.protocol and self.protocol.transport:
8787
self.protocol.transport.close()
@@ -97,7 +97,7 @@ def _connected(self):
9797
"""Connect internal."""
9898
return self._connected_event.is_set()
9999

100-
async def aStart(self):
100+
async def aConnect(self):
101101
"""Connect Async client."""
102102
# get current loop, if there are no loop a RuntimeError will be raised
103103
self.loop = asyncio.get_running_loop()

pymodbus/client/async_tcp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ async def run():
2020
# source_address=("localhost", 0),
2121
)
2222
23-
await client.aStart()
23+
await client.aConnect()
2424
...
25-
await client.aStop()
25+
await client.aClose()
2626
"""
2727
import asyncio
2828
import logging
@@ -71,17 +71,17 @@ def reset_delay(self):
7171
"""Reset wait before next reconnect to minimal period."""
7272
self.delay_ms = self.DELAY_MIN_MS
7373

74-
async def aStart(self):
74+
async def aConnect(self):
7575
"""Initiate connection to start client."""
7676
# force reconnect if required:
77-
await self.aStop()
77+
await self.aClose()
7878
self.loop = asyncio.get_running_loop()
7979

8080
txt = f"Connecting to {self.params.host}:{self.params.port}."
8181
_logger.debug(txt)
8282
return await self._connect()
8383

84-
async def aStop(self): # pylint: disable=invalid-name
84+
async def aClose(self):
8585
"""Stop client."""
8686
# prevent reconnect:
8787
self.params.host = None

pymodbus/client/async_tls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ async def run():
2323
# password=None,
2424
# server_hostname="localhost",
2525
26-
await client.aStart()
26+
await client.aConnect()
2727
...
28-
await client.aStop()
28+
await client.aClose()
2929
"""
3030
import asyncio
3131
import logging
@@ -91,11 +91,11 @@ def __init__(
9191
self.server_hostname = server_hostname
9292
AsyncModbusTcpClient.__init__(self, host, port=port, framer=framer, **kwargs)
9393

94-
async def aStart(self):
94+
async def aConnect(self):
9595
"""Initiate connection to start client."""
9696
# get current loop, if there are no loop a RuntimeError will be raised
9797
self.loop = asyncio.get_running_loop()
98-
return await AsyncModbusTcpClient.start(self)
98+
return await AsyncModbusTcpClient.aConnect(self)
9999

100100
async def _connect(self):
101101
_logger.debug("Connecting.")

0 commit comments

Comments
 (0)