Created
July 22, 2021 03:20
-
-
Save JoelBender/e7de20c9b207bc3988e38b6d289c5a1b to your computer and use it in GitHub Desktop.
AnalogValueObject with a writable object name
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
""" | |
Writable Analog Value Object | |
""" | |
from bacpypes.errors import ExecutionError | |
from bacpypes.primitivedata import Real, CharacterString | |
from bacpypes.basetypes import EngineeringUnits | |
from bacpypes.object import register_object_type, WritableProperty, AnalogValueObject | |
# from bacpypes.consolelogging import ConsoleLogHandler | |
# ConsoleLogHandler("bacpypes.object") | |
print("AnalogValueObject properties") | |
print(" - objectName: %r" % (AnalogValueObject._properties['objectName'],)) | |
print(" - presentValue: %r" % (AnalogValueObject._properties['presentValue'],)) | |
# create an instance | |
avo = AnalogValueObject() | |
# peek at the property object | |
avo_object_name = avo._attr_to_property("objectName") | |
print("avo_object_name: %r" % (avo_object_name,)) | |
print(" - identifier: %r" % (avo_object_name.identifier,)) | |
print(" - datatype: %r" % (avo_object_name.datatype,)) | |
print(" - optional: %r" % (avo_object_name.optional,)) | |
print(" - mutable: %r" % (avo_object_name.mutable,)) | |
print(" - default: %r" % (avo_object_name.default,)) | |
print("") | |
try: | |
# writing fails | |
avo.WriteProperty("objectName", "avo sample") | |
except ExecutionError: | |
print("failed correctly") | |
avo.debug_contents() | |
print("") | |
@register_object_type() | |
class WritableAnalogValueObject(AnalogValueObject): | |
properties = [ | |
WritableProperty("objectName", CharacterString, optional=False), | |
] | |
print("WritableAnalogValueObject properties") | |
print(" - objectName: %r" % (WritableAnalogValueObject._properties['objectName'],)) | |
print(" - presentValue: %r" % (WritableAnalogValueObject._properties['presentValue'],)) | |
wavo = WritableAnalogValueObject() | |
wavo_object_name = wavo._attr_to_property("objectName") | |
print("wavo_object_name: %r" % (wavo_object_name,)) | |
print(" - identifier: %r" % (wavo_object_name.identifier,)) | |
print(" - datatype: %r" % (wavo_object_name.datatype,)) | |
print(" - optional: %r" % (wavo_object_name.optional,)) | |
print(" - mutable: %r" % (wavo_object_name.mutable,)) | |
print(" - default: %r" % (wavo_object_name.default,)) | |
print("") | |
# writing succeeds | |
wavo.WriteProperty("objectName", "wavo sample") | |
wavo.debug_contents() | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment