kevinherron / ua-client-sdk

OPC-UA Client SDK for Java
27 stars 16 forks source link

Double ReferenceDescription on browse hierarchy #6

Closed comtel2000 closed 8 years ago

comtel2000 commented 8 years ago

With the browse method:

    UInteger nodeClassMask = UInteger.valueOf(NodeClass.Object.getValue() | NodeClass.Variable.getValue());
    UInteger resultMask = UInteger.valueOf(BrowseResultMask.All.getValue());
    BrowseDescription bd = new BrowseDescription(node, BrowseDirection.Forward, null, false, nodeClassMask, resultMask);

i got double entries for some Nodes.

Tested with server: opc.tcp://opcua.demo-this.com:51210/UA/SampleServer

Nodes: Objects/Server/Data or Objects/Server/Boilers

image

kevinherron commented 8 years ago

I connected to the server and verified with Wireshark that the server is sending the boiler reference twice. This doesn't appear to be an issue with the client.

comtel2000 commented 8 years ago

I don't see the nodes with other clients. I will wireshark and compare the requests. Maybe there is another BrowserDescription used.. Sorry, I couldn't find a good manual howto browse the tree.

comtel2000 commented 8 years ago

I guess the ReferenceTypeId in the BrowseDescription must be there. Without the result is:

22:45:20.425 [ua-shared-pool-1] ERROR c.d.o.s.e.client.BrowseExample - found 2 duplicate node(s)
22:45:20.425 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=Static, namespaceIndex=2} - NodeId{ns=0, id=47}
22:45:20.427 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=Dynamic, namespaceIndex=2} - NodeId{ns=0, id=47}
22:45:20.427 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=Conditions, namespaceIndex=2} - NodeId{ns=0, id=47}
22:45:20.427 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=Static, namespaceIndex=2} - NodeId{ns=0, id=48}
22:45:20.427 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=Dynamic, namespaceIndex=2} - NodeId{ns=0, id=48}
22:45:20.427 [ua-shared-pool-1] INFO  c.d.o.s.e.client.BrowseExample - node QualifiedName{name=FolderType, namespaceIndex=0} - NodeId{ns=0, id=40}
public class BrowseExample implements ClientExample {

    public static void main(String[] args) throws Exception {
        String endpointUrl = "opc.tcp://opcua.demo-this.com:51210";

        BrowseExample example = new BrowseExample();

        new ClientExampleRunner(endpointUrl, example).run();
    }

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
        // synchronous connect
        client.connect().get();

    UInteger nodeClassMask = UInteger.valueOf(NodeClass.Unspecified.getValue());
    UInteger resultMask = UInteger.valueOf(BrowseResultMask.All.getValue());
    BrowseDescription bd = new BrowseDescription(NodeId.parse("ns=2;i=10157"), BrowseDirection.Forward, null, true, nodeClassMask, resultMask);

        client.browse(bd).whenComplete((r, t) -> {
            //r.getReferences()[0].getReferenceTypeId()
            long distincts = Arrays.stream(r.getReferences()).map(ReferenceDescription::getNodeId).distinct().count();
            if (r.getReferences().length > distincts){
            logger.error("found {} duplicate node(s)", r.getReferences().length - distincts);
            }
            Arrays.stream(r.getReferences()).forEach(d -> logger.info("node {} - {}", d.getBrowseName(), d.getReferenceTypeId()));

        }).get();

        future.complete(client);
    }

}
kevinherron commented 8 years ago

Yes, try Identifiers.HierarchicalReferences ?

comtel2000 commented 8 years ago

No change, still dulicates. I used it before but with the latest SNAPSHOT update the response for the RootFolder is missing.

kevinherron commented 8 years ago

So it returns the same results when you browse with UaExpert, but UaExpert knows how to correctly interpret the results.

This server is returning two references to Boiler #1 - a HasComponent reference and a HasNotifier reference. Your browse tree probably shouldn't be showing a HasEventsource or HasNotifier reference the same as the other HierarchicalReference types.

comtel2000 commented 8 years ago

Thanks a lot for the explanation!