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);
}
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)));
}
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));
}
}
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);
}
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);
}
}
Aggregations