Code-House / bacnet4j-wrapper

Simple facade for bacnet4j api.
GNU General Public License v3.0
49 stars 21 forks source link

Registering a network router #30

Closed janb93 closed 1 year ago

janb93 commented 1 year ago

Hello,

I know all the properties for connecting the BACnet device and want to connect directly. I have a problem that I receive the NullPointerException for the method "addNetworkRouter".

Here is my code:

BacNetIpClient bacNetIpClient = new BacNetIpClient(deviceIP, personalId);
bacNetIpClient.addNetworkRouter(networkNumber, deviceIP, 47808);

bacNetClient = bacNetIpClient;

correctDevice = new Device(deviceId, macAddressBytes, networkNumber);
splatch commented 1 year ago

Hello @janb93, Can you please post stack trace which includes org.code_house and com.serotonin.bacnet4j lines?

janb93 commented 1 year ago

This is only thing from org.code_house

nov 20 10:58:15 run.sh[65084]: java.lang.NullPointerException
nov 20 10:58:15 run.sh[65084]:         at org.code_house.bacnet4j.wrapper.ip.BacNetIpClient.addNetworkRouter(BacNetIpClient.java:76)
splatch commented 1 year ago

Please make sure that you first call client.start(), otherwise network transport might not be fully initialized.

BacNetIpClient bacNetIpClient = new BacNetIpClient(deviceIP, personalId);
bacNetIpClient.start(); // needed to fully initialize client
bacNetIpClient.addNetworkRouter(networkNumber, deviceIP, 47808);

bacNetClient = bacNetIpClient;

correctDevice = new Device(deviceId, macAddressBytes, networkNumber);
janb93 commented 1 year ago

Yes, this helped! Thank you! If anyone needs working code:

        bacNetIpClient = new BacNetIpClient(deviceIP, personalId);

        bacNetIpClient.start();
        bacNetIpClient.addNetworkRouter(networkNumber, deviceIP, port);
        correctDevice = new Device(deviceId, macAddressBytes, networkNumber);
        bacNetIpClient.stop();
splatch commented 1 year ago

Thanks for confirmation. Together we will deliver not only working code but some pieces of documentation. ;-)