0

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?

Thirdman
  • 621
  • 7
  • 13

2 Answers2

0

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.

Mike
  • 3,094
  • 2
  • 12
  • 5
  • Thank you for your answer, but sorry, that's not what I asked for. The code you show only instantiates **one** device. What I try to do is instantiate multiple devices on one hardware (with one network card). I saw that with Scada BACnet Server API it is possible to simply instantiate n virtual devices on one hardware device. I would like to do this to structure my bunch of BACnet Data Points (as I would like to transfer a lot of them). – Thirdman Jun 10 '15 at 05:45
  • Ah sorry - I don't think that's possible (IpNetwork uses a locally bind DatagramSocket internally) except you use different IP ports for each instance. – Mike Jun 16 '15 at 18:17
0

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.

DennisVM-D2i
  • 416
  • 3
  • 8