Created
June 25, 2025 15:26
-
-
Save kevinherron/9ed71c8106e741087933b9e96074f3c0 to your computer and use it in GitHub Desktop.
LegacyDataTypeDictionaryExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: