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