mirror of
https://github.com/JoelBender/modpypes
synced 2025-10-19 22:08:20 +08:00
host and port options that can be overridden
This commit is contained in:
parent
25ab8f52bf
commit
46740fc139
|
|
@ -67,8 +67,17 @@ class ConsoleClient(ConsoleCmd, Client):
|
||||||
print("address, unit and register required")
|
print("address, unit and register required")
|
||||||
return
|
return
|
||||||
|
|
||||||
# get the address and unit
|
# get the address and unit, and register
|
||||||
addr, unitID, register = args[:3]
|
addr, unitID, register = args[:3]
|
||||||
|
|
||||||
|
# address might have a port
|
||||||
|
if ':' in addr:
|
||||||
|
addr, port = addr.split(':')
|
||||||
|
server_address = (addr, int(port))
|
||||||
|
else:
|
||||||
|
server_address = (addr, 502)
|
||||||
|
|
||||||
|
# unit identifier
|
||||||
unitID = int(unitID)
|
unitID = int(unitID)
|
||||||
if _debug: ConsoleClient._debug(" - addr, unitID: %r, %r", addr, unitID)
|
if _debug: ConsoleClient._debug(" - addr, unitID: %r, %r", addr, unitID)
|
||||||
|
|
||||||
|
|
@ -114,7 +123,7 @@ class ConsoleClient(ConsoleCmd, Client):
|
||||||
return
|
return
|
||||||
|
|
||||||
# set the destination
|
# set the destination
|
||||||
req.pduDestination = (addr, 502)
|
req.pduDestination = server_address
|
||||||
req.mpduUnitID = unitID
|
req.mpduUnitID = unitID
|
||||||
if _debug: ConsoleClient._debug(" - req: %r", req)
|
if _debug: ConsoleClient._debug(" - req: %r", req)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Server
|
|
||||||
======
|
|
||||||
|
|
||||||
This executable module is a console application for presenting itself as a
|
This executable module is a console application for presenting itself as a
|
||||||
MODBUS server accepting read and write MODBUS PDUs.
|
MODBUS server accepting read and write MODBUS PDUs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
|
from bacpypes.debugging import bacpypes_debugging, ModuleLogger
|
||||||
|
|
@ -29,6 +27,9 @@ from .app import ModbusServer, ModbusException
|
||||||
_debug = 0
|
_debug = 0
|
||||||
_log = ModuleLogger(globals())
|
_log = ModuleLogger(globals())
|
||||||
|
|
||||||
|
# settings
|
||||||
|
SERVER_HOST = os.getenv("SERVER_HOST", "")
|
||||||
|
SERVER_PORT = int(os.getenv("SERVER_PORT", 502))
|
||||||
|
|
||||||
#
|
#
|
||||||
# ConsoleServer
|
# ConsoleServer
|
||||||
|
|
@ -53,15 +54,23 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def main():
|
def main():
|
||||||
# parse the command line arguments
|
# parse the command line arguments
|
||||||
parser = ArgumentParser(description=__doc__)
|
parser = ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument(
|
||||||
# now parse the arguments
|
"--host", type=str,
|
||||||
|
help="address of host (default {!r})".format(SERVER_HOST),
|
||||||
|
default=SERVER_HOST,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--port", type=int,
|
||||||
|
help="server port (default {!r})".format(SERVER_PORT),
|
||||||
|
default=SERVER_PORT,
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if _debug: _log.debug("initialization")
|
if _debug: _log.debug("initialization")
|
||||||
if _debug: _log.debug(" - args: %r", args)
|
if _debug: _log.debug(" - args: %r", args)
|
||||||
|
|
||||||
# local IO functions
|
# local IO functions
|
||||||
bind(ConsoleServer(), ModbusServer())
|
bind(ConsoleServer(), ModbusServer(port=args.port))
|
||||||
|
|
||||||
_log.debug("running")
|
_log.debug("running")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user