bacstack

bacstack

new bacstack()

Source:
To be able to communicate to BACNET devices, you have to initialize a new bacstack instance.
Example
const bacnet = require('bacstack');

const client = new bacnet({
  port: 47809,                          // Use BAC1 as communication port
  interface: '192.168.251.10',          // Listen on a specific interface
  broadcastAddress: '192.168.251.255',  // Use the subnet broadcast address
  adpuTimeout: 6000                     // Wait twice as long for response
});
Parameters:
Name Type Attributes Default Description
this._settings object <optional>
The options object used for parameterizing the bacstack.
options.port number <optional>
47808 BACNET communication port for listening and sending.
options.interface string <optional>
Specific BACNET communication interface if different from primary one.
options.broadcastAddress string <optional>
255.255.255.255 The address used for broadcast messages.
options.adpuTimeout number <optional>
3000 The timeout in milliseconds until a transaction should be interpreted as error.

Methods

(static) close()

Source:
Unloads the current BACstack instance and closes the underlying UDP socket.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.close();

(static) deviceCommunicationControl(address, timeDuration, enableDisable, optionsopt, next)

Source:
The deviceCommunicationControl command enables or disables network communication of the target device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.deviceCommunicationControl('192.168.1.43', 0, bacnet.enum.EnableDisable.DISABLE, (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
timeDuration number The time to hold the network communication state in seconds. 0 for infinite.
enableDisable EnableDisable The network communication state to set.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
password string <optional>
The optional password used to set the network communication state.
next function The callback containing an error, in case of a failure and value object in case of success.

(static) readProperty(address, objectId, propertyId, optionsopt, next)

Source:
The readProperty command reads a single property of an object from a device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.readProperty('192.168.1.43', {type: 8, instance: 44301}, 28, (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
objectId object The BACNET object ID to read.
Properties
Name Type Description
type number The BACNET object type to read.
instance number The BACNET object instance to read.
propertyId number The BACNET property id in the specified object to read.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
arrayIndex number <optional>
The array index of the property to be read.
next function The callback containing an error, in case of a failure and value object in case of success.

(static) readPropertyMultiple(address, requestArray, optionsopt, next)

Source:
The readPropertyMultiple command reads multiple properties in multiple objects from a device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

const requestArray = [
  {objectId: {type: 8, instance: 4194303}, properties: [{id: 8}]}
];
client.readPropertyMultiple('192.168.1.43', requestArray, (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
requestArray Array.<object> List of object and property specifications to be read.
Properties
Name Type Description
objectId object Specifies which object to read.
Properties
Name Type Description
type number The BACNET object type to read.
instance number The BACNET object instance to read.
properties Array.<object> List of properties to be read.
Properties
Name Type Description
id number The BACNET property id in the specified object to read. Also supports 8 for all properties.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
next function The callback containing an error, in case of a failure and value object in case of success.

(static) reinitializeDevice(address, state, optionsopt, next)

Source:
The reinitializeDevice command initiates a restart of the target device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.reinitializeDevice('192.168.1.43', bacnet.enum.ReinitializedStates.BACNET_REINIT_COLDSTART, (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
state ReinitializedStates The type of restart to be initiated.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
password string <optional>
The optional password used to restart the device.
next function The callback containing an error, in case of a failure and value object in case of success.

(static) timeSync(address, dateTime)

Source:
The timeSync command sets the time of a target device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.timeSync('192.168.1.43', new Date());
Parameters:
Name Type Description
address string IP address of the target device.
dateTime date The date and time to set on the target device.

(static) timeSyncUTC(address, dateTime)

Source:
The timeSyncUTC command sets the UTC time of a target device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.timeSyncUTC('192.168.1.43', new Date());
Parameters:
Name Type Description
address string IP address of the target device.
dateTime date The date and time to set on the target device.

(static) whoIs(optionsopt)

Source:
The whoIs command discovers all BACNET devices in a network.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.whoIs();
Parameters:
Name Type Attributes Description
options object <optional>
Properties
Name Type Attributes Description
lowLimit number <optional>
Minimal device instance number to search for.
highLimit number <optional>
Maximal device instance number to search for.
address string <optional>
Unicast address if command should address a device directly.
Fires:

(static) writeProperty(address, objectId, propertyId, values, optionsopt, next)

Source:
The writeProperty command writes a single property of an object to a device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.writeProperty('192.168.1.43', {type: 8, instance: 44301}, 28, [
  {type: bacnet.enum.ApplicationTags.BACNET_APPLICATION_TAG_REAL, value: 100}
], (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
objectId object The BACNET object ID to write.
Properties
Name Type Description
type number The BACNET object type to write.
instance number The BACNET object instance to write.
propertyId number The BACNET property id in the specified object to write.
values Array.<object> A list of values to be written to the specified property.
Properties
Name Type Description
tag ApplicationTags The data-type of the value to be written.
value number The actual value to be written.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
arrayIndex number <optional>
The array index of the property to be read.
priority number <optional>
The priority of the value to be written.
next function The callback containing an error, in case of a failure and value object in case of success.

(static) writePropertyMultiple(address, values, optionsopt, next)

Source:
The writePropertyMultiple command writes multiple properties in multiple objects to a device.
Example
const bacnet = require('bacstack');
const client = new bacnet();

const values = [
  {objectId: {type: 8, instance: 44301}, values: [
    {property: {id: 28, index: 12}, value: [{type: bacnet.enum.ApplicationTags.BACNET_APPLICATION_TAG_BOOLEAN, value: true}], priority: 8}
  ]}
];
client.writePropertyMultiple('192.168.1.43', values, (err, value) => {
  console.log('value: ', value);
});
Parameters:
Name Type Attributes Description
address string IP address of the target device.
values Array.<object> List of object and property specifications to be written.
Properties
Name Type Description
objectId object Specifies which object to read.
Properties
Name Type Description
type number The BACNET object type to read.
instance number The BACNET object instance to read.
values Array.<object> List of properties to be written.
Properties
Name Type Description
property object Property specifications to be written.
Properties
Name Type Description
id number The BACNET property id in the specified object to write.
index number The array index of the property to be written.
value Array.<object> A list of values to be written to the specified property.
Properties
Name Type Description
tag ApplicationTags The data-type of the value to be written.
value object The actual value to be written.
priority number The priority to be used for writing to the property.
options object <optional>
Properties
Name Type Attributes Description
maxSegments MaxSegments <optional>
The maximimal allowed number of segments.
maxAdpu MaxAdpu <optional>
The maximal allowed ADPU size.
invokeId number <optional>
The invoke ID of the confirmed service telegram.
next function The callback containing an error, in case of a failure and value object in case of success.

Events

error

Source:
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.on('error', (err) => {
  console.log('Error occurred: ', err);
  client.close();
});
Parameters:
Name Type Description
err error The IP address of the detected device.

iAm

Source:
Example
const bacnet = require('bacstack');
const client = new bacnet();

client.on('iAm', (device) => {
  console.log('address: ', device.address, ' - deviceId: ', device.deviceId, ' - maxAdpu: ', device.maxAdpu, ' - segmentation: ', device.segmentation, ' - vendorId: ', device.vendorId);
});
Parameters:
Name Type Description
device object An object representing the detected device.
Properties
Name Type Description
address string The IP address of the detected device.
deviceId number The BACNET device-id of the detected device.
maxAdpu number The max ADPU size the detected device is supporting.
segmentation number The type of segmentation the detected device is supporting.
vendorId number The BACNET vendor-id of the detected device.