Code-House / bacnet4j-wrapper

Simple facade for bacnet4j api.
GNU General Public License v3.0
48 stars 20 forks source link

Unable to fetch property description #17

Closed x-em closed 1 year ago

x-em commented 2 years ago

Unable to fetch property description

    public static void main(String[] args) {
        BacNetClient client = new BacNetIpClient("192.168.0.245", "192.168.0.164", 32891);
        client.start();
        // given number is timeout in millis
        Set<Device> devices = client.discoverDevices(10000);
        for (Device device : devices) {
            System.out.println(device);

            List<BacNetObject> deviceObjects = client.getDeviceObjects(device);
            for (BacNetObject property : deviceObjects) {
                System.out.println(property.getName() + " " + client.getPresentValue(property,new BypassBacnetConverter()));
            }
        }
        client.stop();
    }

error message

Device [32891 [c0,a8,0,a4,d8,f2] network 0]
Exception in thread "main" org.code_house.bacnet4j.wrapper.api.BacNetClientException: Unable to fetch property description
    at org.code_house.bacnet4j.wrapper.api.BacNetClientBase.createObject(BacNetClientBase.java:268)
    at org.code_house.bacnet4j.wrapper.api.BacNetClientBase.getDeviceObjects(BacNetClientBase.java:83)
    at org.code_house.bacnet4j.wrapper.ip.DeviceTest.main(DeviceTest.java:22)
Caused by: com.serotonin.bacnet4j.exception.BACnetException: java.lang.reflect.InvocationTargetException
    at com.serotonin.bacnet4j.transport.ServiceFutureImpl.result(ServiceFutureImpl.java:79)
    at com.serotonin.bacnet4j.transport.ServiceFutureImpl.get(ServiceFutureImpl.java:64)
    at org.code_house.bacnet4j.wrapper.api.BacNetClientBase.createObject(BacNetClientBase.java:262)
    ... 2 more
Caused by: com.serotonin.bacnet4j.exception.ReflectionException: java.lang.reflect.InvocationTargetException
    at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:244)
    at com.serotonin.bacnet4j.type.AmbiguousValue.convertTo(AmbiguousValue.java:181)
    at com.serotonin.bacnet4j.type.Encodable.readANY(Encodable.java:447)
    at com.serotonin.bacnet4j.type.constructed.Choice.read(Choice.java:106)
    at com.serotonin.bacnet4j.type.constructed.Choice.<init>(Choice.java:79)
    at com.serotonin.bacnet4j.type.Encodable.readChoice(Encodable.java:274)
    at com.serotonin.bacnet4j.type.constructed.ReadAccessResult$Result.<init>(ReadAccessResult.java:141)
    at sun.reflect.GeneratedConstructorAccessor3.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:237)
    at com.serotonin.bacnet4j.type.constructed.SequenceOf.<init>(SequenceOf.java:87)
    at com.serotonin.bacnet4j.type.Encodable.readSequenceOf(Encodable.java:316)
    at com.serotonin.bacnet4j.type.Encodable.readOptionalSequenceOf(Encodable.java:349)
    at com.serotonin.bacnet4j.type.constructed.ReadAccessResult.<init>(ReadAccessResult.java:75)
    at sun.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:237)
    at com.serotonin.bacnet4j.type.constructed.SequenceOf.<init>(SequenceOf.java:74)
    at com.serotonin.bacnet4j.type.Encodable.readSequenceOf(Encodable.java:305)
    at com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyMultipleAck.<init>(ReadPropertyMultipleAck.java:56)
    at com.serotonin.bacnet4j.service.acknowledgement.AcknowledgementService.createAcknowledgementService(AcknowledgementService.java:52)
    at com.serotonin.bacnet4j.apdu.ComplexACK.parseServiceData(ComplexACK.java:211)
    at com.serotonin.bacnet4j.transport.DefaultTransport.completeComplexAckResponse(DefaultTransport.java:760)
    at com.serotonin.bacnet4j.transport.DefaultTransport.receiveAPDU(DefaultTransport.java:682)
    at com.serotonin.bacnet4j.transport.DefaultTransport.receiveImpl(DefaultTransport.java:578)
    at com.serotonin.bacnet4j.transport.DefaultTransport.run(DefaultTransport.java:498)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.serotonin.bacnet4j.type.Encodable.read(Encodable.java:237)
    ... 28 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.serotonin.bacnet4j.util.sero.ByteQueue.pop(ByteQueue.java:291)
    at com.serotonin.bacnet4j.type.primitive.Enumerated.<init>(Enumerated.java:114)
    at com.serotonin.bacnet4j.type.enumerated.BinaryPV.<init>(BinaryPV.java:76)
    ... 33 more
splatch commented 2 years ago

Looking at stacktrace it is a low level/transport issue. Can you tell if target device which causes issue is BTL certified or is it some kind of software?

x-em commented 2 years ago

It's an analog device. Snipaste_2022-09-14_19-13-30

splatch commented 2 years ago

I know that thing. Let me test it and see if it fails for me in similar way!

x-em commented 2 years ago

Thank you very much. I debugged the protocol bannet/ip for the first time, and then I used bacnet4j to read it directly. Snipaste_2022-09-14_19-20-20

splatch commented 2 years ago

I just did a scan with simulator and it seems to work:

Device id 9999
Fetching devices for x.y.z.w address with 5 second timeout
  => Device id 1294418
     Metadata
       Address: a.b.c.d:60601
       Name: Room_FC_2014
       Model: Room_FC_2014
       Vendor: 
  => Device id 1294418
     Metadata
       Address: [c0,a8,2,d0,ec,b9]
       Name: 
       Model: 
       Vendor: 
          => Type DEVICE id: 1294418
             Metadata
               Name: RoomController.Simulator
               Units: errorClass=property, errorCode=unknown-property
               Description: Free RoomController Simulator, F. Chaxel 2015
          => Type ANALOG_INPUT id: 0
             Metadata
               Name: Temperature.Indoor
               Units: degrees-fahrenheit
               Description: Indoor Temperature
             Present value 69.8, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 1
             Metadata
               Name: Temperature.Water
               Units: degrees-fahrenheit
               Description: Glycol Water Temperature
             Present value 94.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 2
             Metadata
               Name: Temperature.Outdoor
               Units: degrees-fahrenheit
               Description: Outdoor Temperature
             Present value 53.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 0
             Metadata
               Name: SetPoint.Value
               Units: degrees-fahrenheit
               Description: Effective SetPoint
             Present value 70.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 1
             Metadata
               Name: Setpoint.1
               Units: degrees-fahrenheit
               Description: Setoint 1
             Present value 70.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 2
             Metadata
               Name: Setpoint.2
               Units: degrees-fahrenheit
               Description: Setpoint 2
             Present value 66.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 3
             Metadata
               Name: Setpoint.3
               Units: degrees-fahrenheit
               Description: Setpoint 3
             Present value 63.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type CHARACTER_STRING id: 1
             Metadata
               Name: TextSetpoint.1
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 1
             Present value Comfort, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 2
             Metadata
               Name: TextSetpoint.2
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 2
             Present value Eco+, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 3
             Metadata
               Name: TextSetpoint.3
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 3
             Present value Vacancy, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type BINARY_VALUE id: 0
             Metadata
               Name: State.Heater
               Units: errorClass=property, errorCode=unknown-property
               Description: Heater Status
             Present value active, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type BINARY_VALUE id: 1
             Metadata
               Name: State.Chiller
               Units: errorClass=property, errorCode=unknown-property
               Description: Chiller Status
             Present value inactive, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type MULTISTATE_VALUE id: 0
             Metadata
               Name: State
               Units: errorClass=property, errorCode=unknown-property
               Description: Controler State Command
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type MULTISTATE_VALUE id: 1
             Metadata
               Name: State.VentilationLevel
               Units: errorClass=property, errorCode=unknown-property
               Description: Ventilation level
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type DEVICE id: 1294418
             Metadata
               Name: RoomController.Simulator
               Units: errorClass=property, errorCode=unknown-property
               Description: Free RoomController Simulator, F. Chaxel 2015
          => Type ANALOG_INPUT id: 0
             Metadata
               Name: Temperature.Indoor
               Units: degrees-fahrenheit
               Description: Indoor Temperature
             Present value 69.8, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 1
             Metadata
               Name: Temperature.Water
               Units: degrees-fahrenheit
               Description: Glycol Water Temperature
             Present value 94.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 2
             Metadata
               Name: Temperature.Outdoor
               Units: degrees-fahrenheit
               Description: Outdoor Temperature
             Present value 53.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 0
             Metadata
               Name: SetPoint.Value
               Units: degrees-fahrenheit
               Description: Effective SetPoint
             Present value 70.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 1
             Metadata
               Name: Setpoint.1
               Units: degrees-fahrenheit
               Description: Setoint 1
             Present value 70.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 2
             Metadata
               Name: Setpoint.2
               Units: degrees-fahrenheit
               Description: Setpoint 2
             Present value 66.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 3
             Metadata
               Name: Setpoint.3
               Units: degrees-fahrenheit
               Description: Setpoint 3
             Present value 63.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type CHARACTER_STRING id: 1
             Metadata
               Name: TextSetpoint.1
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 1
             Present value Comfort, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 2
             Metadata
               Name: TextSetpoint.2
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 2
             Present value Eco+, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 3
             Metadata
               Name: TextSetpoint.3
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 3
             Present value Vacancy, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type BINARY_VALUE id: 0
             Metadata
               Name: State.Heater
               Units: errorClass=property, errorCode=unknown-property
               Description: Heater Status
             Present value active, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type BINARY_VALUE id: 1
             Metadata
               Name: State.Chiller
               Units: errorClass=property, errorCode=unknown-property
               Description: Chiller Status
             Present value inactive, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type MULTISTATE_VALUE id: 0
             Metadata
               Name: State
               Units: errorClass=property, errorCode=unknown-property
               Description: Controler State Command
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type MULTISTATE_VALUE id: 1
             Metadata
               Name: State.VentilationLevel
               Units: errorClass=property, errorCode=unknown-property
               Description: Ventilation level
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
Discovery complete

Process finished with exit code 0

The errorClass=property, errorCode=unknown-property messages are not relevant. You can see that BinaryPV with heater status is fine:

          => Type BINARY_VALUE id: 0
             Metadata
               Name: State.Heater
               Units: errorClass=property, errorCode=unknown-property
               Description: Heater Status
             Present value active, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV

From code sample you posted I see you are on most recent release, hence we shall have the same bacnet4j binary.

x-em commented 2 years ago

There may be something wrong with my simulation device, or there may be something wrong with the code I use to debug, because the code hints in the readme file are out of date. So I made some changes. Let me try again.

public static void main(String[] args) {
        //192.168.0.245 is the ip of my computer. 192.168.0.164 is the ip of device
        BacNetClient client = new BacNetIpClient("192.168.0.245", "192.168.0.164", 32891);
        client.start();
        // given number is timeout in millis
        Set<Device> devices = client.discoverDevices(10000);
        for (Device device : devices) {
            System.out.println(device);

            List<BacNetObject> deviceObjects = client.getDeviceObjects(device);
            for (BacNetObject property : deviceObjects) {
                System.out.println(property.getName() + " " + client.getPresentValue(property,new BypassBacnetConverter()));
            }
        }
        client.stop();
    }

Sample code:

BacNetClient client = new BacNetIpClient("<bind ip>", "<broadcast ip>", <client device id>);
client.start();
Set<Device> devices = client.discoverDevices(5000); // given number is timeout in millis
for (Device device : devices) {
    System.out.println(device);

    for (Property property : client.getDeviceProperties(device)) {
        System.out.println(property.getName() + " " + client.getPropertyValue(property));
    }
}

client.stop();
splatch commented 2 years ago

Your code is perfectly fine. Sample from readme is still valid, but will be fading away due to naming alignment made in 1.3 release. Out of curiosity - does the lib fail with all objects or just binarypv? Can you try to run DiscoveryMain which is part of project sources and see what it will print for you?

x-em commented 2 years ago

I debug the code and find that my debugging environment may cause errors for two reasons:

send1

send2

I think it's because of my environment.Thank you.

x-em commented 2 years ago

This is the result of running DiscoveryMain.

  => Device id 32891
     Metadata
       Address: 192.168.0.164:60322
       Name: Room_FC_2014
       Model: Room_FC_2014
       Vendor: 
Unable to fetch property description
  => Device id 32891
     Metadata
       Address: [c0,a8,0,a4,eb,a2]
       Name: 
       Model: 
       Vendor: 
Unable to fetch property description
          => Type DEVICE id: 32891
             Metadata
               Name: RoomController.Simulator
               Units: errorClass=property, errorCode=unknown-property
               Description: Free RoomController Simulator, F. Chaxel 2015
          => Type ANALOG_INPUT id: 0
             Metadata
               Name: Temperature.Indoor
               Units: degrees-celsius
               Description: Indoor Temperature
             Present value 20.7, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 1
             Metadata
               Name: Temperature.Water
               Units: degrees-celsius
               Description: Glycol Water Temperature
             Present value 35.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 2
             Metadata
               Name: Temperature.Outdoor
               Units: degrees-celsius
               Description: Outdoor Temperature
             Present value 12.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 0
             Metadata
               Name: SetPoint.Value
               Units: degrees-celsius
               Description: Effective SetPoint
             Present value 21.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 1
             Metadata
               Name: Setpoint.1
               Units: degrees-celsius
               Description: Setoint 1
             Present value 21.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 2
             Metadata
               Name: Setpoint.2
               Units: degrees-celsius
               Description: Setpoint 2
             Present value 19.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 3
             Metadata
               Name: Setpoint.3
               Units: degrees-celsius
               Description: Setpoint 3
             Present value 17.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type CHARACTER_STRING id: 1
             Metadata
               Name: TextSetpoint.1
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 1
             Present value Comfort, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 2
             Metadata
               Name: TextSetpoint.2
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 2
             Present value Eco+, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 3
             Metadata
               Name: TextSetpoint.3
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 3
             Present value Vacancy, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type BINARY_VALUE id: 1
             Metadata
               Name: State.Chiller
               Units: errorClass=property, errorCode=unknown-property
               Description: Chiller Status
             Present value inactive, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type MULTISTATE_VALUE id: 0
             Metadata
               Name: State
               Units: errorClass=property, errorCode=unknown-property
               Description: Controler State Command
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type MULTISTATE_VALUE id: 1
             Metadata
               Name: State.VentilationLevel
               Units: errorClass=property, errorCode=unknown-property
               Description: Ventilation level
             Present value 3, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type DEVICE id: 32891
             Metadata
               Name: RoomController.Simulator
               Units: errorClass=property, errorCode=unknown-property
               Description: Free RoomController Simulator, F. Chaxel 2015
          => Type ANALOG_INPUT id: 0
             Metadata
               Name: Temperature.Indoor
               Units: degrees-celsius
               Description: Indoor Temperature
             Present value 20.7, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 1
             Metadata
               Name: Temperature.Water
               Units: degrees-celsius
               Description: Glycol Water Temperature
             Present value 35.6, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_INPUT id: 2
             Metadata
               Name: Temperature.Outdoor
               Units: degrees-celsius
               Description: Outdoor Temperature
             Present value 12.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 0
             Metadata
               Name: SetPoint.Value
               Units: degrees-celsius
               Description: Effective SetPoint
             Present value 21.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 1
             Metadata
               Name: Setpoint.1
               Units: degrees-celsius
               Description: Setoint 1
             Present value 21.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 2
             Metadata
               Name: Setpoint.2
               Units: degrees-celsius
               Description: Setpoint 2
             Present value 19.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type ANALOG_VALUE id: 3
             Metadata
               Name: Setpoint.3
               Units: degrees-celsius
               Description: Setpoint 3
             Present value 17.0, type: com.serotonin.bacnet4j.type.primitive.Real
          => Type CHARACTER_STRING id: 1
             Metadata
               Name: TextSetpoint.1
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 1
             Present value Comfort, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 2
             Metadata
               Name: TextSetpoint.2
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 2
             Present value Eco+, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type CHARACTER_STRING id: 3
             Metadata
               Name: TextSetpoint.3
               Units: errorClass=property, errorCode=unknown-property
               Description: Text for Setpoint 3
             Present value Vacancy, type: com.serotonin.bacnet4j.type.primitive.CharacterString
          => Type BINARY_VALUE id: 1
             Metadata
               Name: State.Chiller
               Units: errorClass=property, errorCode=unknown-property
               Description: Chiller Status
             Present value inactive, type: com.serotonin.bacnet4j.type.enumerated.BinaryPV
          => Type MULTISTATE_VALUE id: 0
             Metadata
               Name: State
               Units: errorClass=property, errorCode=unknown-property
               Description: Controler State Command
             Present value 2, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
          => Type MULTISTATE_VALUE id: 1
             Metadata
               Name: State.VentilationLevel
               Units: errorClass=property, errorCode=unknown-property
               Description: Ventilation level
             Present value 3, type: com.serotonin.bacnet4j.type.primitive.UnsignedInteger
Discovery complete
splatch commented 2 years ago

I can just speculate about possible reason for failure, since I can't reproduce issue. I recall that bacnet4j (underlying library which handles transport) once had troubles with Japanese characters and related charset. Not sure if that's same for you since simulator, as far I know, does not have any user controllable labels.

If you still struggle you can try to capture a wireshark pcap which will include failed operation. I will compare it with the same operation on my end and see if we have any difference on the wire level. I suppose we do, but do not know what kind of trouble we deal with.

x-em commented 1 year ago

Thanks. I am following the apache plc4x project. You are also the submitter of the plc4x project. I look forward to more exchanges in the future.