Is it possible to create virtual local devices with bacnet4j?

1.5k views Asked by At

Has anyone built multiple virtual local devices with bacnet4j on a BACnet server? What has to be done, to achieve this?

Is this basically possible at all?

2

There are 2 answers

2
Mike On

Yes you can create a BACnet server using bacnet4j. The following example shows how to set up a device with an analog value BACnet object:

    IpNetwork network = new IpNetwork("10.78.20.255", 0xBAC5);
    Transport transport = new Transport(network);

    // create device with random device number
    int localDeviceID = 10000 + (int) ( Math.random() * 10000);
    LocalDevice localDevice = new LocalDevice(localDeviceID, transport);
    localDevice.initialize();

    System.out.println("Local device is running with device id " + localDeviceID);

    // create sample BACnet object
    ObjectIdentifier objectId = new ObjectIdentifier(ObjectType.analogValue, 1);
    BACnetObject object = new BACnetObject(localDevice, objectId);

    localDevice.addObject(object);

Note that you have to ensure that the object identifier (analog value 1 in the example) is unique on the device.

0
DennisVM-D2i On

My recommendation would be to consider the use of the loopback address, or rather (not commonly known) the lookback address range.

In other words, as much as many people are familiar that the IP(v4) address of 127.0.0.1 is the loopback address, not many people know/stop to realise that it's a Class A address, in other words there are many (local) IP(v4) addresses that you can use/that are available within this 127.x.y.z loopback range, e.g. 127.0.0.2/etc in addition to the typical/default 127.0.0.1 address - both (/all addresses within the range) will (/should) resolve to your local machine, therefore allowing all your (virtual) devices to have the same (BACnet) port # but all have assigned/use a unique IP address.