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