Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad_NodeIdUnknown #37

Closed
ghost opened this issue Aug 22, 2016 · 3 comments
Closed

Bad_NodeIdUnknown #37

ghost opened this issue Aug 22, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 22, 2016

Hello.
I'm trying to create a java opcua server based on your library. Since there is not much documentation I use the example from your previous project and try to add a SqrtMethod() to HelloWorld of Milo, so here is a modified addNodes() method of the HelloWorldNamespace.java

    private void addNodes(UaFolderNode folderNode) {
        for (Object[] os : STATIC_SCALAR_NODES) {
            String name = (String) os[0];
            NodeId typeId = (NodeId) os[1];
            Variant variant = (Variant) os[2];

        UaMethodNode methodNode = UaMethodNode.builder(server.getNodeManager())
        .setNodeId(new NodeId(namespaceIndex, "/Methods/sqrt(x)"))
        .setBrowseName(new QualifiedName(namespaceIndex, "sqrt(x)"))
        .setDisplayName(new LocalizedText(null, "sqrt(x)"))
        .setDescription(LocalizedText.english("Returns the correctly rounded positive square root of a double value."))
        .build();

        try {
            AnnotationBasedInvocationHandler invocationHandler=AnnotationBasedInvocationHandler.fromAnnotatedObject(server.getNodeManager(),new SqrtMethod());
            methodNode.setProperty(UaMethodNode.InputArguments,invocationHandler.getInputArguments());
            methodNode.setProperty(UaMethodNode.OutputArguments,invocationHandler.getOutputArguments());
            methodNode.setInvocationHandler(invocationHandler);            
            UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(server.getNodeManager())
                .setNodeId(new NodeId(namespaceIndex, "Methods/" + name))
                .setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
                .setBrowseName(new QualifiedName(namespaceIndex, name))
                .setDisplayName(LocalizedText.english(name))
                .setDataType(typeId)
                .setTypeDefinition(Identifiers.BaseDataVariableType)
                .build();

            node.setValue(new DataValue(variant));

            server.getNodeManager().addNode(node);
            server.getNodeManager().addNode(methodNode);
            folderNode.addOrganizes(node);
            folderNode.addOrganizes(methodNode);

            folderNode.addReference(new Reference(folderNode.getNodeId(),Identifiers.HasComponent,methodNode.getNodeId().expanded(),methodNode.getNodeClass(),true));
            } catch (Exception e) {
                logger.error("Error creating sqrt() method.",e);
            }
        }
    }

The class for SqrtMethod is:

public class SqrtMethod {

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

    @UaMethod
    public void invoke(
            InvocationContext context,

            @UaInputArgument(
                    name = "x",
                    description = "A value.")
            Double x,

            @UaOutputArgument(
                    name = "x_sqrt",
                    description = "The positive square root of x. If the argument is NaN or less than zero, the result is NaN.")
            Out<Double> xSqrt) {

        System.out.println("sqrt(" + x.toString() + ")");
        logger.debug(String.format("Invoking sqrt() method of Object '%s'", context.getObjectNode().getBrowseName().getName()));

        xSqrt.set(Math.sqrt(x));
    }

}

To connect to the server I use Prosys OPC UA Java Client and when I try to call the appropriate method with this client I get:
Failed to call:Bad_NodeIdUnknown (0x80340000) "The node id refers to a node that does not exist in the server address space."

Since variables work correctly and I never had any issues with Prosys I assume something is wrong with your software. Can you please help to solve it? Thanks.

@kevinherron
Copy link
Contributor

kevinherron commented Aug 22, 2016

ExampleNamespace on the more-examples branch has an example implementation of the sqrt method now: https://github.com/eclipse/milo/blob/more-examples/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/server/ExampleNamespace.java

The part you may have missed is overriding getInvocationHandler, which you can see at the bottom of the example namespace.

There is also a fully runnable example here: https://github.com/eclipse/milo/blob/more-examples/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/MethodExample.java

@ghost
Copy link
Author

ghost commented Aug 22, 2016

Thanks. Was not obvious for me and I missed more examples you've provided.

@ghost ghost closed this as completed Aug 22, 2016
@kevinherron
Copy link
Contributor

The more-examples branch is in progress. Once I finish up a few more things I'll merge it back into master and it won't be so hidden away.

@ghost ghost reopened this Sep 1, 2016
@ghost ghost closed this as completed Sep 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant