Hi,
I am trying to perform BACnet Master Slave communication and for that, I have done below things as given in the example.
For Master Device:
static void master(final SerialPort serialPort) throws Exception {
try (JsscSerialPortInputStream in = new JsscSerialPortInputStream(serialPort);
JsscSerialPortOutputStream out = new JsscSerialPortOutputStream(serialPort)) {
final MasterNode node = new MasterNode("test", in, out, (byte) 3, 2);
node.setMaxInfoFrames(5);
node.setUsageTimeout(100);
final MstpNetwork network = new MstpNetwork(node, 0);
final Transport transport = new DefaultTransport(network);
final LocalDevice ld = new LocalDevice(1970, transport);
ld.initialize();
System.out.println(prefix() + "Initialized");
for (int i = 0; i < 10; i++) {
System.out.println(prefix() + "Discovering");
final RemoteDeviceDiscoverer rdd = ld.startRemoteDeviceDiscovery((r) -> {
System.out.println(prefix() + "Device: " + r + ", " + r.getName());
});
ThreadUtils.sleep(6000);
System.out.println("remote device list :: "+rdd.getRemoteDevices());
rdd.stop();
}
System.out.println(prefix() + "Terminating");
ld.terminate();
}
}
For Slave Device:
static void slave(final SerialPort serialPort) throws Exception {
try (JsscSerialPortInputStream in = new JsscSerialPortInputStream(serialPort);
JsscSerialPortOutputStream out = new JsscSerialPortOutputStream(serialPort)) {
final SlaveNode node = new SlaveNode("test", in, out, (byte) 3); //Creating mstp node and place it in ideal state
final MstpNetwork network = new MstpNetwork(node, 0);
final Transport transport = new DefaultTransport(network);
final LocalDevice ld = new LocalDevice(111, transport);
ld.initialize();
ld.startRemoteDeviceDiscovery((r) -> {
System.out.println("Get instance number: "+r.getInstanceNumber());
});
ThreadUtils.sleep(100000);
System.out.println("getBytesIn :: "+node.getBytesIn());
System.out.println("getBytesOut :: "+node.getBytesOut());
ld.terminate();
}
}
But still not able to discover the remote devices.
Is there anything that I miss or any mistake I have done?
I think it's probably obvious that I am new to BACnet and the BACnet4J library. I would be super grateful for any help!
Thank you,
Vihangi