Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Not able to read analog values from device


  • Not able to read analog values from device
    public class Test {
    static LocalDevice lDevice;
    /static ResourceBundle resource = ResourceBundle
    .getBundle("com.serotonin.bacnet4j/bacnet4j");
    /

    public Test() {
    }
    
    public static void main(String args[]) {
    	initializeDevice();
    }
    
    public static void initializeDevice() {
    	try {
    		System.out.println("Inicializando...");
    		IpNetwork ipNetwork = new IpNetwork("172.28.14.255", 47808,	"172.28.14.63");
    		Transport transport = new Transport(ipNetwork);
    		lDevice = new LocalDevice(9899, transport);
    		lDevice.initialize();
    		lDevice.getEventHandler().addListener(new Listener());
    		lDevice.sendGlobalBroadcast(new WhoIsRequest());
    		Thread.sleep(500);
    

    // RemoteDevice rd = new RemoteDevice(101, new Address(new byte[] { (byte) 1, (byte) 2, 3, (byte) 4 }, 47808), null);
    // lDevice.addRemoteDevice(rd);
    //
    @SuppressWarnings("unused")
    ReadPropertyRequest read = new ReadPropertyRequest(
    new ObjectIdentifier(ObjectType.analogInput, 243),PropertyIdentifier.presentValue);
    getObjectList(lDevice, "172.28.14.63", 47808, 17800);
    } catch (Exception e) {
    System.out.println("Error al inicializar " + e.getMessage());
    } finally {
    closeDevice();
    }
    }

    public static AcknowledgementService send(LocalDevice d,
    		ConfirmedRequestService s) throws Exception {
    	Address a = new Address(InetAddrCache.get("localhost", 0xbac1));
    	return d.send(a, null, MaxApduLength.UP_TO_1476,	Segmentation.segmentedBoth, s);
    }
     
    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) {
    	for (RemoteDevice d : localDevice.getRemoteDevices()) {
    		ObjectIdentifier oid = d.getObjectIdentifier();
    

    // 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(d, new ReadPropertyRequest(oid, PropertyIdentifier.presentValue));
    // System.out.println("Value: " + ack.getValue());

    // InetSocketAddress addr1 = new InetSocketAddress(InetAddress.getByName(ip), port);
    // System.out.println(addr1.toString());

    // networkNumber=0, macAddress=[ac,1c,e,64,ba,c0]
    Address addr = new Address(0, "172.28.14.63");
    ReadPropertyAck ack;
    try {
    ack = (ReadPropertyAck) localDevice.send(addr, null, MaxApduLength.UP_TO_1476, Segmentation.segmentedBoth, read);
    System.out.println("Value: " + ack.getValue());
    } catch (BACnetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    // System.out.println(send(lDevice, new ReadPropertyRequest(oid, PropertyIdentifier.objectName, null)));
    // System.out.println(send(lDevice, new ReadPropertyRequest(created, PropertyIdentifier.presentValue, null)));
    // System.out.println(send(lDevice, new ReadPropertyRequest(oid, PropertyIdentifier.objectList,
    // new UnsignedInteger(0))));

    // ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(d,
    // new ReadPropertyRequest(oid,
    // PropertyIdentifier.protocolServicesSupported));
    // System.out.println("Value: " + ack.getValue());

    	/*	@SuppressWarnings("unchecked")
    		SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack
    				.getValue();
    		for (ObjectIdentifier oid1 : oids) {
    			System.out.println("    " + oid1.getObjectType());
    		}
    
    		PropertyIdentifier pids = (PropertyIdentifier) ack.getValue();
    		System.out.println("    " + pids);*/
    	}
    	
    }
    

    }
    am getting an exception
    com.serotonin.bacnet4j.exception.ErrorAPDUException: ErrorAPDU(choice=12, errorClass=Object, errorCode=Unknown object)
    at com.serotonin.bacnet4j.transport.Transport.send(Transport.java:202)
    at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:381)
    at com.lnt.test.Test.getObjectList(Test.java:99)
    at com.lnt.test.Test.initializeDevice(Test.java:55)
    at com.lnt.test.Test.main(Test.java:35)
    can some one help on this


  • Hi there I think I may be able to point you in the right direction.

    In your method getObjectList(localDevice, ip, port, deviceId) you may be using the wrong Object Identifier. You are hard coding the deviceId to 17800 but you are requesting the object list for all remote devices that have been discovered. I was able to get your code to work on my test platform by changing the following:

    ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.device, deviceId), PropertyIdentifier.objectList);
    

    to:

    ReadPropertyRequest read = new ReadPropertyRequest(oid,PropertyIdentifier.objectList);
    

    This change ensures that you are using the ObjectIdentifier for the remote devices that have been discovered.


  • Thanks a lot for your replay !!!
    ya i tried in your way am ...please see this code
    now my source code is ...

    package com.lnt.TestApp;

    import java.util.List;

    import com.serotonin.bacnet4j.LocalDevice;
    import com.serotonin.bacnet4j.RemoteDevice;
    import com.serotonin.bacnet4j.enums.MaxApduLength;
    import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
    import com.serotonin.bacnet4j.service.acknowledgement.AcknowledgementService;
    import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
    import com.serotonin.bacnet4j.service.confirmed.ConfirmedRequestService;
    import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
    import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
    import com.serotonin.bacnet4j.transport.Transport;
    import com.serotonin.bacnet4j.type.constructed.Address;
    import com.serotonin.bacnet4j.type.constructed.SequenceOf;
    import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
    import com.serotonin.bacnet4j.type.enumerated.Segmentation;
    import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
    import com.serotonin.bacnet4j.util.RequestUtils;

    public class Test {
    static LocalDevice lDevice;
    static Address addr = new Address(0, "172.28.14.100");

    public Test() {
    }
    
    public static void main(String args[]) {
    	initializeDevice();
    }
    
    public static void initializeDevice() {
    	try {
    		System.out.println("Initializing...");
    		IpNetwork ipNetwork = new IpNetwork("172.28.14.255", 47808,	"172.28.14.63");
    		Transport transport = new Transport(ipNetwork);
    		lDevice = new LocalDevice(9899, transport);
    		lDevice.initialize();
    		lDevice.getEventHandler().addListener(new Listener());
    		lDevice.sendGlobalBroadcast(new WhoIsRequest());
    		Thread.sleep(500);
    
    		getObjectList(lDevice, "172.28.14.100",	47808, 0);
    	} catch (Exception e) {
    		System.out.println("Error : " + e.getMessage());
    	} finally {
    		closeDevice();
    	}
    }
    
    public static AcknowledgementService send(LocalDevice d,
    		ConfirmedRequestService s) throws Exception {
    

    // Address a = new Address(InetAddrCache.get("localhost", 0xbac1));
    return d.send(addr, null, MaxApduLength.UP_TO_1476, Segmentation.segmentedBoth, s);
    }

    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 {
    	for (RemoteDevice d : localDevice.getRemoteDevices()) {
    

    // ObjectIdentifier oid = d.getObjectIdentifier();
    @SuppressWarnings("unchecked")
    List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>) RequestUtils
    .sendReadPropertyAllowNull(localDevice, d, d.getObjectIdentifier(),PropertyIdentifier.objectList)).getValues();

    		for (int i = 0; i < oids.size(); i++) {
    			System.out.println("OBjectIdentifier"+oids);
    		}
    		
    		for (ObjectIdentifier oid : oids) {
    			
    			ReadPropertyRequest read = new ReadPropertyRequest(oid,	PropertyIdentifier.deviceAddressBinding);
    			ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(d, read); 
    			
    			System.out.println("Value: " + ack.getValue());
    			
    
    		}
    		
    	}
    }
    

    }

    and my optpuit is
    Segmentation: both
    OBjectIdentifier[Device 9899]
    Value: []
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    OBjectIdentifier[Device 0, Analog Value 1, Analog Value 2, Trend Log 1, Trend Log 2, File 0]
    but i want analog values form that any hint ???


  • can u please replay ,,

    can u please see my code where am going wrong????


  • can u send the code for ReadRangeRequest, and ReadRangeAck


  • Sorry I have been very busy lately with other work. All BACNet4j source is here http://sourceforge.net/projects/bacnet4j/

    Also, the code you posted isn't complete, you have not provided the source for the Listener class so I was unable to run the code you posted.


  • I just realized the new BACNet4j code is located in GitHub here: https://github.com/mlohbihler/BACnet4J

    Sorry for the confusion.