Reputation: 641
Hi I developing a project with bacnet (BAC0 library) and python 3 and this is my code in my method
// 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')
And question is how to trig a function with BAC0 in python3 when has Notify by COV (Change of Value) Thanks.
Upvotes: 0
Views: 852
Reputation: 839
For now, COV is implemented in the develop branch only. It will be in the next release, don't know when.
You can subscribe to a COV for any point (if your device supports it). When the notification will be received, the history of the point will be written to so the lastValue of the point will be accurate.
By default, confirmedCOV are declared. But you can configure this, as lifetime too.
# 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 : a tuple with ("objectType", instance) ex. ("analogInput",1)
More information available in the documentation : https://bac0.readthedocs.io/en/latest/cov.html?highlight=cov
Upvotes: 2