Created
October 20, 2020 02:31
-
-
Save JoelBender/8533c0750a12df81a723584fde76f2c8 to your computer and use it in GitHub Desktop.
Simple way of serving analog value objects
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
#!/usr/bin/env python | |
""" | |
This sample application shows how to create analog value objects with | |
different values. | |
""" | |
import os | |
import random | |
from bacpypes.debugging import bacpypes_debugging, ModuleLogger | |
from bacpypes.consolelogging import ConfigArgumentParser | |
from bacpypes.core import run | |
from bacpypes.primitivedata import Real | |
from bacpypes.object import AnalogValueObject, Property, register_object_type | |
from bacpypes.errors import ExecutionError | |
from bacpypes.app import BIPSimpleApplication | |
from bacpypes.local.device import LocalDeviceObject | |
# some debugging | |
_debug = 0 | |
_log = ModuleLogger(globals()) | |
# settings | |
OBJECT_COUNT = int(os.getenv("OBJECT_COUNT", 10)) | |
# | |
# __main__ | |
# | |
def main(): | |
# parse the command line arguments | |
args = ConfigArgumentParser(description=__doc__).parse_args() | |
_log.debug("initialization") | |
_log.debug(" - args: %r", args) | |
# make a device object | |
this_device = LocalDeviceObject( | |
objectName=args.ini.objectname, | |
objectIdentifier=("device", int(args.ini.objectidentifier)), | |
maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted), | |
segmentationSupported=args.ini.segmentationsupported, | |
vendorIdentifier=int(args.ini.vendoridentifier), | |
) | |
# make a sample application | |
this_application = BIPSimpleApplication(this_device, args.ini.address) | |
# make some random input objects | |
for i in range(1, OBJECT_COUNT + 1): | |
avo = AnalogValueObject( | |
objectIdentifier=("analogValue", i), | |
objectName="value_%d" % (i,), | |
presentValue=i * 10.0, | |
) | |
_log.debug(" - avo: %r", avo) | |
this_application.add_object(avo) | |
# make sure they are all there | |
_log.debug(" - object list: %r", this_device.objectList) | |
_log.debug("running") | |
run() | |
_log.debug("fini") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment