Created
December 17, 2023 14:40
-
-
Save kevinherron/f85ce3b0eebe84008e59a5192f6b404d to your computer and use it in GitHub Desktop.
Browse for HasTypeDefinition References
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; | |
import org.eclipse.milo.opcua.stack.core.NodeIds; | |
import org.eclipse.milo.opcua.stack.core.UaException; | |
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; | |
import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection; | |
import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask; | |
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass; | |
import org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription; | |
import org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult; | |
import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription; | |
import static java.util.Objects.requireNonNull; | |
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint; | |
class Scratch { | |
public static void main(String[] args) throws UaException { | |
var client = OpcUaClient.create("opc.tcp://localhost:4840"); | |
client.connect(); | |
browseWithNodeClassMask(client, uint(NodeClass.ObjectType.getValue() | NodeClass.VariableType.getValue())); | |
browseWithNodeClassMask(client, uint(0)); | |
} | |
private static void browseWithNodeClassMask(OpcUaClient client, UInteger mask) throws UaException { | |
System.out.println("Browsing with NodeClass mask: " + mask); | |
BrowseResult result = client.browse(new BrowseDescription( | |
NodeIds.Server_ServerStatus, | |
BrowseDirection.Forward, | |
NodeIds.HasTypeDefinition, | |
false, | |
mask, | |
uint(BrowseResultMask.All.getValue()) | |
)); | |
ReferenceDescription[] references = requireNonNull(result.getReferences()); | |
if (references.length > 0) { | |
for (int i = 0; i < references.length; i++) { | |
System.out.printf(" Reference[%d]:%n", i); | |
System.out.println(" NodeId: " + references[i].getNodeId()); | |
System.out.println(" BrowseName: " + references[i].getBrowseName()); | |
System.out.println(" DisplayName: " + references[i].getDisplayName()); | |
System.out.println(" NodeClass: " + references[i].getNodeClass()); | |
System.out.println(" TypeDefinition: " + references[i].getTypeDefinition()); | |
} | |
} else { | |
System.out.println(" No references found"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment