MSTP WhoIs
-
Hi,
I'm trying to detect MSTP bacnet devices connected to a rs485-usb adapter and I'm having a problem reliably getting IAm responses.
I get a response about once every five to ten WhoIs requests,
This increases to about once every two to three tries if I change the MAC address between each request.
Other than that I cannot find any patteren in the responses.
Once I get a response(and save its details) i can reliably send requests to that device as much and as often as i want.
This, combined with tests I've done with other software, leads me to believe its not the hardware I'm using.Originally I assumed it was my code, but once simplified as much as I could I still got the same problem.
Is this a problem others have encountered? Is this a problem with the library? or am I using it wrong?Here is my simplified code:
public static void main(String[] args) throws Exception { System.out.println("Loading Params"); SerialParameters params = new SerialParameters(); params.setCommPortId("COM3"); params.setBaudRate(9600); params.setDataBits(8); params.setStopBits(1); params.setParity(0); System.out.println("Creating Device"); localDevice = new LocalDevice(1234, new Transport(new MstpNetwork(new MasterNode(params,(byte) 0x01,1)))); try { System.out.println("Initilising"); localDevice.initialize(); localDevice.getEventHandler().addListener(new Listener()); localDevice.sendGlobalBroadcast(new WhoIsRequest()); System.out.println("Listening"); Thread.sleep(20000); System.out.println("Done"); } finally { localDevice.terminate(); } } static class Listener extends DeviceEventAdapter { @Override public void iAmReceived(RemoteDevice d) { System.out.println("IAm received from " + d); } }
Thanks for any help you can give,
KT
-
Can you try putting in a pause after initializing the local device, using "Thread.sleep(###)"? There may be a delay while the device waits to join the network, during which your requests might be timing out. Start with something like 10 seconds to see if this works, and then reduce the time as much as you can.
-
That didn't fix it, I even went up to 30 seconds, same problem. the original program I had initialized them on startup then the user manually triggered the whoIs so there was usually a substantial delay between initialisation and broadcast anyway. I also tried this:
System.out.println("Creating Device"); localDevice = new LocalDevice(1234, new Transport(new MstpNetwork(new MasterNode(params,(byte) 0x01,1)))); try { System.out.println("Initilising"); localDevice.initialize(); Thread.sleep(10000); localDevice.getEventHandler().addListener(new Listener()); for(int i=1; i<=20;i++) { localDevice.sendGlobalBroadcast(new WhoIsRequest()); System.out.println("Broadcast "+i); Thread.sleep(20000); } System.out.println("Done"); } finally { localDevice.terminate(); }
And got the following:
Loading Params
Creating Device
Initilising
Broadcast 1
Broadcast 2
Broadcast 3
Broadcast 4
Broadcast 5
Broadcast 6
Broadcast 7
Broadcast 8
Broadcast 9
Broadcast 10
Broadcast 11
Broadcast 12
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[7]], linkServiceAddress=null)
Broadcast 13
Broadcast 14
Broadcast 15
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[7]], linkServiceAddress=null)
Broadcast 16
Broadcast 17
Broadcast 18
Broadcast 19
Broadcast 20
DoneI then did the same, but changed the mac address about 5 seconds before each broadcast and got the following:
Loading Params
Creating Device
Initilising
Broadcast 1
Broadcast 2
Broadcast 3
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[9]], linkServiceAddress=null)
Broadcast 4
Broadcast 5
Broadcast 6
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[15]], linkServiceAddress=null)
Broadcast 7
Broadcast 8
Broadcast 9
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[11]], linkServiceAddress=null)
Broadcast 10
Broadcast 11
Broadcast 12
Broadcast 13
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=[f]], linkServiceAddress=null)
Broadcast 14
Broadcast 15
Broadcast 16
Broadcast 17
Broadcast 18
Broadcast 19
IAm received from RemoteDevice(instanceNumber=9999, address=Address [networkNumber=0, macAddress=**], linkServiceAddress=null)
Broadcast 20
Done -
Any other Suggestions as to what it might be?