-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_basic_usage.py
More file actions
30 lines (24 loc) · 878 Bytes
/
server_basic_usage.py
File metadata and controls
30 lines (24 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
!/usr/bin/env python3
"""
Modbus/TCP server
~~~~~~~~~~~~~~~~~
Run this as root to listen on TCP privileged ports (<= 1024).
Add "--host 0.0.0.0" to listen on all available IPv4 addresses of the host.
$ sudo ./server.py --host 0.0.0.0
"""
import argparse
import logging
from pyModbusTCP.server import ModbusServer
# init logging
logging.basicConfig()
# parse args
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', type=str, default='localhost', help='Host (default: localhost)')
parser.add_argument('-p', '--port', type=int, default=502, help='TCP port (default: 502)')
parser.add_argument('-d', '--debug', action='store_true', help='set debug mode')
args = parser.parse_args()
# logging setup
if args.debug:
logging.getLogger('pyModbusTCP.server').setLevel(logging.DEBUG)
# start modbus server
server = ModbusServer(host=args.host, port=args.port)