-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sample application for testing address strings
- Loading branch information
1 parent
54d0f44
commit 96ee7f4
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
|