1
1
/*
2
- * Copyright (c) 2024 the Eclipse Milo Authors
2
+ * Copyright (c) 2025 the Eclipse Milo Authors
3
3
*
4
4
* This program and the accompanying materials are made
5
5
* available under the terms of the Eclipse Public License 2.0
18
18
import java .util .UUID ;
19
19
import java .util .concurrent .CompletableFuture ;
20
20
import org .eclipse .milo .opcua .sdk .client .OpcUaClient ;
21
- import org .eclipse .milo .opcua .sdk .core .types .DynamicEnum ;
22
- import org .eclipse .milo .opcua .sdk .core .types .DynamicOptionSet ;
23
- import org .eclipse .milo .opcua .sdk .core .types .DynamicStruct ;
21
+ import org .eclipse .milo .opcua .sdk .core .types .DynamicEnumType ;
22
+ import org .eclipse .milo .opcua .sdk .core .types .DynamicOptionSetType ;
23
+ import org .eclipse .milo .opcua .sdk .core .types .DynamicStructType ;
24
+ import org .eclipse .milo .opcua .sdk .core .types .DynamicType ;
24
25
import org .eclipse .milo .opcua .stack .core .encoding .EncodingContext ;
25
26
import org .eclipse .milo .opcua .stack .core .security .SecurityPolicy ;
26
27
import org .eclipse .milo .opcua .stack .core .types .builtin .ByteString ;
@@ -64,40 +65,40 @@ public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throw
64
65
private void readWriteReadPerson (OpcUaClient client ) throws Exception {
65
66
NodeId nodeId = NodeId .parse ("ns=3;s=Person1" );
66
67
67
- DynamicStruct value = readScalarValue (client , nodeId );
68
+ DynamicStructType value = ( DynamicStructType ) readScalarValue (client , nodeId );
68
69
logger .info ("Person1: {}" , value );
69
70
70
71
Random r = new Random ();
71
- DynamicEnum gender = (DynamicEnum ) value .getMembers ().get ("Gender" );
72
+ DynamicEnumType gender = (DynamicEnumType ) value .getMembers ().get ("Gender" );
72
73
value .getMembers ().put ("Name" , "Fat Boy" + r .nextInt (100 ));
73
- value .getMembers ().put ("Gender" , new DynamicEnum (gender .getDataType (), r .nextInt (2 )));
74
+ value .getMembers ().put ("Gender" , new DynamicEnumType (gender .getDataType (), r .nextInt (2 )));
74
75
75
76
StatusCode status = writeValue (client , nodeId , value );
76
77
System .out .println ("write status: " + status );
77
78
78
- value = readScalarValue (client , nodeId );
79
+ value = ( DynamicStructType ) readScalarValue (client , nodeId );
79
80
logger .info ("Person1': {}" , value );
80
81
}
81
82
82
83
private void readWriteReadWorkOrder (OpcUaClient client ) throws Exception {
83
84
NodeId nodeId = NodeId .parse ("ns=3;s=Demo.Static.Scalar.WorkOrder" );
84
85
85
- DynamicStruct value = readScalarValue (client , nodeId );
86
+ DynamicStructType value = ( DynamicStructType ) readScalarValue (client , nodeId );
86
87
logger .info ("WorkOrder: {}" , value );
87
88
88
89
value .getMembers ().put ("ID" , UUID .randomUUID ());
89
90
90
91
StatusCode status = writeValue (client , nodeId , value );
91
92
System .out .println ("write status: " + status );
92
93
93
- value = readScalarValue (client , nodeId );
94
+ value = ( DynamicStructType ) readScalarValue (client , nodeId );
94
95
logger .info ("WorkOrder': {}" , value );
95
96
}
96
97
97
98
private void readWriteCarExtras (OpcUaClient client ) throws Exception {
98
99
NodeId nodeId = NodeId .parse ("ns=3;s=Demo.Static.Scalar.CarExtras" );
99
100
100
- DynamicOptionSet value = (DynamicOptionSet ) readScalarValue (client , nodeId );
101
+ DynamicOptionSetType value = (DynamicOptionSetType ) readScalarValue (client , nodeId );
101
102
logger .info ("CarExtras: {}" , value );
102
103
103
104
byte b = requireNonNull (value .getValue ().bytes ())[0 ];
@@ -106,33 +107,32 @@ private void readWriteCarExtras(OpcUaClient client) throws Exception {
106
107
StatusCode status = writeValue (client , nodeId , value );
107
108
System .out .println ("write status: " + status );
108
109
109
- value = (DynamicOptionSet ) readScalarValue (client , nodeId );
110
+ value = (DynamicOptionSetType ) readScalarValue (client , nodeId );
110
111
logger .info ("CarExtras': {}" , value );
111
112
}
112
113
113
114
private void readWorkOrderArray (OpcUaClient client ) throws Exception {
114
115
NodeId nodeId = NodeId .parse ("ns=3;s=Demo.Static.Arrays.WorkOrder" );
115
116
116
- DynamicStruct [] value = readArrayValue (client , nodeId );
117
+ DynamicType [] value = readArrayValue (client , nodeId );
117
118
118
119
logger .info ("WorkOrderArray:" );
119
120
for (int i = 0 ; i < value .length ; i ++) {
120
121
logger .info (" WorkOrder[{}]: {}" , i , value [i ]);
121
122
}
122
123
}
123
124
124
- private static DynamicStruct readScalarValue (OpcUaClient client , NodeId nodeId ) throws Exception {
125
+ private static DynamicType readScalarValue (OpcUaClient client , NodeId nodeId ) throws Exception {
125
126
DataValue dataValue =
126
127
client .readValues (0.0 , TimestampsToReturn .Neither , List .of (nodeId )).get (0 );
127
128
128
129
ExtensionObject xo = (ExtensionObject ) dataValue .getValue ().getValue ();
129
130
assert xo != null ;
130
131
131
- return (DynamicStruct ) xo .decode (client .getDynamicEncodingContext ());
132
+ return (DynamicType ) xo .decode (client .getDynamicEncodingContext ());
132
133
}
133
134
134
- private static DynamicStruct [] readArrayValue (OpcUaClient client , NodeId nodeId )
135
- throws Exception {
135
+ private static DynamicType [] readArrayValue (OpcUaClient client , NodeId nodeId ) throws Exception {
136
136
DataValue dataValue =
137
137
client .readValues (0.0 , TimestampsToReturn .Neither , List .of (nodeId )).get (0 );
138
138
@@ -141,13 +141,12 @@ private static DynamicStruct[] readArrayValue(OpcUaClient client, NodeId nodeId)
141
141
142
142
EncodingContext ctx = client .getDynamicEncodingContext ();
143
143
144
- return Arrays .stream (xos )
145
- .map (xo -> (DynamicStruct ) xo .decode (ctx ))
146
- .toArray (DynamicStruct []::new );
144
+ return Arrays .stream (xos ).map (xo -> (DynamicType ) xo .decode (ctx )).toArray (DynamicType []::new );
147
145
}
148
146
149
- private static StatusCode writeValue (OpcUaClient client , NodeId nodeId , DynamicStruct value )
147
+ private static StatusCode writeValue (OpcUaClient client , NodeId nodeId , DynamicType value )
150
148
throws Exception {
149
+
151
150
ExtensionObject xo =
152
151
ExtensionObject .encodeDefaultBinary (
153
152
client .getDynamicEncodingContext (), value , value .getDataType ().getBinaryEncodingId ());
@@ -160,7 +159,7 @@ private static StatusCode writeValue(OpcUaClient client, NodeId nodeId, DynamicS
160
159
@ Override
161
160
public String getEndpointUrl () {
162
161
// Change this if UaCPPServer is running somewhere other than localhost.
163
- return "opc.tcp://localhost :48010" ;
162
+ return "opc.tcp://192.168.1.66 :48010" ;
164
163
}
165
164
166
165
@ Override
0 commit comments