BACnet Server API - Object Access Tutorial

Click Here to Download Download application - 41.5 Kb
Click Here to Download Download Winpcap - Version 3.0



Introduction

The most common operation is to Read or Write to Binary and Analog objects stored inside a BACnet Device. Sensors and actuators for temperature etc. are connected directly to the device and then stored inside Inputs and Outputs objects. The value is stored inside the object in a property known as the presentValue. The ObjectName is stored as a seperate property inside the object. The ObjectName and PresentValue properties exist for all Inputs and Outputs.

Installation and Running the Sample

To Install the sample application you will need to unzip the contents of the application into a directory and then install winpcap. Once Winpcap is installed just start the object_access.exe application. When it starts will be asked to enter a device ID for the application, you can leave this as zero. You should then see a screen that lists all of the options available as shown by the screenshot above.

To use the example application you will need another device connected to the network, and it needs to be running BACnet/IP. This device needs to have a different device ID to the one you enterred for the application. It is assumed that there is another device connected connected which has a device ID of 100, and it contains Analog Value Object with Instance Number 0. If there are no other device, you can create object inside the application using the CreateObject option described below.

Reading the Present Value

To read the value of an object stored in another device select option 1. You will be prompted to enter a device ID corresponding to the device you wish to read from. In this case it will be Device 100.
Enter Object Type = 2 (for Analog Value)
Enter Instance Number = 0
Enter Property Type = 85 (for PresentValue)
Enter Array Index = -1 (This means the array index will be ignored

If the application does not know the location of the device, it will first attempt to locate it by sending off a whoIs request on the network, it should get an Iam response back from the device. The Iam response is used to map an IP Address to a Device ID by the application. The application will then send a readProperty request to the device which will send back the value stored inside the object if no error occurs. The code to execute a readProperty request is shown below.


	//Create An instance of the CBACnetServiceReadProperty class
	CBACnetServiceReadProperty read_prop;

	//Execute The Service using the Parameters Supplied, Returns true if successful
	if (read_prop.Execute(0, 2, 0, 85, -1))
	{
		//Note, the value will be converted into a string
		//The CBACnetAny can be used to return the value as a "float" if required
		printf(read_prop.GetPropertyValue());
	}

Writing to the Present Value

To write to the value of an object stored in another device select option 2. You will be prompted to enter a device ID corresponding to the device you wish to read from. In this case it will be Device 100.
Enter Object Type = 2 (for Analog Value)
Enter Instance Number = 0
Enter Property Type = 85 (for PresentValue)
Enter Array Index = -1 (This means the array index will be ignored
Enter a Data Type = 0 (This will send a Real Value)
Enter a Value = 22

If the application does not know the location of the device, it will first attempt to locate it by sending off a whoIs request on the network, it should get an Iam response back from the device. The Iam response is used to map an IP Address to a Device ID by the application. The application will then send a writeProperty request to the device which will send back the value stored inside the object if no error occurs. The code to execute a readProperty request is shown below.


	//Create An instance of the CBACnetServiceWriteProperty class
	CBACnetServiceWriteProperty write_prop;

	//Execute The Service using the Parameters Supplied, Returns true if successful
	//Note, value must correspond to the appropriate data type
	//In this case the data type is a float
	if (write_prop.Execute(0, 2, 0, 85, float(22), 10, -1))
		printf("Success\n");

Creating an Object

You can create objects inside another device using this option. The application will send a CreateObject request to the device and an object will be created.
Select Option 7 to create an object
Enter Device ID = 0 (This will create an object internal to the application.)
Enter Object Type = 2 (for Analog Value)
Enter Instance Number = 0

You can use this option to create Internal Objects inside the application for testing purposes. This will allow you to send a readProperty request to the application using the steps described above.

If the application does not know the location of the device, it will first attempt to locate it by sending off a whoIs request on the network, it should get an Iam response back from the device. The Iam response is used to map an IP Address to a Device ID by the application. The application will then send a createObject request to the device which will create a new object inside it's database if no error occurs. The code to execute a readProperty request is shown below.


	//Create An instance of the CBACnetServiceCreateObject class
	CBACnetServiceCreateObject service;

	//Execute The Service using the Parameters Supplied, Returns true if successful
	//Note, value must correspond to the appropriate data type
	//In this case the data type is a float
	if (service.Execute(0, 2, 0)
		printf("Success\n");

Examine the Code

The entire source code for this sample is available from the downloads area of this web site as part of the BACnet Server API using either Windows or Linux. The code has many comments that describe the use of the standard BACnet Services used to Access BACnet Objects.

Further Reading