5.12. BACnet

[Note]Note

The BACnet interface is only supported on Windows and on Linux. It has not been ported to Mac OS X.

The BCVTB contains an actor, called BACnetReader, that can read from BACnet devices and an actor, called BACnetWriter, that can write to BACnet devices. These actors use the open source BACnet protocol stack , which is shipped with the BCVTB installation and that has been developed by Steve Karg. Both actors use a configuration file that specifies the BACnet devices, the object types and the property identifiers with which data is to be exchanged. The next sections describe how to configure these configuration files, and how to set up a model that reads from and writes to BACnet devices.

[Note]Note

BACnet systems typically allow a user to export a list of BACnet object types with their instance numbers. Such a list needs to be obtained for the particular control system in order to configure the data exchange that is described in Section 5.12.2, “Reading from BACnet” and Section 5.12.3, “Writing to BACnet” .

The BACnetReader actor reads an xml configuration file to determine what data it needs to read from BACnet devices. This configuration file specifies the BACnet object types and their child elements, [2] which can be other BACnet object types or BACnet property identifiers . The xml configuration file has the following syntax: It starts and ends with

<?xml version="1.0" encoding="utf-8"?>
<BACnet>
   <!-- Child elements are not shown. -->
</BACnet>

The above element BACnet requires at least one child element of the form

<Object Type="Device" Instance="123">
   <!-- Child elements are not shown. -->
</Object>

i.e., the element name is Object, the attribute Type needs to be Device and the attribute Instance needs to be set to its instance number, which is a unique number that is assigned at the discretion of the control provider. Any Object element can contain other Object elements and other PropertyIdentifier elements.

The Object elements can have any of the following values for the attribute Type (the meaning of these types is explained in Chapter 12 of the BACnet Standard [ASHRAE 2004] ): Analog Input, Analog Output, Analog Value, Binary Input, Binary Output, Binary Value, Calendar, Command, Device, Event Enrollment, File, Group, Loop, Multi State Input, Multi State Output, Notification Class, Program, Schedule, Averaging, Multi State Value, Trend Log, Life Safety Point, Life Safety Zone, Accumulator, Pulse Converter, Event Log, Global Group, Trend Log Multiple, Load Control, Structured View, Access Door, Lighting Output, Access Credential, Access Point, Access Rights, Access User, Access Zone, Authentication Factor Input, Max ASHRAE, Load Control, Structured View, Access Door, Lighting Output, Access Credential, Access Point, Access Rights, Access User, Access Zone, Authentication Factor Input, Max ASHRAE.

Each of these object types has its own set of properties that can be read or written to. These properties are declared in the element PropertyIdentifier which has one attribute called Name. For example, for the object with type Analog Output, the BACnet standard lists in Table 12-3 the properties shown in Table 5.4, “Properties of the Analog Output Object Type according to BACnet Standard, Table 12-3 (not all properties are shown).” .


Thus, we can set, for example,

<?xml version="1.0" encoding="utf-8"?>
<BACnet>
  <Object Type="Device" Instance="123">
    <Object Type="Analog Output" Instance="1">
      <PropertyIdentifier Name="Present_Value"/>
    </Object>
  </Object>
</BACnet>

which would cause the BACnetReader to read the present value of the BACnet Analog Output object type with instance number 1, which is part of a BACnet Device Object with instance number 123.

The following code listing shows an example of a larger configuration file that is used to read data from a BACnet system.

<?xml version="1.0" encoding="utf-8"?>
<BACnet>
  <Object Type="Device" Instance="637501">                 (1)
    
    <PropertyIdentifier Name="Local_Date"/>                (2)
    
    <Object Type="Analog Input" Instance="1">              (3)
      <PropertyIdentifier Name="Object_Identifier"/>       (4)
      <PropertyIdentifier Name="Units"/>                   (5)
      <PropertyIdentifier Name="Present_Value"/>           (6)
    </Object>
    
    <Object Type="Analog Output" Instance="2">             (7)
      <PropertyIdentifier Name="Present_Value"
                          Index="2"/>                      (8)
    </Object>
    
  </Object>
  
  <Object Type="Device" Instance="637502">                 (9)
    
    <Object Type="Analog Input" Instance="1">
      <PropertyIdentifier Name="Present_Value"/>
    </Object>
    
    <Object Name="Analog Output" Instance="3">
      <PropertyIdentifier Name="Present_Value"/>
    </Object>
    
  </Object>
</BACnet>

The numbered items have the following functionalities:

19

The BACnet devices are declared at the top-level of the control system. The only valid elements are

<Object Type="Device" Instance="123">
   <!-- Child elements are not shown. -->
</Object>

which all need to have a unique, system-dependent instance number.

2

This line declares a BACnet property identifier of the device with instance number 637501. This statement will cause the BACnet reader to read the local date from the device.

37

These lines declare BACnet object types that are children of the device object type with instance number 637501. The first instance has the instance number 1, and the second instance has the instance number 2. Note that instance numbers are assigned by the controls provider and need not start at 1.

456

These entries declare BACnet property identifiers of the device with instance number 1. These statements will cause the BACnet reader to read its object identifier, its units and its present value.

8

The optional attribute Index="2" declares that the present value will only be obtained for the second element of this Analog Output object. If the Index would not be specified and the Analog Output object has an array of values, then all elements of the array would be read.

The BCVTB contains an actor called BACnetWriter that can write to BACnet devices. The BACnet standard [ASHRAE 2004] defines the conformance codes shown in Table 5.5, “BACnet Conformance Codes.” . The BACnetReader can write to any BACnet properties with the conformance code W.


The BACnetWriter provides the WriteProperty Service that is specified in Section 15.9 in the BACnet Standard [ASHRAE 2004] . The configuration file that is used by the BACnetWriter is identical to the one used for the BACnetReader explained in Section 5.12.2, “Reading from BACnet” , except that the xml elements of type PropertyIdentifier have the additional attributes ApplicationTag, Priority, and Index. These attributes are explained in Table 5.6, “Attributes of the PropertyIdentifier xml element if used to write to a BACnet device.” . The following program listing shows an example configuration file.

<?xml version="1.0" encoding="utf-8"?>
<BACnet>
  <!-- Top level BACnet device -->  
  <Object Type="Device" Instance="637501">

    <!-- BACnet object for analog input -->    
    <Object Type="Analog Input" Instance="1">
      <PropertyIdentifier Name="Present_Value" ApplicationTag="Real" 
			  Priority="15" Index="-1"/>
    </Object>
  </Object>
  <!-- Top level BACnet device -->    
  <Object Type="Device" Instance="637502">
    
    <Object Type="Analog Input" Instance="1">
      <PropertyIdentifier Name="Present_Value" ApplicationTag="Real" 
			  Priority="15" Index="-1"/>
    </Object>
    <!-- BACnet object for analog input -->        
    <Object Type="Analog Input" Instance="2">
      <PropertyIdentifier Name="Present_Value" ApplicationTag="Real" 
			  Priority="15" Index="-1"/>
    </Object>
  </Object>
</BACnet>

For the BACnetWriter, the xml element PropertyIdentifier has the attributes shown in Table 5.6, “Attributes of the PropertyIdentifier xml element if used to write to a BACnet device.” .


To write data to BACnet devices, the BACnetWriter actor calls an executable program that is provided by the BACnet stack. This section describes how the entries in the xml file relate to this executable. The example shows the low-level implementation and may be skipped by users who are not interested in the implementation.

To write to BACnet, the BACnet stack provides the following function:

bacwp device-instance object-type object-instance property priority index tag value [tag value...]

(For an explanation of the arguments, type ./bacwp --help on a console.) The above xml file would cause the following commands to be executed:

bacwp 637501 0 1 85 15 -1 4 "value[1]"
bacwp 637502 0 1 85 15 -1 4 "value[2]"
bacwp 637502 0 2 85 15 -1 4 "value[3]"

Note that our implementation only supports one pair of tag value. However, multiple pairs can be constructed by declaring a separate PropertyIdentifier element for each pair.

In the first command, the second argument is zero as this is the enumeration for analog input objects in the BACnet stack; the fourth argument is 85 which is the enumeration for the present value property; the second last element is 4 as this is the enumeration for the application tag; and "value[1]" will be replaced with the actual value of the first element of the vector that is received at the input port of the actor.

In the second command, "value[2]" will be replaced with the actual value of the second element of the vector that is received at the input port of the actor. For a list of the enumerations that are used in the above commands, see the file bacenum.h that is part of the BACnet stack.

The BACnetReader and the BACnetWriter actor can be used in the same Ptolemy II model. In this section, however, we will explain how to configure separate Ptolemy II models that write to and read from BACnet devices. These files can be found in the directories bcvtb/examples/BACnetReaderALC and bcvtb/examples/BACnetWriterALC. Note that these examples have been developed for a particular hardware setup. To run these examples for other hardware, their configuration files need to be modified as described in Section 5.12.2, “Reading from BACnet” and Section 5.12.3, “Writing to BACnet” .


Figure 5.43 shows a Ptolemy II system model that uses the BACnetReader actor. To configure the BACnetReader, double-click on its icon and add the name of its configuration file that has been developed as described in Section 5.12.2, “Reading from BACnet” . There is also a check-box called continueWhenError. If activated and an error occurs, then Ptolemy II will continue the simulation and the actor will output at its ports the last known value and the error message, unless the error occurs in the first step, in which case the simulation stops. If deactivated and an error occurs, then the simulation will stop, the error message will be displayed on the screen and the user is required to confirm the error message by clicking on its OK button. Thus, select this box if the BCVTB should continue its operation when a run-time error, such as a network timeout, occurs.

The BACnetReader has one input port, which is a trigger port. If the SDF Director is used in the Ptolemy II system model, then this port need not be connected. The BACnetReader has the output ports shown in Table 5.7, “Output ports of the BACnetReader actor.”.



The configuration of the BACnetWriter actor is similar to the configuration of BACnetReader.
Figure 5.44 shows a Ptolemy II system model that uses the BACnetWriter. To configure the BACnetWriter, double-click on its icon and add the name of its configuration file that has been developed as described in Section 5.12.3, “Writing to BACnet” . There is also a check-box called continueWhenError. If activated and an error occurs, then Ptolemy II will continue the simulation and the actor will output the error message at its ports, unless the error occurs in the first step, in which case the simulation stops. If deactivated and an error occurs, then the simulation will stop, the error message will be displayed on the screen and the user is required to confirm the error message by clicking on its OK button. Thus, select this box if the BCVTB should continue its operation when a run-time error, such as a network timeout, occurs.

Input into the actor is an array of values that will be written to the BACnet devices according to the order specified in the xml configuration file. In Ptolemy II, such an array can be composed from scalar inputs by using the actor Actors->Array->ElementsToArray.

The BACnetWriter has one input port. This port is used to collect the data that need to be sent to the BACnet devices. The BACnetWriter has the output ports shown in Table 5.8, “Output ports of the BACnetWriter actor.”.




[2] In xml, an element B is called a child element of an element A if B is contained exactly one level below element A.