-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
31 lines (24 loc) · 909 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// BACnet device implementation.
// Example for using this module.
//
const BACnetDevice = require('./index.js');
const BE = require('bacstack').enum;
const dev = new BACnetDevice({
// These parameters are all mandatory by the BACnet spec.
deviceId: 123,
vendorId: 0,
name: 'Example device',
databaseRevision: 1,
});
// Add a new data point to our device.
const objExample = dev.addObject(1, BE.ObjectType.ANALOG_INPUT, 'Example value');
// Add a property to the new data point.
const propExample = objExample.addProperty(BE.PropertyIdentifier.PRESENT_VALUE, BE.ApplicationTags.REAL);
// Set an initial value for the data point's "present value" property.
propExample.value = 1;
console.log('Dumping objects contained within this device:');
Object.keys(dev.objects).forEach(objInstance => {
const o = dev.objects[objInstance];
console.log(`\nObject #${o.instance}:`, o.dumpProperties());
});