Read BACnet ObjectValues
-
Hello everyone!
I am beginning with BACnet4j project. I think it is a great project, so i am very glad with it.
I am trying to read BACnet object values from my computer with a Java project. My code is:public class BACnetNetwork { static LocalDevice lDevice; static ResourceBundle resource = ResourceBundle.getBundle("resources/bacnet4j"); public BACnetNetwork(){} public static void main(String args[]){ initializeDevice(); } public static void initializeDevice(){ try{ System.out.println("Inicializando..."); lDevice = new LocalDevice(17800, resource.getString("localDeviceIP")); lDevice.getEventHandler().addListener(new Listener()); lDevice.initialize(); //System.out.println("Remote Devices..."+lDevice.get); @SuppressWarnings("unused") ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.analogInput, 243), PropertyIdentifier.presentValue); getObjectList(lDevice, resource.getString("deviceIP"), Integer.valueOf(resource.getString("port")), 17800); }catch(Exception e){ System.out.println("Error al inicializar "+e.getMessage()); }finally{ closeDevice(); } } public static void closeDevice(){ try{ lDevice.terminate(); }catch(Exception e){ System.out.println(e.getMessage()); } } private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId) throws Exception { InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port); System.out.println(addr.toString()); ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.device, deviceId), PropertyIdentifier.objectList); ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(addr, null, 1476, Segmentation.segmentedBoth, read); System.out.println("IP: " + ip); @SuppressWarnings("unchecked") SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue(); for (ObjectIdentifier oid : oids) { System.out.println(" " + oid.getObjectType()); } PropertyIdentifier pids = (PropertyIdentifier) ack.getValue(); System.out.println(" " + pids); } static class Listener extends DefaultDeviceEventListener { @Override public void iAmReceived(RemoteDevice d) { System.out.println("I am received" + d); } }
However, when I run, the output shows:
P: 192.168.107.247 Device 17800 Analog Input 0 Multi-state Input 0 Analog Input 1 Trend Log 1 Trend Log 2 Trend Log 3 File 0
I have been studying a BACnet frame from Wireshark, but I do not see any value.
How could I read values from a device?
Thank you very much!!
Regards!Attachment: download link
-
BACnet4J does not store present values for objects. You need to request them using ReadProperty or ReadPropertyMultiple requests, asking objects for their present value property.
-
@mlohbihler said:
BACnet4J does not store present values for objects. You need to request them using ReadProperty or ReadPropertyMultiple requests, asking objects for their present value property.
But in my code I am already using "ReadPropertyRequest". Another option is "ReadPropertyMultipleRequest"
Thanks! -
The only property that you are reading is objectList.
-
@mlohbihler said:
The only property that you are reading is objectList.
Ok!! Thank you very much!! I solve the problem. So, do I need send a ReadPropertyRequest and a ReadPropertyAck for each property? I have tried with PropertyIdentifier.all, however it throws an Exception. If I send a request for each property I can see that property, but I think it could be a lot of load in BAcnet network...
Regards! -
Using the "all" identifier will often result in an exception because the content is too much to put into a single response. BACnet4J will try to compensate in come cases, but it doesn't always work out.
You can ask for multiple properties with a ReadPropertyMultiple request, as long as your equipment supports it.
-
Hello, I am trying to figure out how to use bacnet4j and this thread is helpful however I am still stuck on the various IP addresses and ports used? Can you explain the difference between resource.getString("localDeviceIP"), resource.getString("deviceIP") and resource.getString("port")? Thanks in advance.