Skip to content

Commit

Permalink
sample application for testing address strings
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBender committed Mar 10, 2017
1 parent 54d0f44 commit 96ee7f4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions samples/Address.py
Original file line number Diff line number Diff line change
@@ -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)))

0 comments on commit 96ee7f4

Please sign in to comment.