![]() | 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 |
---|---|
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).”
.
Table 5.4. Properties of the Analog Output Object Type according to BACnet Standard, Table 12-3 (not all properties are shown).
Property Identifier | Property Datatype | Conformance Code |
---|---|---|
Object_Identifier | BACnetObjectIdentifier | R |
Object_Name | CharacterString | R |
Object_Type | BACnetObjectType | R |
Present_Value | REAL | W |
Description | CharacterString | O |
(further entries are omitted) |
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"><PropertyIdentifier Name="Local_Date"/>
<Object Type="Analog Input" Instance="1">
<PropertyIdentifier Name="Object_Identifier"/>
<PropertyIdentifier Name="Units"/>
<PropertyIdentifier Name="Present_Value"/>
</Object> <Object Type="Analog Output" Instance="2">
<PropertyIdentifier Name="Present_Value" Index="2"/>
</Object> </Object> <Object Type="Device" Instance="637502">
<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:
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. | |
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. | |
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. | |
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. | |
The optional attribute |
To read data from BACnet devices, the
BACnetReader
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 read from BACnet, the BACnet stack provides the following function:
bacrp device-instance object-type object-instance property [index]
(For an explanation of the arguments, type
./bacrp --help
on a console.) The above
xml file would cause the following commands to be
executed:
bacrp 637501 8 637501 56 bacrp 637501 0 1 75 bacrp 637501 0 1 117 bacrp 637501 0 1 191 bacrp 637501 1 2 117 2 bacrp 637502 0 1 191 bacrp 637502 1 3 191
In the first command, the second argument is 8 as this
is the enumeration for the BACnet Object Device, and
the fourth argument is 56 as this is the enumeration
for the Local Date Property. The following lines are
constructed similarly, using the enumerations that are
defined in the file bacenum.h
that is part
of the BACnet stack.
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
.
Table 5.5. BACnet Conformance Codes.
O | Indicates that the property is optional. |
R | Indicates that the property is required to be present and readable using BACnet services. |
W | Indicates that the property is required to be present, readable, and writeable using BACnet services. |
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.”
.
Table 5.6. Attributes of the PropertyIdentifier
xml element if used to write to a BACnet device.
Attribute name | Required | Description |
---|---|---|
Name | yes | The name of the property identifier. |
ApplicationTag | yes |
This attribute specifies the data format that is used to send the value to the BACnet device. Possible entries are
NULL , BOOLEAN , UNSIGNED_INT , SIGNED_INT , REAL , DOUBLE , OCTET_STRING , CHARACTER_STRING , BIT_STRING , ENUMERATED , DATE , TIME , OBJECT_ID , MAX_BACNET_APPLICATION_TAG .
The value of this attribute will be converted to upper-case, and then sent to the BACnet interface.
|
Priority | no | This parameter sets the priority of the write operation. Allowed entries are any integers from 0 to 16. If Priority 0 is given, no priority is sent, which defaults according to the BACnet standard to the lowest priority. The highest priority is 1 and the lowest priority is 16. If the value is not specified, then it is set to 15. |
Index | no |
This integer parameter is the index number of an array. If the property is an array, individual elements can be written to if supported by the BACnet device. If this parameter is -1, the index is ignored and hence the entire array is referenced. If the value is not specified, then it is set to -1. |
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
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.”.
Table 5.7. Output ports of the BACnetReader
actor.
Port | Description |
---|---|
errorSignal | If there were no errors in the previous data exchange, then this port outputs zero. Otherwise, the output is a non-zero integer. |
errorMessage | If there was an error in the previous data exchange, then this port outputs the error message that was generated by the BACnetReader actor.
(The error messages that were generated by the BACnet stack are output of the consoleOutput port.) |
consoleOutput |
This port outputs the standard output stream and the standard error stream of the executable that communicates with BACnet. |
propertyValueArray |
This port outputs the values obtained at the last successful communication with the BACnet devices. If there was an error in the last communication, then the values from the previous time step will be output of this port.
The output data type is an array whose elements
are string representations of the BACnet
properties that are read according to the
configuration file. Elements can be extracted
from this array using actors from Ptolemy II's
|
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 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.”.
Table 5.8. Output ports of the BACnetWriter
actor.
Port | Description |
---|---|
errorSignal | If there were no errors in the previous data exchange, then this port outputs zero. Otherwise, the output is a non-zero integer. |
errorMessage | If there was an error in the previous data exchange, then this port outputs the error message that was generated by the BACnetReader actor.
(The error messages that were generated by the BACnet stack are output of the consoleOutput port.) |
consoleOutput |
This port outputs the standard output stream and the standard error stream of the executable that communicates with BACnet. |
[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
.