0

嗨,我用 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')

问题是如何在 python3 中使用 BAC0 触发函数,当通过 COV(值更改)通知时,谢谢。

4

1 回答 1

2

目前,COV 仅在开发分支中实现。下个版本会出,不知道什么时候。

您可以订阅任何点的 COV(如果您的设备支持)。当收到通知时,将写入点的历史记录,因此点的 lastValue 将是准确的。

默认情况下,confirmedCOV 被声明。但是您也可以将其配置为生命周期。

# 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, objectID, confirmed=True, lifetime=None, callback=my_callback)

objectID :带有 ("objectType", instance) 的元组,例如。(“模拟输入”,1)

文档中提供了更多信息: https ://bac0.readthedocs.io/en/latest/cov.html?highlight=cov

于 2020-10-18T18:34:31.707 回答