I’m looking the OPC UA Device example.The example show how to add Opc Ua Node.
But I have 2 question:
1.how to update the value of Opc Ua Node, is ManagedAddressSpaceServices.write(WriteContext context,List writeValues) ?
2.I try to update the value of one Opc Ua Node like this:
node.writeAttribute(
new AttributeContext(
node.getNodeContext().getServer(),
null
),
AttributeId.Value.uid(),
new DataValue(new Variant((long) 101), StatusCode.GOOD),
null
);
But the ig show err .“UaException: status=Bad_TypeMismatch, message=The value supplied for the attribute is not of the same type as the attribute’s value.”
You can call node.setValue()
to update the value once, or install an AttributeFilter
that will act as a callback any time an attribute is being read from the Node.
The device APIs are just a thin layer on top of the Eclipse Milo OPC UA SDK. You may find it useful to look at examples that use the API here and here.
hi Kevin.
As you say,I try to install an AttributeFilter
like:
{
node.setValue(new DataValue(new Variant(100 + i)));
node.getFilterChain().addLast(
new AttributeLoggingFilter(),
AttributeFilters.getValue(
ctx ->
new DataValue(new Variant((long) new Random().nextInt()))
)
);
}
but it run err :
java.lang.NoSuchMethodError: ‘org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilterChain org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode.getFilterChain()’
in pom.xml,I have add:
org.eclipse.milo
sdk-server
0.4.0
Ah, I forgot AttributeFilterchain
is new to version 0.4. The SDK currently uses a 0.3.x version of Milo. There is something called AttributeDelegate
instead. Look at the examples from one of the 0.3 release branches: https://github.com/eclipse/milo/blob/release/0.3.8/milo-examples/server-examples/src/main/java/org/eclipse/milo/examples/server/ExampleNamespace.java
You shouldn’t add your own Milo dependency - you get one as a transitive dependency from the module SDK.
I done it. Thanks for your support.