I am a newbie to BACnet and other automation protocols.We are going to write one BACnet client which is expected to connect to BACnet interface to fetch the objects and further we are going to ingest these objects in our microservices layer.Our server infrastructure contains LumInsight Desktop which will push the data onto BACnet interface. We are referring one example code but while running it I am getting below issue:
> inside main....com.serotonin.bacnet4j.transport.DefaultTransport@7b7221a0
inside main....3996: BACnet device
Exception in thread "main" java.net.BindException: Address already in use: Cannot bind
at java.net.DualStackPlainDatagramSocketImpl.socketBind(Native Method)
at java.net.DualStackPlainDatagramSocketImpl.bind0(Unknown Source)
at java.net.AbstractPlainDatagramSocketImpl.bind(Unknown Source)
at java.net.DatagramSocket.bind(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at com.serotonin.bacnet4j.npdu.ip.IpNetwork.initialize(IpNetwork.java:215)
at com.serotonin.bacnet4j.transport.DefaultTransport.initialize(DefaultTransport.java:183)
at com.serotonin.bacnet4j.LocalDevice.initialize(LocalDevice.java:228)
at com.bacnet.Main.main(Main.java:110)
package com.bacnet;
import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.RemoteDevice;
import com.serotonin.bacnet4j.ServiceFuture;
import com.serotonin.bacnet4j.event.DeviceEventAdapter;
import com.serotonin.bacnet4j.exception.BACnetException;
import com.serotonin.bacnet4j.exception.ErrorAPDUException;
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyMultipleAck;
import com.serotonin.bacnet4j.service.confirmed.*;
import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
import com.serotonin.bacnet4j.transport.DefaultTransport;
import com.serotonin.bacnet4j.transport.Transport;
import com.serotonin.bacnet4j.type.constructed.ReadAccessResult;
import com.serotonin.bacnet4j.type.constructed.ReadAccessSpecification;
import com.serotonin.bacnet4j.type.constructed.SequenceOf;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.enumerated.Segmentation;
import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
import com.serotonin.bacnet4j.type.primitive.Real;
import com.serotonin.bacnet4j.util.DiscoveryUtils;
import com.serotonin.bacnet4j.RemoteObject;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
IpNetwork network = new IpNetwork("10.44.55.5", IpNetwork.DEFAULT_PORT);
Transport transport = new DefaultTransport(network);
System.out.println("inside main...." + transport);
transport.setTimeout(500);
transport.setSegTimeout(150);
final LocalDevice localDevice = new LocalDevice(3996, transport);
System.out.println("inside main...." + localDevice);
localDevice.getEventHandler().addListener(new DeviceEventAdapter() {
@Override
public void iAmReceived(RemoteDevice device) {
System.out.println("inside I am received...");
System.out.println("Discovered device " + device);
localDevice.addRemoteDevice(device);
final RemoteDevice remoteDevice = localDevice
.getRemoteDevice(device.getAddress());
remoteDevice
.setSegmentationSupported(Segmentation.segmentedBoth);
new Thread(new Runnable() {
@Override
public void run() {
try {
try {
DiscoveryUtils.getExtendedDeviceInformation(
localDevice, remoteDevice);
} catch (BACnetException e) {
e.printStackTrace();
}
System.out.println(remoteDevice.getName() + " "
+ remoteDevice.getVendorName() + " "
+ remoteDevice.getModelName() + " "
+ remoteDevice.getAddress() + " "
+ remoteDevice.getProtocolRevision() + " "
+ remoteDevice.getProtocolVersion());
ReadPropertyAck ack = localDevice.send(
remoteDevice,
new ReadPropertyRequest(remoteDevice
.getObjectIdentifier(),
PropertyIdentifier.objectList))
.get();
SequenceOf<ObjectIdentifier> value = ack.getValue();
for (ObjectIdentifier id : value) {
List<ReadAccessSpecification> specs = new ArrayList<ReadAccessSpecification>();
specs.add(new ReadAccessSpecification(id,
PropertyIdentifier.presentValue));
specs.add(new ReadAccessSpecification(id,
PropertyIdentifier.units));
specs.add(new ReadAccessSpecification(id,
PropertyIdentifier.objectName));
specs.add(new ReadAccessSpecification(id,
PropertyIdentifier.description));
specs.add(new ReadAccessSpecification(id,
PropertyIdentifier.objectType));
ReadPropertyMultipleRequest multipleRequest = new ReadPropertyMultipleRequest(
new SequenceOf<ReadAccessSpecification>(
specs));
ReadPropertyMultipleAck send = localDevice
.send(remoteDevice, multipleRequest)
.get();
SequenceOf<ReadAccessResult> readAccessResults = send
.getListOfReadAccessResults();
System.out.print(id.getInstanceNumber() + " "
+ id.getObjectType() + ", ");
for (ReadAccessResult result : readAccessResults) {
for (ReadAccessResult.Result r : result
.getListOfResults()) {
System.out.print(r.getReadResult()
+ ", ");
}
}
System.out.println();
}
ObjectIdentifier mode = new ObjectIdentifier(
ObjectType.analogValue, 11);
ServiceFuture send = localDevice.send(remoteDevice,
new WritePropertyRequest(mode,
PropertyIdentifier.presentValue,
null, new Real(2), null));
System.out.println(send.getClass());
System.out.println(send.get().getClass());
} catch (ErrorAPDUException e) {
System.out.println("Could not read value "
+ e.getApdu().getError() + " " + e);
} catch (BACnetException e) {
e.printStackTrace();
}
}
}).start();
}
@Override
public void iHaveReceived(RemoteDevice device, RemoteObject object) {
System.out.println("Value reported " + device + " " + object);
}
});
localDevice.initialize();
localDevice.sendGlobalBroadcast(new WhoIsRequest());
List<RemoteDevice> remoteDevices = localDevice.getRemoteDevices();
for (RemoteDevice device : remoteDevices) {
System.out.println("Remote dev " + device);
}
System.in.read();
localDevice.terminate();
}
}
The error is self explanatory "Address already in use", please check if have any other client running and using the port 47808 (Default Port).