BAC0.scripts package

Submodules

BAC0.scripts.Base module

BasicScript - implement the BAC0.core.app.ScriptApplication Its basic function is to start and stop the bacpypes stack. Stopping the stack, frees the IP socket used for BACnet communications. No communications will occur if the stack is stopped.

Bacpypes stack enables Whois and Iam functions, since this minimum is needed to be a BACnet device. Other stack services can be enabled later (via class inheritance). [see: see BAC0.scripts.ReadWriteScript]

Class::
BasicScript(WhoisIAm)
def startApp() def stopApp()
class BAC0.scripts.Base.Base(localIPAddr='127.0.0.1', networkNumber=None, localObjName='BAC0', deviceId=None, firmwareRevision='3.7.9 (default, May 10 2023, 17:48:33) n[GCC 7.5.0]', maxAPDULengthAccepted='1024', maxSegmentsAccepted='1024', segmentationSupported='segmentedBoth', bbmdAddress=None, bbmdTTL=0, bdtable=None, modelName='BAC0 Scripting Tool', vendorId=842, vendorName='SERVISYS inc.', description='http://christiantremblay.github.io/BAC0/', location='Bromont, Québec', spin=None)[source]

Bases: object

Build a running BACnet/IP device that accepts WhoIs and IAm requests Initialization requires some minimial information about the local device.

Parameters:
  • localIPAddr='127.0.0.1'
  • localObjName='BAC0'
  • deviceId=None
  • maxAPDULengthAccepted='1024'
  • maxSegmentsAccepted='1024'
  • segmentationSupported='segmentedBoth'
clear_notes()

Clear notes object

disconnect()[source]

Stop the BACnet stack. Free the IP socket.

discoveredNetworks
log(note, *, level=10)

Add a log entry…no note

log_subtitle(subtitle, args=None, width=35)
log_title(title, args=None, width=35)
logname = 'BAC0.scripts.Base | Base'
note(note, *, level=20, log=True)

Add note to the object. By default, the note will also be logged :param note: (str) The note itself :param level: (logging.level) :param log: (boolean) Enable or disable logging of note

notes

Retrieve notes list as a Pandas Series

register_foreign_device(addr=None, ttl=0)[source]
routing_table

Routing Table will give all the details about routers and how they connect BACnet networks together.

It’s a decoded presentation of what bacpypes.router_info_cache contains.

Returns a dict with the address of routers as key.

startApp()[source]

Define the local device, including services supported. Once defined, start the BACnet stack in its own thread.

unregister_foreign_device()[source]
class BAC0.scripts.Base.LocalObjects(device)[source]

Bases: object

clear_notes()

Clear notes object

log(note, *, level=10)

Add a log entry…no note

log_subtitle(subtitle, args=None, width=35)
log_title(title, args=None, width=35)
logname = 'BAC0.scripts.Base | LocalObjects'
note(note, *, level=20, log=True)

Add note to the object. By default, the note will also be logged :param note: (str) The note itself :param level: (logging.level) :param log: (boolean) Enable or disable logging of note

notes

Retrieve notes list as a Pandas Series

BAC0.scripts.Base.charstring(val)[source]

BAC0.scripts.Complete module

BAC0.scripts.Lite module

ReadWriteScript - extended version of BasicScript.py

As everything is handled by the BasicScript, select the additional features you want:

# Create a class that implements a basic script with read and write functions
from BAC0.scripts.BasicScript import BasicScript
from BAC0.core.io.Read import ReadProperty
from BAC0.core.io.Write import WriteProperty
class ReadWriteScript(BasicScript,ReadProperty,WriteProperty)

Once the class is created, create the local object and use it:

bacnet = ReadWriteScript(localIPAddr = '192.168.1.10')
bacnet.read('2:5 analogInput 1 presentValue)
class BAC0.scripts.Lite.Lite(ip: Optional[str] = None, port: Optional[int] = None, mask: Optional[int] = None, bbmdAddress=None, bbmdTTL: int = 0, bdtable=None, ping: bool = True, ping_delay: int = 300, db_params: Optional[Dict[str, Any]] = None, **params)[source]

Bases: BAC0.scripts.Base.Base, BAC0.core.functions.Discover.Discover, BAC0.core.io.Read.ReadProperty, BAC0.core.io.Write.WriteProperty, BAC0.core.io.Simulate.Simulation, BAC0.core.functions.TimeSync.TimeSync, BAC0.core.functions.Reinitialize.Reinitialize, BAC0.core.functions.DeviceCommunicationControl.DeviceCommunicationControl, BAC0.core.functions.cov.CoV, BAC0.core.functions.Schedule.Schedule, BAC0.core.functions.Calendar.Calendar, BAC0.core.functions.Text.TextMixin

Build a BACnet application to accept read and write requests. [Basic Whois/IAm functions are implemented in parent BasicScript class.] Once created, execute a whois() to build a list of available controllers. Initialization requires information on the local device.

Parameters:ip='127.0.0.1' – Address must be in the same subnet as the BACnet network [BBMD and Foreign Device - not supported]
add_trend(point_to_trend: Union[BAC0.core.devices.Points.Point, BAC0.core.devices.Trends.TrendLog, BAC0.core.devices.Virtuals.VirtualPoint]) → None[source]

Add point to the list of histories that will be handled by Bokeh

Argument provided must be of type Point or TrendLog ex. bacnet.add_trend(controller[‘point_name’])

clear_notes()

Clear notes object

devices

This property will create a good looking table of all the discovered devices seen on the network.

For that, some requests will be sent over the network to look for name, manufacturer, etc and in big network, this could be a long process.

disconnect() → None[source]

Stop the BACnet stack. Free the IP socket.

discover(networks: Union[str, List[int], int] = 'known', limits: Tuple[int, int] = (0, 4194303), global_broadcast: bool = False, reset: bool = False)[source]

Discover is meant to be the function used to explore the network when we connect. It will trigger whois request using the different options provided with parameters.

By default, a local broadcast will be used. This is required as in big BACnet network, global broadcast can lead to network flood and loss of data.

If not parameters are given, BAC0 will try to :

  • Find the network on which it is
  • Find routers for other networks (accessible via local broadcast)
  • Detect “known networks”
  • Use the list of known networks and create whois request to find all devices on those networks

This should be sufficient for most cases.

Once discovery is done, user may access the list of “discovered devices” using

bacnet.discoveredDevices
:param networks (list, integer) : A simple integer or a list of integer
representing the network numbers used to issue whois request.
:param limits (tuple) : tuple made of 2 integer, the low limit and the high
limit. Those are the device instances used in the creation of the whois request. Min : 0 ; Max : 4194303
:param global_broadcast (boolean) : If set to true, a global broadcast
will be used for the whois. Use with care.
known_network_numbers

This function will read the table of known network numbers gathered by the NetworkServiceElement. It will also look into the discoveredDevices property and add any network number that would not be in the NSE table.

log(note, *, level=10)

Add a log entry…no note

log_subtitle(subtitle, args=None, width=35)
log_title(title, args=None, width=35)
logname = 'BAC0.scripts.Lite | Lite'
note(note, *, level=20, log=True)

Add note to the object. By default, the note will also be logged :param note: (str) The note itself :param level: (logging.level) :param log: (boolean) Enable or disable logging of note

notes

Retrieve notes list as a Pandas Series

ping_registered_devices() → None[source]

Registered device on a network (self) are kept in a list (registered_devices). This function will allow pinging thoses device regularly to monitor them. In case of disconnected devices, we will disconnect the device (which will save it). Then we’ll ping again until reconnection, where the device will be bring back online.

To permanently disconnect a device, an explicit device.disconnect(unregister=True [default value]) will be needed. This way, the device won’t be in the registered_devices list and BAC0 won’t try to ping it.

register_device(device: Union[BAC0.core.devices.Device.RPDeviceConnected, BAC0.core.devices.Device.RPMDeviceConnected]) → None[source]
registered_devices

Devices that have been created using BAC0.device(args)

remove_trend(point_to_remove: Union[BAC0.core.devices.Points.Point, BAC0.core.devices.Trends.TrendLog, BAC0.core.devices.Virtuals.VirtualPoint]) → None[source]

Remove point from the list of histories that will be handled by Bokeh

Argument provided must be of type Point or TrendLog ex. bacnet.remove_trend(controller[‘point_name’])

trends

This will present a list of all registered trends used by Bokeh Server

unregister_device(device)[source]

Remove from the registered list

Module contents