Skip to content

Commit ccce9e7

Browse files
committed
transport listen in server.
1 parent 71ceb06 commit ccce9e7

File tree

19 files changed

+437
-394
lines changed

19 files changed

+437
-394
lines changed

API_changes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Version 3.4.0
99
- Modbue<x>Server handler=, allow_reuse_addr=, backlog= are no longer accepted
1010
- ModbusTcpClient / AsyncModbusTcpClient no longer support unix path
1111
- StartAsyncUnixServer / ModbusUnixServer removed (never worked on Windows)
12-
- ModbusTlsServer reqclicert= is not longer accepted
12+
- ModbusTlsServer reqclicert= is no longer accepted
13+
- ModbusSerialServer auto_connect= is no longer accepted
1314

1415

1516
-------------

doc/source/library/simulator/config.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ Server configuration examples
104104
"parity": "N",
105105
"baudrate": 9600,
106106
"timeout": 3,
107-
"auto_reconnect": false,
108107
"reconnect_delay": 2,
109108
"framer": "rtu",
110109
"identity": {

examples/client_async.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
44
An example of a asynchronous client.
55
6-
usage: client_async.py [-h] [--comm {tcp,udp,serial,tls}]
7-
[--framer {ascii,binary,rtu,socket,tls}]
8-
[--log {critical,error,warning,info,debug}]
9-
[--port PORT]
6+
usage: client_async.py [-h] [-c {tcp,udp,serial,tls}]
7+
[-f {ascii,binary,rtu,socket,tls}]
8+
[-l {critical,error,warning,info,debug}] [-p PORT]
9+
[--baudrate BAUDRATE] [--host HOST]
10+
11+
Run asynchronous client.
12+
1013
options:
1114
-h, --help show this help message and exit
12-
--comm {tcp,udp,serial,tls}
13-
"serial", "tcp", "udp" or "tls"
14-
--framer {ascii,binary,rtu,socket,tls}
15-
"ascii", "binary", "rtu", "socket" or "tls"
16-
--log {critical,error,warning,info,debug}
17-
"critical", "error", "warning", "info" or "debug"
18-
--port PORT the port to use
19-
--baudrate BAUDRATE the baud rate to use for the serial device
15+
-c {tcp,udp,serial,tls}, --comm {tcp,udp,serial,tls}
16+
set communication, default is tcp
17+
-f {ascii,binary,rtu,socket,tls}, --framer {ascii,binary,rtu,socket,tls}
18+
set framer, default depends on --comm
19+
-l {critical,error,warning,info,debug}, --log {critical,error,warning,info,debug}
20+
set log level, default is info
21+
-p PORT, --port PORT set port
22+
--baudrate BAUDRATE set serial device baud rate
23+
--host HOST set host, default is 127.0.0.1
2024
2125
The corresponding server must be started before e.g. as:
2226
python3 server_sync.py

examples/client_sync.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
44
An example of a single threaded synchronous client.
55
6-
usage: client_sync.py [-h] [--comm {tcp,udp,serial,tls}]
7-
[--framer {ascii,binary,rtu,socket,tls}]
8-
[--log {critical,error,warning,info,debug}]
9-
[--port PORT]
6+
usage: client_sync.py [-h] [-c {tcp,udp,serial,tls}]
7+
[-f {ascii,binary,rtu,socket,tls}]
8+
[-l {critical,error,warning,info,debug}] [-p PORT]
9+
[--baudrate BAUDRATE] [--host HOST]
10+
11+
Run asynchronous client.
12+
1013
options:
1114
-h, --help show this help message and exit
12-
--comm {tcp,udp,serial,tls}
13-
"serial", "tcp", "udp" or "tls"
14-
--framer {ascii,binary,rtu,socket,tls}
15-
"ascii", "binary", "rtu", "socket" or "tls"
16-
--log {critical,error,warning,info,debug}
17-
"critical", "error", "warning", "info" or "debug"
18-
--port PORT the port to use
19-
--baudrate BAUDRATE the baud rate to use for the serial device
15+
-c {tcp,udp,serial,tls}, --comm {tcp,udp,serial,tls}
16+
set communication, default is tcp
17+
-f {ascii,binary,rtu,socket,tls}, --framer {ascii,binary,rtu,socket,tls}
18+
set framer, default depends on --comm
19+
-l {critical,error,warning,info,debug}, --log {critical,error,warning,info,debug}
20+
set log level, default is info
21+
-p PORT, --port PORT set port
22+
--baudrate BAUDRATE set serial device baud rate
23+
--host HOST set host, default is 127.0.0.1
2024
2125
The corresponding server must be started before e.g. as:
2226
python3 server_sync.py

examples/helper.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def get_commandline(server=False, description=None, extras=None, cmdline=None):
6363
default=9600,
6464
type=int,
6565
)
66+
parser.add_argument(
67+
"--host",
68+
help="set host, default is 127.0.0.1",
69+
dest="host",
70+
default=None,
71+
type=str,
72+
)
6673
if server:
6774
parser.add_argument(
6875
"--store",
@@ -83,14 +90,6 @@ def get_commandline(server=False, description=None, extras=None, cmdline=None):
8390
help="ADVANCED USAGE: set datastore context object",
8491
default=None,
8592
)
86-
else:
87-
parser.add_argument(
88-
"--host",
89-
help="set host, default is 127.0.0.1",
90-
dest="host",
91-
default="127.0.0.1",
92-
type=str,
93-
)
9493
if extras:
9594
for extra in extras:
9695
parser.add_argument(extra[0], **extra[1])
@@ -116,6 +115,8 @@ def get_commandline(server=False, description=None, extras=None, cmdline=None):
116115
args.port = args.port or comm_defaults[args.comm][1]
117116
if args.comm != "serial" and args.port:
118117
args.port = int(args.port)
118+
if not args.host:
119+
args.host = "" if server else "127.0.0.1"
119120
return args
120121

121122

examples/server_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def run_async_server(args):
145145
txt = f"### start ASYNC server, listening on {args.port} - {args.comm}"
146146
_logger.info(txt)
147147
if args.comm == "tcp":
148-
address = ("", args.port) if args.port else None
148+
address = (args.host if args.host else "", args.port if args.port else None)
149149
server = await StartAsyncTcpServer(
150150
context=args.context, # Data storage
151151
identity=args.identity, # server identify
@@ -160,7 +160,10 @@ async def run_async_server(args):
160160
# TBD strict=True, # use strict timing, t1.5 for Modbus RTU
161161
)
162162
elif args.comm == "udp":
163-
address = ("127.0.0.1", args.port) if args.port else None
163+
address = (
164+
args.host if args.host else "127.0.0.1",
165+
args.port if args.port else None,
166+
)
164167
server = await StartAsyncUdpServer(
165168
context=args.context, # Data storage
166169
identity=args.identity, # server identify
@@ -192,7 +195,7 @@ async def run_async_server(args):
192195
# strict=True, # use strict timing, t1.5 for Modbus RTU
193196
)
194197
elif args.comm == "tls":
195-
address = ("", args.port) if args.port else None
198+
address = (args.host if args.host else "", args.port if args.port else None)
196199
server = await StartAsyncTlsServer(
197200
context=args.context, # Data storage
198201
host="localhost", # define tcp address where to connect to.

0 commit comments

Comments
 (0)