Errors when attempting to read
-
Unfortunately I am getting the same error when running the new code:
Exception in thread "main" com.serotonin.bacnet4j.exception.BACnetException: java.lang.reflect.InvocationTargetException at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:172) at com.serotonin.bacnet4j.type.Encodable.readWrapped(Encodable.java:324) at com.serotonin.bacnet4j.type.Encodable.readEncodable(Encodable.java:284) at com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck.<init>(ReadPropertyAck.java:86) at com.serotonin.bacnet4j.service.acknowledgement.AcknowledgementService.createAcknowledgementService(AcknowledgementService.java:44) at com.serotonin.bacnet4j.apdu.ComplexACK.parseServiceData(ComplexACK.java:196) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.waitForAck(IpMessageControl.java:659) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:289) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:269) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:225) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:413) 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:809) at com.serotonin.bacnet4j.LocalDevice.readOidPresentValues(LocalDevice.java:843) at com.serotonin.bacnet4j.LocalDevice.readPresentValues(LocalDevice.java:832) at com.serotonin.bacnet4j.LocalDevice.readPresentValues(LocalDevice.java:825) at com.serotonin.bacnet4j.test.Schneider.ReadProperty(Schneider.java:94) at com.serotonin.bacnet4j.test.Schneider.main(Schneider.java:71) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:169) ... 18 more Caused by: java.lang.ArrayIndexOutOfBoundsException: -1 at com.serotonin.util.queue.ByteQueue.pop(ByteQueue.java:93) at com.serotonin.bacnet4j.base.BACnetUtils.popInt(BACnetUtils.java:57) at com.serotonin.bacnet4j.type.primitive.Real.<init>(Real.java:46) ... 23 more
Thrown by:
@SuppressWarnings("unchecked") protected static <T extends Encodable> T read(ByteQueue queue, Class<T> clazz) throws BACnetException { if (clazz == Primitive.class) return (T)Primitive.createPrimitive(queue); try { return clazz.getConstructor(new Class[] {ByteQueue.class}).newInstance(new Object[] {queue}); } catch (Exception e) { throw new BACnetException(e); } }
Any ideas?
Thanks in advance! -
Hi Randy,
The data in the response doesn't appear to make sense for the context. The object type is Analog Value, which has a present value property of type Real. A real is always a 4 byte value plus a length. For example, 1.23 gets serialized to [44,3f,9d,70,a4]. Also, the first "4" of the "44" says explicitly that the value is a Real.
The response data is [31,5], which says that the type is Signed Integer of length 1 and value 5. This is odd because the only property of this type is the "utc offset" of a "device".
-
So the problem lies with the way my bacnet device is replying to the request, not the code itself?
Would it be possible just to dump (println) the hex value instead of parsing it into an encodable? And if so, how could I do this?
-
The code is written to be as automatic as possible, so there would be effort involved in preventing full parsing of the data. Besides, the hex value would be encoded BACnet data, and might not make a lot of sense.
What is the actual object type configured in your remote device? The BACnet specification clearly says that an Analog Value object has a Real as its present value. Using a Signed Integer is non-compliant.
-
You were correct, this was an error in the way my hardware was responding. The new build fixes that issue.
I am now however having an issue that keeps happening randomly (but this time simply won't fix itself after many attempts). Bacnet4j sends the packet correctly, and the bacnet device responds, but for some reason bacnet4j won't acknowledge the fact that it received an awk packet. There errors are as following:
Write property:
public static int WriteProperty(InetAddress Address, int port, int instanceID, int propertyID,int objectID, float data) throws Exception { LocalDevice localDevice = new LocalDevice(1234, "192.168.0.255"); //create new local device localDevice.initialize(); //initialize the device byte[] IPRaw = new byte[4]; //allocate mem for IP address IPRaw=Address.getAddress(); //Convert InetAddress into bte array RemoteDevice rd = new RemoteDevice(instanceID, new Address(new UnsignedInteger(port), //create a new bacnet drvice with proper Instance ID and IP new OctetString(new byte[] {IPRaw[0], IPRaw[1], IPRaw[2], IPRaw[3]})), null); localDevice.addRemoteDevice(rd); //add newly created bacnet device to the localdevice ObjectIdentifier oid = new ObjectIdentifier(new ObjectType(propertyID),objectID); rd.setSegmentationSupported(Segmentation.segmentedBoth); //needed to send packet properly rd.setMaxAPDULengthAccepted(1476); //max length RemoteObject ro = new RemoteObject(new ObjectIdentifier(new ObjectType(propertyID),objectID)); //create the object based on the right property ID (usually present value), and object ID. rd.setObject(ro); //add object to remote device Thread.sleep(1000); //wait for everything to setup properly localDevice.setPresentValue(rd,oid,new Real(data)); //send data write packet return 1; }
Exception in thread "main" com.serotonin.bacnet4j.exception.BACnetTimeoutException: Timeout while waiting for response for id 0 at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:298) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:269) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:225) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:413) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:401) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:394) at com.serotonin.bacnet4j.LocalDevice.setProperty(LocalDevice.java:848) at com.serotonin.bacnet4j.LocalDevice.setPresentValue(LocalDevice.java:852) at com.serotonin.bacnet4j.test.Schneider.WriteProperty(Schneider.java:160) at com.serotonin.bacnet4j.test.Schneider.main(Schneider.java:73)
read property:
public static String ReadProperty(InetAddress Address, int port, int instanceID, int propertyID, int objectID ) throws Exception { LocalDevice localDevice = new LocalDevice(32491, "192.168.0.255"); //create device to send out packets localDevice.initialize(); //initialize this device byte[] IPRaw = new byte[4]; //allocate mem for IP adress IPRaw=Address.getAddress(); //Convert InetAddress into byte array RemoteDevice rd = new RemoteDevice(instanceID, new Address(new UnsignedInteger(port), //Create a new bacnet device with the proper instance ID and IP new OctetString(new byte[] {IPRaw[0], IPRaw[1], IPRaw[2], IPRaw[3]})), null); localDevice.addRemoteDevice(rd); //add the newly created bacnet device to the localdevice created earlier // ObjectIdentifier oid = new ObjectIdentifier(new ObjectType(propertyID),objectID); //set oid to have the proper property (usually present value), and the right object property on the remote device rd.setSegmentationSupported(Segmentation.segmentedBoth); //Needed to send the packet properly rd.setMaxAPDULengthAccepted(1476); //needed to send the packet properly RemoteObject ro = new RemoteObject(new ObjectIdentifier(new ObjectType(propertyID),objectID)); //create the object based on the right property ID (usually present value), and object ID. rd.setObject(ro); //add the newly created object to the bacnet device Thread.sleep(1000); //wait for everything to setup properly PropertyValues values = localDevice.readPresentValues(rd); PropertyReferences refs = new PropertyReferences(); // refs.add(rd.getObjectIdentifier(), new PropertyIdentifier(propertyID)); refs.add(rd.getObjectIdentifier(), PropertyIdentifier.all); PropertyValues pvs = localDevice.readProperties(rd, refs); ObjectPropertyReference opr = new ObjectPropertyReference(ro.getObjectIdentifier(),new PropertyIdentifier(propertyID)); System.out.println(opr.getPropertyIdentifier().toString()); System.out.println(pvs.getNoErrorCheck(opr)); System.out.println(opr.getPropertyIdentifier().toString()); System.out.println(values.getNoErrorCheck(opr)); String value = values.getString(new ObjectIdentifier(new ObjectType(propertyID),objectID),new PropertyIdentifier(propertyID)); System.out.println(value); return value; }
Exception in thread "main" com.serotonin.bacnet4j.exception.BACnetTimeoutException: Timeout while waiting for response for id 0 at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:298) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:269) at com.serotonin.bacnet4j.npdu.ip.IpMessageControl.send(IpMessageControl.java:225) at com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:413) 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:809) at com.serotonin.bacnet4j.LocalDevice.readOidPresentValues(LocalDevice.java:843) at com.serotonin.bacnet4j.LocalDevice.readPresentValues(LocalDevice.java:832) at com.serotonin.bacnet4j.LocalDevice.readPresentValues(LocalDevice.java:825) at com.serotonin.bacnet4j.test.Schneider.ReadProperty(Schneider.java:99) at com.serotonin.bacnet4j.test.Schneider.main(Schneider.java:74)
The captured packets are here:
http://www.filebox.com/hzrynxyfz9zxAnother bacnet client that I have does not have this issue with the hardware I am using.
And help would be greatly appreciated ?PS. I know that I am writing 3.3 but it is returning 3.0000. Though this should have nothing to do with this issue.
-
If the app had actually received the response and for some reason misinterpreted it, you would see an exception like, "No waiting recipient for message: peer=...". Were there other messages, or just the timeouts?
-
Just the timeout. If you look at the packets in wireshark, bacnet4j sends the request 3 times and gets a reply back each time. For some reason it is refusing to read the awk packet. The packet bacnet4j is sending is identical to the one bacbeat sends out. However, bacbeat recognizes the awk packet and displays the value, while bacnet4j does not, so it shouldn't be a hardware problem.
The code running those 2 methods are here:
InetAddress deviceIP = InetAddress.getByName("192.168.16.3"); WriteProperty(deviceIP,47808,3331779,2,1,(float)3.3); String result = ReadProperty(deviceIP,47808,3331779,2,1);
-
Do you know how to add System.out statements to the code and build the jar? It seems as if BACnet4J isn't getting the response at all, since any other possibility should cause an exception to be thrown.
If so, add the following line in IpMessageControl at line 424:
try { socket.receive(p); System.out.println("Received a packet!"); // ADD THIS LINE incomingExecutorService.execute(new IncomingMessageExecutor(p)); p.setData(buffer); }
If the packet is being received, then we can go down the BACnet4J road. If not, there must be something else preventing its proper routing.
-
Added the line, and complied.
When running the line, nothing changed (did not display the "packet received message").
The question is however, why is bacbeat able to receive the packet while bacnet4j is not?
I have a few computers here, do you think I should try executing on another one?
-
The question is however, why is bacbeat able to receive the packet while bacnet4j is not?
running as root vs. usual user?
windows firewall?
port in use by other program? -
@craig said:
The question is however, why is bacbeat able to receive the packet while bacnet4j is not?
running as root vs. usual user?
windows firewall?
port in use by other program?- Running as administrator (windows)
-I'll shut off windows firewall and test that theory in a bit, though it was working last week with windows firewall on. - Happens directly after a fresh bootup. Before, when my program didn't exit properly I had to restart it to get it working again (thus the port was in use). On a fresh bootup however, I have doubts the bacnet port (47808) would be in use. I will however try to test for this.
Thanks for the tips :)
- Running as administrator (windows)
-
I'm also having the same error "Timeout while waiting for response for id 0 " as Randy.
I'm getting it with the following code: localDevice.getExtendedDeviceInformation(remoteDevice);
I looked at the wireshark and Bacnet4J is sending the readProperty request for property protocol-services-supported 3 times
and my device is answering everytime. I can see the data sent back but Bacnet4J can't seem to catch it.What is weird is that my code was working 1 year ago and tried it again this week and I get this.
Anyone found the reason for that problem or a workaround?
I suspect that something changed in our bacnet network but I don't know what to look for...
thanks!
Eric
-
@Randy hello,Randi, How did you solve the problem of InvocationTargetException,now I am also facing the same problem
-
@BigKING please create a new thread and reference this one. This one was solved over twelve years ago!
Fox