• Recent
    • Tags
    • Popular
    • Register
    • Login

    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 Mango 5 Documentation Website

    ArrayIndexOutOfBoundsException in CommandPriorityTest

    BACnet4J general discussion
    2
    5
    3.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      Valter Henrique
      last edited by

      Hi everyone,
      i could run almost all examples, but i really need run this one 'CommandPriorityTest.java', i want to set the present value of my object.

      So i try to run, and gives me this error:

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
              at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:343)
              at com.bacnet.webservice.CommandPriorityTest.main(CommandPriorityTest.java:46)
      

      Here's my code:

      /*
          Copyright (C) 2006-2009 Serotonin Software Technologies Inc.
       	@author Matthew Lohbihler
       */
      package com.bacnet.webservice;
      
      import com.serotonin.bacnet4j.LocalDevice;
      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.service.unconfirmed.WhoHasRequest;
      import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
      import com.serotonin.bacnet4j.type.Encodable;
      import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
      import com.serotonin.bacnet4j.type.primitive.CharacterString;
      import com.serotonin.bacnet4j.type.primitive.Null;
      import com.serotonin.bacnet4j.type.primitive.Real;
      import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
      
      /**
       * @author Matthew Lohbihler
       */
      public class CommandPriorityTest {
          private static LocalDevice localDevice;
          private static RemoteDevice remoteDevice;
          private static RemoteObject remoteObject;
          
          public static void main(String[] args) throws Exception {
              String objectName = "Command Priority Test";
              localDevice = new LocalDevice(101, "255.255.255.255"); // the only thing i change is the device id
              localDevice.initialize();
              
              // Who is
              localDevice.sendBroadcast(2068, null, new WhoIsRequest());
              Thread.sleep(1000);
              
              // Who has
              localDevice.sendBroadcast(2068, null, new WhoHasRequest(null, new CharacterString(objectName)));
              
              // Wait a bit for responses to come in.
              Thread.sleep(1000);
              
              // Find the device
              remoteDevice = localDevice.getRemoteDevices().get(0);
      //        localDevice.getExtendedDeviceInformation(remoteDevice);
      //        List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>)localDevice.sendReadPropertyAllowNull(
      //                remoteDevice, remoteDevice.getObjectIdentifier(), PropertyIdentifier.objectList)).getValues();
      //        for ()
      //        remoteDevice.setObject(new RemoteObject())
              
              
              // Find the object.
              for (RemoteObject o : remoteDevice.getObjects()) {
                  if (o.getObjectName().equals(objectName)) {
                      remoteObject = o;
                      break;
                  }
              }
                  
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Real(16), 16);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Real(15), 15);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Null(), 16);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Real(16), 16);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Real(10), 10);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Null(), 10);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Null(), 15);
              getPresentValue();
              getPriorityArray();
              
              setPresentValue(new Null(), 16);
              getPresentValue();
              getPriorityArray();
              
              
              localDevice.terminate();
          }
          
          private static void getPresentValue() throws Exception {
              ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
                      PropertyIdentifier.presentValue);
              ReadPropertyAck ack = (ReadPropertyAck)localDevice.send(remoteDevice, rpr);
              System.out.println("Present value: "+ ack.getValue());
          }
          
          private static void getPriorityArray() throws Exception {
              ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
                      PropertyIdentifier.priorityArray);
              ReadPropertyAck ack = (ReadPropertyAck)localDevice.send(remoteDevice, rpr);
              System.out.println("Priority array: "+ ack.getValue());
          }
          
          private static void setPresentValue(Encodable value, int priority) throws Exception {
              WritePropertyRequest wpr = new WritePropertyRequest(remoteObject.getObjectIdentifier(),
                      PropertyIdentifier.presentValue, null, value, new UnsignedInteger(priority));
              localDevice.send(remoteDevice, wpr);
          }
      }
      

      Any idea ?

      Best regards,
      Valter Henrique.

      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        This test class works under the expectation that the device you want to communicate with will respond to a WhoIs request (or at least be the first to respond) within one second. Below, at lines 36 and 40 WhoIs and WhoHas requests are sent respectively. Responses to these cause the responder to be automatically registered in the list of known remote devices. If nothing has responded, you will the the error that you have gotten.

        If you want a cleaner message, you can check if the list in question is empty, print out a messages like "no devices responded", and return.

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • V
          Valter Henrique
          last edited by

          @mlohbihler, i have a supervisory that is composed by a FX 20 and a FX 06 both from Johnson Controls, i connected my FX 20 in my router, so i can connect with it acessing 192.168.1.149 inside my LAN.
          So i wonder how i can change the value from my device ?
          I can read those values, but i don't know how to change them.

          If you can help me, i appreciate.

          I could run some example and paste it here to help us.

          Best regards,
          Valter Henrique.

          1 Reply Last reply Reply Quote 0
          • V
            Valter Henrique
            last edited by

            @mlohbihler, i follow your suggestion and happens what you say, no remote devices responds.
            I think in my case is just local devices .
            Well, this is my code if could help anyone:

            
            /*
            Copyright (C) 2006-2009 Serotonin Software Technologies Inc.
            @author Matthew Lohbihler
             */
            package com.bacnet.ready;
            
            import com.serotonin.bacnet4j.LocalDevice;
            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.service.unconfirmed.WhoHasRequest;
            import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
            import com.serotonin.bacnet4j.type.Encodable;
            import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
            import com.serotonin.bacnet4j.type.primitive.CharacterString;
            import com.serotonin.bacnet4j.type.primitive.Null;
            import com.serotonin.bacnet4j.type.primitive.Real;
            import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
            
            /**
             * @author Matthew Lohbihler
             */
            public class CommandPriorityTest {
            
                private static LocalDevice localDevice;
                private static RemoteDevice remoteDevice;
                private static RemoteObject remoteObject;
            
                public static void main(String[] args) throws Exception {
                    String objectName = "Command Priority Test";
                    localDevice = new LocalDevice(101, "192.168.1.255");
                    localDevice.initialize();
            
                    // Who is
                    localDevice.sendBroadcast(47808, null, new WhoIsRequest());
                    Thread.sleep(1000);
            
                    // Who has
                    localDevice.sendBroadcast(47808, null, new WhoHasRequest(null, new CharacterString(objectName)));
            
                    // Wait a bit for responses to come in.
                    Thread.sleep(1000);
            
                    // Find the device
                    if (localDevice.getRemoteDevices().isEmpty()) {
                        System.out.println("No devices responded");
                    } else {
                        remoteDevice = localDevice.getRemoteDevices().get(0);
            //        localDevice.getExtendedDeviceInformation(remoteDevice);
            //        List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>)localDevice.sendReadPropertyAllowNull(
            //                remoteDevice, remoteDevice.getObjectIdentifier(), PropertyIdentifier.objectList)).getValues();
            //        for ()
            //        remoteDevice.setObject(new RemoteObject())
            
            
                        // Find the object.
                        for (RemoteObject o : remoteDevice.getObjects()) {
                            if (o.getObjectName().equals(objectName)) {
                                remoteObject = o;
                                break;
                            }
                        }
            
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Real(16), 16);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Real(15), 15);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Null(), 16);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Real(16), 16);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Real(10), 10);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Null(), 10);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Null(), 15);
                        getPresentValue();
                        getPriorityArray();
            
                        setPresentValue(new Null(), 16);
                        getPresentValue();
                        getPriorityArray();
            
            
                    }
                        localDevice.terminate();
                }
            
                private static void getPresentValue() throws Exception {
                    ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
                            PropertyIdentifier.presentValue);
                    ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(remoteDevice, rpr);
                    System.out.println("Present value: " + ack.getValue());
                }
            
                private static void getPriorityArray() throws Exception {
                    ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
                            PropertyIdentifier.priorityArray);
                    ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(remoteDevice, rpr);
                    System.out.println("Priority array: " + ack.getValue());
                }
            
                private static void setPresentValue(Encodable value, int priority) throws Exception {
                    WritePropertyRequest wpr = new WritePropertyRequest(remoteObject.getObjectIdentifier(),
                            PropertyIdentifier.presentValue, null, value, new UnsignedInteger(priority));
                    localDevice.send(remoteDevice, wpr);
                }
            }
            
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post