use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project iot-tree by bambooww.
the class ConnPtOPCUA method browseNodesOut.
public static void browseNodesOut(Writer w, OpcUaClient client) throws Exception {
// client.getAddressSpace().
UaNode uan = client.getAddressSpace().getNode(Identifiers.RootFolder);
if (uan == null)
return;
browseNodesOut(w, "", client, uan);
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project iot-tree by bambooww.
the class ConnPtOPCUA method listBindBeSelectedItems.
private void listBindBeSelectedItems(List<BindItem> bis, OpcUaClient client, String ppath, UaNode n) throws Exception {
NodeId nid = n.getNodeId();
String bn = n.getBrowseName().getName();
if (n instanceof UaVariableNode) {
UaVariableNode uvn = (UaVariableNode) n;
DataValue dataval = uvn.getValue();
Object valob = dataval.getValue().getValue();
if (valob != null && valob.getClass().isArray()) {
Object[] objectArray = (Object[]) valob;
valob = Arrays.deepToString(objectArray);
}
String val_dt = Convert.toFullYMDHMS(dataval.getSourceTime().getJavaDate());
NodeId dt = uvn.getDataType();
UaVariableTypeNode vtn = uvn.getTypeDefinition();
UInteger[] arrdim = vtn.getArrayDimensions();
UaDataTypeNode tpnode = (UaDataTypeNode) uaClient.getAddressSpace().getNode(dt);
String datatp = tpnode.getBrowseName().getName();
String arr_dim = "";
if (arrdim != null && arrdim.length > 0) {
arr_dim = Convert.combineWith(arrdim, ',');
}
BindItem bi = new BindItem(ppath + "/" + bn, datatp);
bi.setVal(valob);
bis.add(bi);
return;
}
List<? extends UaNode> nodes = client.getAddressSpace().browseNodes(n);
if (nodes != null && nodes.size() > 0) {
if (Convert.isNullOrEmpty(ppath))
ppath = bn;
else
ppath += "/" + bn;
for (UaNode node : nodes) {
String bn0 = node.getBrowseName().getName();
if (bn0.startsWith("_"))
continue;
listBindBeSelectedItems(bis, client, ppath, node);
}
}
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.
the class AddressSpace method browseNodesAsync.
/**
* Browse from {@code nodeId} using {@code browseOptions}.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} to start the browse from.
* @param browseOptions the {@link BrowseOptions} to use.
* @return a CompletableFuture that completes successfully with a List of {@link UaNode}s
* referenced by {@code node} given the currently configured {@link BrowseOptions} or completes
* exceptionally if a service-level error occurs.
*/
public CompletableFuture<List<? extends UaNode>> browseNodesAsync(NodeId nodeId, BrowseOptions browseOptions) {
BrowseDescription browseDescription = new BrowseDescription(nodeId, browseOptions.getBrowseDirection(), browseOptions.getReferenceTypeId(), browseOptions.isIncludeSubtypes(), browseOptions.getNodeClassMask(), uint(BrowseResultMask.All.getValue()));
CompletableFuture<List<ReferenceDescription>> browse = BrowseHelper.browse(client, browseDescription, browseOptions.getMaxReferencesPerNode());
return browse.thenCompose(references -> {
List<CompletableFuture<? extends UaNode>> cfs = references.stream().map(reference -> {
NodeClass nodeClass = reference.getNodeClass();
ExpandedNodeId xNodeId = reference.getNodeId();
ExpandedNodeId xTypeDefinitionId = reference.getTypeDefinition();
switch(nodeClass) {
case Object:
case Variable:
{
CompletableFuture<CompletableFuture<? extends UaNode>> ff = toNodeIdAsync(xNodeId).thenCombine(toNodeIdAsync(xTypeDefinitionId), (targetNodeId, typeDefinitionId) -> {
if (nodeClass == NodeClass.Object) {
return getObjectNodeAsync(targetNodeId, typeDefinitionId);
} else {
return getVariableNodeAsync(targetNodeId, typeDefinitionId);
}
});
return unwrap(ff).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
default:
{
// TODO specialized getNode for other NodeClasses?
return toNodeIdAsync(xNodeId).thenCompose(this::getNodeAsync).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
}
}).collect(Collectors.toList());
return sequence(cfs);
});
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.
the class AddressSpace method getVariableNodeAsync.
/**
* Get a {@link UaVariableNode} instance for the VariableNode identified by {@code nodeId},
* assuming the type definition identified by {@code typeDefinitionId}.
* <p>
* If this type definition is registered with the {@link VariableTypeManager} a
* {@link UaVariableNode} of the appropriate subclass will be returned.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} identifying the VariableNode to get.
* @param typeDefinitionId the {@link NodeId} identifying the type definition.
* @return a CompletableFuture that completes successfully with a {@link UaVariableNode}
* instance for the VariableNode identified by {@code nodeId} or completes exceptionally if an
* error occurs while creating the VariableNode.
*/
public CompletableFuture<UaVariableNode> getVariableNodeAsync(NodeId nodeId, NodeId typeDefinitionId) {
UaNode cachedNode = nodeCache.getIfPresent(nodeId);
if (cachedNode instanceof UaVariableNode) {
return completedFuture((UaVariableNode) cachedNode);
} else {
CompletableFuture<ReadResponse> future = readAttributes(nodeId, AttributeId.VARIABLE_ATTRIBUTES);
return future.thenCompose(response -> {
List<DataValue> attributeValues = l(response.getResults());
try {
UaVariableNode node = newVariableNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
}
use of org.eclipse.milo.opcua.sdk.client.nodes.UaNode in project milo by eclipse.
the class AddressSpaceTest method modifyBrowseOptions.
@Test
public void modifyBrowseOptions() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
UaNode serverNode = addressSpace.getNode(Identifiers.Server);
{
addressSpace.modifyBrowseOptions(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Method)));
List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode);
assertFalse(nodes.isEmpty());
assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Method));
}
{
addressSpace.modifyBrowseOptions(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Object)));
List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode);
assertFalse(nodes.isEmpty());
assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Object));
}
{
addressSpace.modifyBrowseOptions(b -> b.setNodeClassMask(EnumSet.of(NodeClass.Variable)));
List<? extends UaNode> nodes = addressSpace.browseNodes(serverNode);
assertFalse(nodes.isEmpty());
assertTrue(nodes.stream().allMatch(n -> n.getNodeClass() == NodeClass.Variable));
}
}
Aggregations