Search in sources :

Example 1 with UaObjectNode

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

the class MethodExample2 method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // synchronous connect
    client.connect().get();
    UaObjectNode objectNode = client.getAddressSpace().getObjectNode(NodeId.parse("ns=2;s=HelloWorld"));
    UaMethod sqrtMethod = objectNode.getMethod("sqrt(x)");
    logArguments(client, sqrtMethod);
    Variant[] inputs = { new Variant(16.0) };
    Variant[] outputs = sqrtMethod.call(inputs);
    logger.info("Input values: " + Arrays.toString(inputs));
    logger.info("Output values: " + Arrays.toString(outputs));
    future.complete(client);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) UaMethod(org.eclipse.milo.opcua.sdk.client.methods.UaMethod)

Example 2 with UaObjectNode

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

the class UaMethodTest method callMethodWithNoInputsOrOutputs.

@Test
public void callMethodWithNoInputsOrOutputs() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    Variant[] outputs = objectsNode.callMethod(new QualifiedName(2, "hasNoInputsOrOutputs()"), new Variant[0]);
    assertEquals(0, outputs.length);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 3 with UaObjectNode

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

the class UaMethodTest method findMethodNotFound.

@Test
public void findMethodNotFound() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode serverNode = addressSpace.getObjectNode(Identifiers.Server);
    assertThrows(UaException.class, () -> serverNode.getMethod("foo"));
}
Also used : AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 4 with UaObjectNode

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

the class UaMethodTest method throwsUaMethodException.

@Test
public void throwsUaMethodException() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    assertThrows(UaMethodException.class, () -> {
        try {
            objectsNode.callMethod(new QualifiedName(2, "onlyAcceptsPositiveInputs()"), new Variant[] { new Variant(-1) });
        } catch (UaMethodException e) {
            System.out.println("result: " + e.getStatusCode());
            System.out.println("inputArgumentResults: " + Arrays.toString(e.getInputArgumentResults()));
            throw e;
        }
    });
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 5 with UaObjectNode

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

the class UaMethodTest method callMethodWithHasComponentReference.

@Test
public void callMethodWithHasComponentReference() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    UaObjectNode objectsNode = addressSpace.getObjectNode(Identifiers.ObjectsFolder);
    Variant[] outputs = objectsNode.callMethod(new QualifiedName(2, "sqrt(x)"), new Variant[] { new Variant(16.0) });
    assertEquals(4.0, outputs[0].getValue());
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Aggregations

UaObjectNode (org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode)16 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)12 Test (org.junit.jupiter.api.Test)12 AddressSpace (org.eclipse.milo.opcua.sdk.client.AddressSpace)9 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)9 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)6 UaException (org.eclipse.milo.opcua.stack.core.UaException)3 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)3 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)3 ManagedDataItem (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem)2 ManagedSubscription (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription)2 ReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse)2 ArrayList (java.util.ArrayList)1 ObjectNodeConstructor (org.eclipse.milo.opcua.sdk.client.ObjectTypeManager.ObjectNodeConstructor)1 UaMethod (org.eclipse.milo.opcua.sdk.client.methods.UaMethod)1 UaMethodException (org.eclipse.milo.opcua.sdk.client.methods.UaMethodException)1 UaNode (org.eclipse.milo.opcua.sdk.client.nodes.UaNode)1 UaObjectTypeNode (org.eclipse.milo.opcua.sdk.client.nodes.UaObjectTypeNode)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)1