From 96ee7f4701f302bb1f551944e34877306ce7b240 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Fri, 10 Mar 2017 00:42:06 -0500 Subject: [PATCH] sample application for testing address strings --- samples/Address.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 samples/Address.py diff --git a/samples/Address.py b/samples/Address.py new file mode 100644 index 00000000..736557d0 --- /dev/null +++ b/samples/Address.py @@ -0,0 +1,39 @@ +#!/bin/bash python + +""" +This simple application takes a string form of a BACnet address from the +command line and attempts to interpret it. +""" + +import sys + +from bacpypes.consolelogging import ArgumentParser +from bacpypes.pdu import Address + +# build a parser for the command line arguments +parser = ArgumentParser(description=__doc__) +parser.add_argument("address", + help="address to interpret", + ) + +# parse the command line arguments +args = parser.parse_args() + +# try to interpret the address +try: + addr = Address(args.address) +except Exception as err: + print(err) + sys.exit(1) + +# print the string form +print(addr) + +# print the various components +for attr in [ + 'addrType', 'addrNet', 'addrAddr', 'addrLen', # universal + 'addrTuple', 'addrBroadcastTuple', # IPv4 + ]: + if hasattr(addr, attr): + print("%s: %r" % (attr, getattr(addr, attr))) +