2

I would like to implement a simple loop for extracting my bacnet values all together without asking each one by one but getting an error. Or, is there any better way to fetch all the values together? Can anyone help, please? Thanks! Here is my code (this works):

import BAC0
bacnet = BAC0.connect()

a = bacnet.read('10.1.1.9 analogValue 1 presentValue')
print(a)

But this does not work:

import BAC0
bacnet = BAC0.connect()

i = 0
for i = i+1:
    a = bacnet.read('10.1.1.9 analogValue % i presentValue')
    print(a)
end

It gives the error:

ValueError: invalid literal for int() with base 10: '%'

Okay, I found the solution as:

for i in range(1,5):
a = bacnet.read('10.1.1.9 analogValue {} presentValue'.format(i))
print(a)
Hossain
  • 235
  • 1
  • 3
  • 15

1 Answers1

3

This will retrieve only analogValues... if it’s what you want. But a more global approach would be to use the BAC0.device approach.

You will need the BACnet ID of the device to define it :

import BAC0
bacnet = BAC0.lite()
deviceID = 1000 # example
dev = BAC0.device(‘10.1.1.9’, deviceID,bacnet,poll=30)
dev.points #will give you all points on which you can iterate if you want...

This will create a device named “dev” on which you will be able to interact with a lot of properties. By default, BAC0 will define AI,AV,AO,BI,BV,BO,MV,TrendLogs.

You will also be able to get information on a points or write to them using the square bracket syntax :

dev[“NameOfPoint”]
#Let’s pretend a point is named HTG-O
dev[“HTG-O”] = 100 #this will override the output
dev[“HTG-O”].value # will output the value to be used in some calculation

dev.properties #will give you more details on the point itself

Using this method will assure you that ReadPropertyMultiple will be used to read all the points. This means a lot less network requests (and more speed). You will also get the units for each analog points... and the state text for each multistate ones...and the description, etc.

The poll=30 will tell BAC0 to read all the variables every 30 seconds... so you can choose what fits your need. Using 0 will disable the polling. Default is 10.

Each time a value is polled, it will be saved in the point history so you can retrieve all the values using :

dev[“YourPoint”].history
# This will give you a Pandas series ready to be used

If you want to interact with a device having a lot of points (>1000) you will probably want to disable the polling, maybe disable segmentation if required... but the best, would be to build a custom object list with the variables you want. No more.

See here for details : https://bac0.readthedocs.io/en/latest/controller.html