Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinherron/9ed71c8106e741087933b9e96074f3c0 to your computer and use it in GitHub Desktop.
Save kevinherron/9ed71c8106e741087933b9e96074f3c0 to your computer and use it in GitHub Desktop.
LegacyDataTypeDictionaryExample.java
package org.eclipse.milo.examples.client;
import java.util.concurrent.CompletableFuture;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.dtd.LegacyDataTypeManagerInitializer;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
public class LegacyDataTypeDictionaryExample implements ClientExample {
public static void main(String[] args) throws Exception {
var example = new LegacyDataTypeDictionaryExample();
new ClientExampleRunner(example, false).run();
}
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
client.setDataTypeManagerInitializer(new LegacyDataTypeManagerInitializer(client));
client.connect();
DataValue dataValue =
client.readValue(
0.0, TimestampsToReturn.Both, NodeId.parse("ns=3;s=Demo.WorkOrder.WorkOrderVariable"));
if (dataValue.getValue().getValue() instanceof ExtensionObject xo) {
Object decoded = xo.decode(client.getDynamicEncodingContext());
System.out.println("Read WorkOrderVariable: " + decoded);
}
future.complete(client);
}
@Override
public String getEndpointUrl() {
return "opc.tcp://10.211.55.3:48010";
}
@Override
public SecurityPolicy getSecurityPolicy() {
return SecurityPolicy.None;
}
}
@kevinherron
Copy link
Author

Output:

Read WorkOrderVariable: BsdStructWrapper[dataType=org.eclipse.milo.opcua.sdk.core.dtd.BsdDataType@27eedb64, object=Struct{name=WorkOrderType, members={ID=Member{name=ID, value=3b9e7785-0de3-4c59-92db-695a3dd38068}, StartTime=Member{name=StartTime, value=DateTime{date=Wed Jun 25 08:21:33 PDT 2025, instant=2025-06-25T15:21:33.072941200Z}}, StatusComments=Member{name=StatusComments, value=[BsdStructWrapper[dataType=org.eclipse.milo.opcua.sdk.core.dtd.BsdDataType@13330ac6, object=Struct{name=WorkOrderStatusType, members={Actor=Member{name=Actor, value=Wendy Terry}, Timestamp=Member{name=Timestamp, value=DateTime{date=Wed Jun 25 08:21:33 PDT 2025, instant=2025-06-25T15:21:33.071940300Z}}, Comment=Member{name=Comment, value=LocalizedText[locale=en-US, text=Mission accomplished!]}}}], BsdStructWrapper[dataType=org.eclipse.milo.opcua.sdk.core.dtd.BsdDataType@539d019, object=Struct{name=WorkOrderStatusType, members={Actor=Member{name=Actor, value=Gavin Mackenzie}, Timestamp=Member{name=Timestamp, value=DateTime{date=Wed Jun 25 08:21:33 PDT 2025, instant=2025-06-25T15:21:33.071940300Z}}, Comment=Member{name=Comment, value=LocalizedText[locale=en-US, text=I think clients would love this.]}}}], BsdStructWrapper[dataType=org.eclipse.milo.opcua.sdk.core.dtd.BsdDataType@39a2bb97, object=Struct{name=WorkOrderStatusType, members={Actor=Member{name=Actor, value=Phil Taylor}, Timestamp=Member{name=Timestamp, value=DateTime{date=Wed Jun 25 08:21:33 PDT 2025, instant=2025-06-25T15:21:33.072941200Z}}, Comment=Member{name=Comment, value=LocalizedText[locale=en-US, text=And justice for all.]}}}]]}, AssetID=Member{name=AssetID, value=123-X-Y-Z}}}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment