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

How read and write values from local devices ?


  • Hi everyone,
    i'm using some examples codes, recently i discover that i have to use localDevices and not remoteDevices, so i read the instance number, but i want to read the present value too and change these values.

    Here is the code that i'm using:

    
    package com.bacnet.webservice;
    
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    
    import com.serotonin.bacnet4j.LocalDevice;
    import com.serotonin.bacnet4j.RemoteDevice;
    import com.serotonin.bacnet4j.event.DefaultDeviceEventListener;
    import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
    import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
    import com.serotonin.bacnet4j.type.constructed.SequenceOf;
    import com.serotonin.bacnet4j.type.enumerated.ObjectType;
    import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
    import com.serotonin.bacnet4j.type.enumerated.Segmentation;
    import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
    
    public class Test2 {
        public static void main(String[] args) throws Exception {
            LocalDevice localDevice = new LocalDevice(101, "192.168.1.255");
            localDevice.getEventHandler().addListener(new Listener());
            localDevice.setPort(47808);
            localDevice.initialize();
    
            // Read
            ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.analogInput, 243), PropertyIdentifier.presentValue);
            getObjectList(localDevice, "192.168.1.149", 0xBAC0, 101);
    
            localDevice.terminate();
        }
    
        private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId) throws Exception {
            InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
            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);
            SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue();
            for (ObjectIdentifier oid : oids)
                System.out.println("    " + oid);
    
        }
    
        static class Listener extends DefaultDeviceEventListener {
            @Override
            public void iAmReceived(RemoteDevice d) {
                System.out.println("IAm received" + d);
            }
        }
    }
    
    

    My output:

    
    run:
    IP: 192.168.1.149
        Device 101
        Analog Value 0
        Analog Value 1
        Binary Value 1
        Binary Value 0
    
    

    Here is a print screen from my bacnet table, just to make sure i'm not doing anything wrong =)
    http://i944.photobucket.com/albums/ad284/mascaranegra/internet/exporttable.jpg


  • Hi everyone,
    based in examples i'm trying to write in my digital output, here's my code:

    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.bacnet.test;
    
    import com.serotonin.bacnet4j.LocalDevice;
    import com.serotonin.bacnet4j.Network;
    import com.serotonin.bacnet4j.RemoteDevice;
    import com.serotonin.bacnet4j.RemoteObject;
    import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
    import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
    import com.serotonin.bacnet4j.service.confirmed.WritePropertyRequest;
    import com.serotonin.bacnet4j.type.Encodable;
    import com.serotonin.bacnet4j.type.constructed.SequenceOf;
    import com.serotonin.bacnet4j.type.enumerated.ObjectType;
    import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
    import com.serotonin.bacnet4j.type.enumerated.Segmentation;
    import com.serotonin.bacnet4j.type.primitive.Null;
    import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
    import com.serotonin.bacnet4j.type.primitive.Real;
    import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    
    /**
     *
     * @author Valter
     */
    public class Light {
    
        private static LocalDevice localDevice;
    
        public static void main(String[] args) throws Exception {
            localDevice = new LocalDevice(101, "192.168.1.255");
            localDevice.setPort(47808);
            localDevice.initialize();
    
            // Find the device
            if (localDevice.getRemoteDevices().isEmpty()) {
                System.out.println("No remote devices responded");
            }
    
            getObjectList(localDevice, "192.168.1.149", 0xBAC0, 101);
    
            localDevice.terminate();
        }
    
        private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId) throws Exception {
            InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
            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);
            SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue();
            
            int i = 0;
            for (ObjectIdentifier oid : oids) {
                System.out.println("--------  " + oid.getInstanceNumber());
                //System.out.println();
                
                //1 : not writable
                //2 : writable
                //3 : not writable
                //4 : writable
    
                // Rotator
    //            if (i == 2){
    //                for (int j = 1; j <=16; j++){
    //                    setPresentValue(addr, read, oid, new Real(16), j);
    //                }
    //            }
                // 4 it's a lamp that i'm trying to on
                if (i == 4){
                    for (int k = 1; k <=16; k++){
                        setPresentValue(addr, read, oid, new Null(), k);
                    }
                }
                i++;
            }
    
        }
    
        private static void setPresentValue(InetSocketAddress addr, ReadPropertyRequest read, ObjectIdentifier objectIdentifier, Encodable value, int priority) throws Exception {
            WritePropertyRequest wpr = new WritePropertyRequest(objectIdentifier , PropertyIdentifier.presentValue, null, value, new UnsignedInteger(priority));
            localDevice.send(addr, null, 1476, Segmentation.segmentedBoth, wpr);
        }
    }
    
    

    But nothing happens..
    Any help ?

    Thanks.


  • Hi guys,

    someone could help me please ?

    I really need to read/ write some values from my device.

    Please.

    Best regards,
    Valter Henrique.


  • Hi everyone,
    i finally found it what was my mistake, so i replace by this and works fine!

    
                if (i == 4){
                    for (int k = 1; k <=16; k++){
                        setPresentValue(addr, read, oid, new com.serotonin.bacnet4j.type.primitive.Boolean(true) , k); // alternate between true and false input
                    }
                }
    
    

    Thank you Serotonin by this great project, really thanks!


  • Hi everyone,

    i need to read the values of my objects, i only can read the instance number:

    
        private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId, float value) throws Exception {
            InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
            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);
            SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue();
    
            int i = 0;
            for (ObjectIdentifier oid : oids) {
                System.out.println("--------  " + oid.getInstanceNumber());
            }
    
        }
    
    

    But how read the value of each object ?
    For example, i would like to read '15' from my analog output object, o true or false from my digital values and go on.
    image

    I try to write this code:

    
            InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
            ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.analogOutput, deviceId), PropertyIdentifier.priorityArray);
            ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(addr, null, 1476, Segmentation.segmentedBoth, read);
            PriorityArray priorityArray = (PriorityArray) ack.getValue();
    
            float priority = priorityArray.get(16).getRealValue().floatValue();
            System.out.println("priorityArray = " + priority);
    
    

    But is not working.

    Could anyone help me with this please ?

    Best regards,
    Valter Henrique.


  • Hi Valter,

    Are you using the bacnet device in real environment or simulating a virtual device in your computer and make a java program to read/write values ?

    If you are simulating it, Which program are you using to simulate the bacnet device ?

    Thanks


  • Hi Guven, i'm using a real enviroment.

    One FX 20 from Johnson Controls and another FX 06 from Johnson Controls too.


  • It means that I need real device to develop a application by using bacnet4j..Right?

    In your code, could you explain where your code is running? In the controller or in computer ?

    I need to develop an application to get alarms information from bacnet software (by the way, this bacnet software is Andover Continuum - Schneider Electric),

    I also need to develop an application get alarms information as a string and convert it to bacnet protocol and inform bacnet software? This bacnet software actually is managing and controlling subsystems which some of these subsystem's protocol is not bacnet..One of them is Web service so only way to get alarms is to call Web services method and convert to bacnet protocol and pass this info to bacnet software..

    could it be possible develop an application like this with bacnet4j ?


  • Hi Guve,
    i believe @mlohbihler is the person more capable to answer this to you dude.

    I'm waiting for an answer from him too, let's wait =)


  • @Valter Henrique said:

    Hi everyone,

    i need to read the values of my objects, i only can read the instance number:

    
       private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId, float value) throws Exception {
           InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
           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);
           SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue();
    
           int i = 0;
           for (ObjectIdentifier oid : oids) {
               System.out.println("--------  " + oid.getInstanceNumber());
           }
    
       }
    
    

    But how read the value of each object ?
    For example, i would like to read '15' from my analog output object, o true or false from my digital values and go on.
    image

    I try to write this code:

    
           InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);
           ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.analogOutput, deviceId), PropertyIdentifier.priorityArray);
           ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(addr, null, 1476, Segmentation.segmentedBoth, read);
           PriorityArray priorityArray = (PriorityArray) ack.getValue();
    
           float priority = priorityArray.get(16).getRealValue().floatValue();
           System.out.println("priorityArray = " + priority);
    
    

    But is not working.

    Could anyone help me with this please ?

    Best regards,
    Valter Henrique.

    Hi, someone could help me with this please ?

    mlohbihler , could you help me, please ?

    Thanks in advance.