BAC0

BAC0 is a script module based on bacpypes (https://github.com/JoelBender/bacpypes.git) to automate task using Bacnet/IP protocole. It's mainly targetted as a tool to test sequences on DDC controlelrs using bacnet.

Using the simplciity of python, the power of pandas, it's easy to test and keep a trace of the history of each points.

How to use

First you must install the 2 modules pip install bacpypes

Note : All tests have been done in Windows 7 using Anaconda3 (http://continuum.io/downloads)

Import module


In [1]:
import BAC0
import pandas as pd
%matplotlib inline
# Define network and connect to it
bacnet = BAC0.connect()


/home/pi/miniconda3/lib/python3.4/importlib/_bootstrap.py:321: FutureWarning: The pandas.lib module is deprecated and will be removed in a future version. These are private functions and can be accessed from pandas._libs.lib instead
  return f(*args, **kwds)
xlwings not installed. If using Windows or OSX, install to get more features.
Using ip : 192.168.111.13
Click here to open Live Trending Web Page
http://localhost:5006/?bokeh-session-id=0v2rWfXDL7ipg0yn3TfR8nJX35jfOners4zsE2pIaENq
Failed running bokeh serve
Bokeh server already running

In [ ]:
BAC0.version

In [ ]:
# Define the controller using : controller = BAC0.device(address, device_id, network)
fx = BAC0.device('2:5',5,bacnet)

In [ ]:
# Access points list
fx.points

In [ ]:
# Create a table with multiple points

lst = ['nvoAI1', 'nvoAI2', 'nvoDI1']

fx.df(lst).fillna(method='ffill')

In [ ]:
# Create a trend with multiple points using the DataFrame

lst = ['nvoAI1', 'nvoAI2']


fx.df(lst).resample('1min').plot(title='My title')

In [ ]:
fx.chart(lst, title='My title')

In [ ]:
fx.notes = 'New note to remember'
fx.notes

In [ ]:
fx

Finding devices on a network


In [ ]:
bacnet.whois() # Note that this function is called automatically in ReadWriteScript

# The result takes a few milliseconds to be processed... it can be used in the same cell.

Using the bacnet object to read or write objects from devices

Accessing the list of object of a device can be done using the objectList property


In [ ]:
# Let's print the first 10 objects...
bacnet.read('2:5 device 5 objectList')[:10]

In [ ]:
bacnet.readMultiple('2:5 analogInput 1 objectName description presentValue units')

In [ ]:
import time
obj = '2:5 analogValue 41 presentValue'
old_value = bacnet.read(obj)
print('Old Value is : %s' % old_value)
new_value = 120

bacnet.write('%s %s' % (obj,new_value))
print('New value is %s' % bacnet.read(obj))

Stopping the app


In [ ]:
bacnet.disconnect()