如何解决当有COV通知时,如何在python3中使用BAC0触发函数 编辑以说明回调的使用,已添加到开发分支中
嗨,我用bacnet(BAC0库)和python 3开发了一个项目 这是我方法中的代码
// Connect in Lite Mode
self.bacnet = BAC0.connect(
ip='192.168.1.2'
)
self.bacnet.discover(networks='kNown')
tmp = self.bacnet.devices
my_controller = BAC0.device(address=tmp[0][2],device_id=tmp[0][3],network=self.bacnet)
points = my_controller.points
point = points[0]
numeric_point = self.GetNumericPoint(point)
// create a while for change value of point and trig COV notification
while True:
i = i + 1
numeric_point.write(i,prop="presentValue",priority="12")
value = numeric_point
time.sleep(1)
print('wait')
问题是当具有COV通知(值更改)时如何在python3中使用BAC0触发函数 谢谢。
解决方法
目前,COV仅在开发分支中实现。它将在下一个版本中发布,不知道何时发布。
您可以在任何时候订阅COV(如果您的设备支持的话)。收到通知后,将记录该点的历史记录,以便该点的lastValue准确。
默认情况下,声明已确认的COV。但是您也可以将其配置为生存期。
# This would declare a COV for a point.
device['point'].subscribe_cov(confirmed=False,lifetime=900)
# This would declare a COV outside the context of a device
bacnet.cov(address,objectID,confirmed=True,lifetime=None)
编辑以说明回调的使用,已添加到开发分支中
# The Notification will pass a variable named "elements" to the callback
# your function must include this argument
# elements is a dict containing all the information of the COV
def my_callback(elements):
print("Present value is : {}".format(elements['properties']['presentValue'])
bacnet.cov(address,lifetime=None,callback=my_callback)
objectID:具有(例如)“”的ObjectType”的元组。 (“ analogInput”,1)
文档中提供了更多信息: https://bac0.readthedocs.io/en/latest/cov.html?highlight=cov
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。