RejectAPDUException
-
Hello,
I am new to both BACNet as well as bacnet4j. I am receiving RejectAPDUException when I try to read the properties of devices and am not sure how to resolve this.
The code I run:
/* * ============================================================================ * GNU Lesser General Public License * ============================================================================ * * Copyright (C) 2006-2009 Serotonin Software Technologies Inc. http://serotoninsoftware.com * @author Matthew Lohbihler * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ package com.serotonin.bacnet4j.test; import java.io.IOException; import java.util.List; import com.serotonin.bacnet4j.LocalDevice; import com.serotonin.bacnet4j.RemoteDevice; import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest; 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.primitive.ObjectIdentifier; import com.serotonin.bacnet4j.util.PropertyReferences; /** * @author Matthew Lohbihler */ public class DiscoveryTest { @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { System.out.println("Starting Discovery Test"); LocalDevice localDevice = new LocalDevice(1, "192.168.1.255"); try { localDevice.initialize(); }catch(IOException e) { System.out.println("IO Error!"); e.printStackTrace(); return; } System.out.println("localDevice initialized"); // Who is localDevice.sendBroadcast(47808, new WhoIsRequest(null, null)); // localDevice.sendUnconfirmed( // new Address(new UnsignedInteger(47808), new OctetString(new byte[] {(byte)206, (byte)210, 100, (byte)134})), // new WhoIsRequest(new UnsignedInteger(105), new UnsignedInteger(105))); // RemoteDevice rd = new RemoteDevice(105, new Address(new UnsignedInteger(47808), // new OctetString(new byte[] {(byte)206, (byte)210, 100, (byte)134})), null); // rd.setSegmentationSupported(Segmentation.segmentedBoth); // rd.setMaxAPDULengthAccepted(1476); // localDevice.addRemoteDevice(rd); // Wait a bit for responses to come in. System.out.println("Sleeping..."); Thread.sleep(5000); System.out.println("Awake."); // Get extended information for all remote devices. if(localDevice.getRemoteDevices().isEmpty()) { System.out.println("device list empty..."); } else { System.out.println("device list size = " + localDevice.getRemoteDevices().size()); } int i = 0; for (RemoteDevice d : localDevice.getRemoteDevices()) { System.out.println("device " + i + " processed?"); i++; localDevice.getExtendedDeviceInformation(d); List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>)localDevice.sendReadPropertyAllowNull( d, d.getObjectIdentifier(), PropertyIdentifier.objectList)).getValues(); PropertyReferences refs = new PropertyReferences(); System.out.println("oids = " + oids.size()); for (ObjectIdentifier oid : oids) { //System.out.println("oid"); addPropertyReferences(refs, oid); } localDevice.readProperties(d, refs); System.out.println("readProperties:"); System.out.println(d); } // Wait a bit for responses to come in. Thread.sleep(2000); localDevice.terminate(); } private static void addPropertyReferences(PropertyReferences refs, ObjectIdentifier oid) { refs.add(oid, PropertyIdentifier.objectName); ObjectType type = oid.getObjectType(); System.out.print("oid instanceNum = " + oid.getInstanceNumber()); System.out.print(", oid.TYPE_ID = " + oid.TYPE_ID); System.out.print(", type = " + type.toString()); System.out.println(", intVal = " + type.intValue() + "\n"); //System.out.println("refs.map = " + refs.getProperties().toString() + "\n"); if (ObjectType.accumulator.equals(type)) { refs.add(oid, PropertyIdentifier.units); } else if (ObjectType.analogInput.equals(type) || ObjectType.analogOutput.equals(type) || ObjectType.analogValue.equals(type) || ObjectType.pulseConverter.equals(type)) { refs.add(oid, PropertyIdentifier.units); } else if (ObjectType.binaryInput.equals(type) || ObjectType.binaryOutput.equals(type) || ObjectType.binaryValue.equals(type)) { //System.out.println("binary"); refs.add(oid, PropertyIdentifier.inactiveText); refs.add(oid, PropertyIdentifier.activeText); } else if (ObjectType.lifeSafetyPoint.equals(type)) { refs.add(oid, PropertyIdentifier.units); } else if (ObjectType.loop.equals(type)) { refs.add(oid, PropertyIdentifier.outputUnits); } else if (ObjectType.multiStateInput.equals(type) || ObjectType.multiStateOutput.equals(type) || ObjectType.multiStateValue.equals(type)) { refs.add(oid, PropertyIdentifier.stateText); } else return; refs.add(oid, PropertyIdentifier.presentValue); } }
The resulting output:
Starting Discovery Test localDevice initialized Sleeping... Awake. device list size = 1 device 0 processed? oids = 40 oid instanceNum = 10000, oid.TYPE_ID = 12, type = Device, intVal = 8 oid instanceNum = 1, oid.TYPE_ID = 12, type = Notification Class, intVal = 15 oid instanceNum = 2, oid.TYPE_ID = 12, type = Notification Class, intVal = 15 oid instanceNum = 3, oid.TYPE_ID = 12, type = Notification Class, intVal = 15 oid instanceNum = 10010, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10011, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10012, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10050, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10051, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10052, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10090, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10091, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10092, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10213, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10253, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10293, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10488, oid.TYPE_ID = 12, type = Binary Output, intVal = 4 oid instanceNum = 10489, oid.TYPE_ID = 12, type = Binary Output, intVal = 4 oid instanceNum = 10490, oid.TYPE_ID = 12, type = Binary Output, intVal = 4 oid instanceNum = 10491, oid.TYPE_ID = 12, type = Binary Output, intVal = 4 oid instanceNum = 10500, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10501, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10502, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10503, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10504, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10505, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10506, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10507, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10579, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10580, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 10582, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11500, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11501, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11502, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11503, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11504, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11506, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 11508, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 16401, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 oid instanceNum = 16404, oid.TYPE_ID = 12, type = Multi-state Input, intVal = 13 reject pdu type: 6 Exception in thread "main" com.serotonin.bacnet4j.exception.RejectAPDUException: com.serotonin.bacnet4j.apdu.Reject@7df at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:426) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:401) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:394) at com.serotonin.bacnet4j.LocalDevice.readProperties(LocalDevice.java:812) at com.serotonin.bacnet4j.test.DiscoveryTest.main(DiscoveryTest.java:101)
Any help would be greatly appreciated!
Thanks
-Johnny
-
Hi Johnny,
The request may be getting rejected because the device may not be able to fit all of the requested values into its response. This happens more frequently if the device doesn't support segmentation, but can also happen if it does.
Try using the attached jar. It includes some enhancements around this stuff. I can't guarantee it will fix things, but give it a try.
Attachment: download link
-
Hey,
Thanks for helping.
Unfortunately it gives the exact same error.
If it is any help:
executing addPropertyReferences(refs, oid) only on the first oid causes no error and returns:Starting Discovery Test localDevice initialized Sleeping... Awake. device list size = 1 device 0 processed? oids = 40 oid instanceNum = 10000, oid.TYPE_ID = 12, type = Device, intVal = 8 here readProperties: RemoteDevice(instanceNumber=10000, address=Address(networkNumber=47808, macAddress=[c0,a8,1,2]), network=null)
Executing addPropertyReferences(refs, oid) on the second oid and onwards causes the Reject.
Any other ideas why this might be happening?
-
I still believe the problem is the device can't fit its data into its response, and so it aborts. The attachment was a possible workaround. Try doing the addPropertyReferences thing individually on each property and see what happens.