Search in sources :

Example 11 with UaNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.

the class AddressSpaceTest method getNode.

@Test
public void getNode() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaNode serverNode = addressSpace.getNode(Identifiers.Server);
    assertNotNull(serverNode);
    assertTrue(serverNode instanceof ServerTypeNode);
    UaNode serverStatusNode = addressSpace.getNode(Identifiers.Server_ServerStatus);
    assertNotNull(serverStatusNode);
    assertTrue(serverStatusNode instanceof ServerStatusTypeNode);
}
Also used : ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.ServerStatusTypeNode) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 12 with UaNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.

the class AddressSpaceTest method browseWithReferenceType.

@Test
public void browseWithReferenceType() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaNode serverNode = addressSpace.getNode(Identifiers.Server);
    BrowseOptions browseOptions = addressSpace.getBrowseOptions().copy(b -> b.setReferenceType(BuiltinReferenceType.HasProperty));
    List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode, browseOptions);
    assertEquals(5, nodes.size());
    assertTrue(nodes.stream().anyMatch(n -> n.getNodeId().equals(Identifiers.Server_ServerArray)));
    assertTrue(nodes.stream().anyMatch(n -> n.getNodeId().equals(Identifiers.Server_NamespaceArray)));
    assertTrue(nodes.stream().anyMatch(n -> n.getNodeId().equals(Identifiers.Server_ServiceLevel)));
    assertTrue(nodes.stream().anyMatch(n -> n.getNodeId().equals(Identifiers.Server_Auditing)));
    assertTrue(nodes.stream().anyMatch(n -> n.getNodeId().equals(Identifiers.Server_EstimatedReturnTime)));
}
Also used : BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BuiltinReferenceType(org.eclipse.milo.opcua.stack.core.BuiltinReferenceType) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) List(java.util.List) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest) UaException(org.eclipse.milo.opcua.stack.core.UaException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.ServerStatusTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 13 with UaNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.

the class AddressSpaceTest method browseWithNodeClassMask.

@Test
public void browseWithNodeClassMask() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaNode serverNode = addressSpace.getNode(Identifiers.Server);
    {
        BrowseOptions browseOptions = addressSpace.getBrowseOptions().copy(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Method)));
        List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode, browseOptions);
        assertFalse(nodes.isEmpty());
        assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Method));
    }
    {
        BrowseOptions browseOptions = addressSpace.getBrowseOptions().copy(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Object)));
        List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode, browseOptions);
        assertFalse(nodes.isEmpty());
        assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Object));
    }
    {
        BrowseOptions browseOptions = addressSpace.getBrowseOptions().copy(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Variable)));
        List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode, browseOptions);
        assertFalse(nodes.isEmpty());
        assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Variable));
    }
}
Also used : BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) BuiltinReferenceType(org.eclipse.milo.opcua.stack.core.BuiltinReferenceType) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) List(java.util.List) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest) UaException(org.eclipse.milo.opcua.stack.core.UaException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.ServerStatusTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode) List(java.util.List) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 14 with UaNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.

the class BrowseAsyncExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // synchronous connect
    client.connect().get();
    // start browsing at root folder
    UaNode rootNode = client.getAddressSpace().getNode(Identifiers.RootFolder);
    Tree<UaNode> tree = new Tree<>(rootNode);
    long startTime = System.nanoTime();
    browseRecursive(client, tree).get();
    long endTime = System.nanoTime();
    traverse(tree, 0, (depth, n) -> logger.info(indent(depth) + n.getBrowseName().getName()));
    logger.info("Browse took {}ms", TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS));
    future.complete(client);
}
Also used : UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode)

Example 15 with UaNode

use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.

the class BrowseNodeExample method browseNode.

private void browseNode(String indent, OpcUaClient client, NodeId browseRoot) {
    try {
        List<? extends UaNode> nodes = client.getAddressSpace().browseNodes(browseRoot);
        for (UaNode node : nodes) {
            logger.info("{} Node={}", indent, node.getBrowseName().getName());
            // recursively browse to children
            browseNode(indent + "  ", client, node.getNodeId());
        }
    } catch (UaException e) {
        logger.error("Browsing nodeId={} failed: {}", browseRoot, e.getMessage(), e);
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode)

Aggregations

UaNode (org.eclipse.milo.opcua.sdk.client.nodes.UaNode)30 UaException (org.eclipse.milo.opcua.stack.core.UaException)17 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)17 UaVariableNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode)12 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)9 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)8 Test (org.junit.jupiter.api.Test)8 List (java.util.List)7 ExecutionException (java.util.concurrent.ExecutionException)7 ServerTypeNode (org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode)6 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)6 EnumSet (java.util.EnumSet)5 BrowseOptions (org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions)5 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)5 BrowseDirection (org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)5 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 IOException (java.io.IOException)4