Subscribe COV problems
-
My Program subscribes for a analogue value, after this it waits 5 seconds(I receive the COVs in this 5 Seconds), after that I want to unsubscribe, but here I get the error "b ErrorAPDU(choice=5, errorClass=Object, errorCode=covSubscriptionFailed)" also If I try to subscribe for another value, I get this error.
What do I do wrong? I use the bacnet4j-3.2.4-APIpublic class Test1 { static LocalDevice localDevice; public static void main(String[] args) throws Exception { IpNetwork network = new IpNetworkBuilder().build(); Transport transport = new DefaultTransport(network); localDevice = new LocalDevice(44444, transport); try { localDevice.initialize(); localDevice.getEventHandler().addListener(new Listener()); localDevice.sendGlobalBroadcast(new WhoIsRequest()); Thread.sleep(2 * 1000); RemoteDevice device = localDevice.getRemoteDevice(2222); UnsignedInteger subscriberProcessIdentifier = new UnsignedInteger(0); UnsignedInteger lifetime = new UnsignedInteger(0); ObjectIdentifier oi = new ObjectIdentifier(ObjectType.analogValue, 0); SubscribeCOVRequest request = new SubscribeCOVRequest( subscriberProcessIdentifier, oi, new Boolean(true), lifetime); localDevice.send(device, request, new ResponseConsumer() { @Override public void success(AcknowledgementService arg0) { System.out.println("a " + arg0); } @Override public void fail(AckAPDU arg0) { System.out.println("b " + arg0); } @Override public void ex(BACnetException arg0) { System.out.println("c " + arg0); } }); Thread.sleep(5000); SubscribeCOVRequest request1 = new SubscribeCOVRequest( subscriberProcessIdentifier, oi, null, null); localDevice.send(device, request1, new ResponseConsumer() { @Override public void success(AcknowledgementService arg0) { System.out.println("a " + arg0); } @Override public void fail(AckAPDU arg0) { System.out.println("b " + arg0); } @Override public void ex(BACnetException arg0) { System.out.println("c " + arg0); } }); try { new BufferedReader(new InputStreamReader(System.in)).readLine(); } catch (IOException e) { e.printStackTrace(); } localDevice.terminate(); } catch (Exception ex) { ex.printStackTrace(); } } static class Listener extends DeviceEventAdapter { @Override public void covNotificationReceived( UnsignedInteger subscriberProcessIdentifier, RemoteDevice initiatingDevice, ObjectIdentifier monitoredObjectIdentifier, UnsignedInteger timeRemaining, SequenceOf<PropertyValue> listOfValues) { for (int i = 0; i < listOfValues.getCount(); i++) { if (!(listOfValues.getValues().get(i).getValue() instanceof StatusFlags)) { System.out.println("COV_Result: Instance-ID:" + monitoredObjectIdentifier.getInstanceNumber() + " Value:" + listOfValues.getValues().get(i).getValue() + " Type: " + monitoredObjectIdentifier.getObjectType() .intValue()); } } } @Override public void iAmReceived(RemoteDevice d) { System.out.println("IAm received from " + d); System.out.println("Segmentation: " + d.getSegmentationSupported()); d.setSegmentationSupported(Segmentation.noSegmentation); } } }
the output of my program is;
IAm received from RemoteDevice(instanceNumber=2222, address=Address [networkNumber=20, macAddress=[ae,8,0,0,0,0]])
Segmentation: both
a null
COV_Result: Instance-ID:0 Value:2784.5 Type: 2
COV_Result: Instance-ID:0 Value:2785.0 Type: 2
COV_Result: Instance-ID:0 Value:2785.5 Type: 2
COV_Result: Instance-ID:0 Value:2786.0 Type: 2
b ErrorAPDU(choice=5, errorClass=Object, errorCode=covSubscriptionFailed)
COV_Result: Instance-ID:0 Value:2786.5 Type: 2
COV_Result: Instance-ID:0 Value:2787.0 Type: 2EDIT: The "Problem" is that my removeDevice will be overwritten as soon as I receive the first COV. I did a workarround like that:
private RemoteDevice getRemoteDevice() { return localDevice.getRemoteDeviceCreate(2222, new Address( 19, new OctetString(new byte[] { -82, 8, 0, 0, 0, 0 }))); }
this is executed any time when I send something to the bacnet server. How can I do that propperly?