|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 the Eclipse Milo Authors |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made |
| 5 | + * available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + */ |
| 10 | + |
1 | 11 | package org.eclipse.milo.examples.client; |
2 | 12 |
|
3 | 13 | import java.util.concurrent.CompletableFuture; |
4 | | - |
5 | 14 | import org.eclipse.milo.opcua.sdk.client.OpcUaClient; |
6 | 15 | import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy; |
7 | 16 | import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; |
|
15 | 24 |
|
16 | 25 | public class IJTReadCustomDataTypeExample implements ClientExample { |
17 | 26 |
|
18 | | - public static void main(String[] args) throws Exception { |
19 | | - var example = new IJTReadCustomDataTypeExample(); |
20 | | - |
21 | | - new ClientExampleRunner(example, false).run(); |
22 | | - } |
| 27 | + public static void main(String[] args) throws Exception { |
| 28 | + var example = new IJTReadCustomDataTypeExample(); |
23 | 29 |
|
24 | | - private final Logger logger = LoggerFactory.getLogger(getClass()); |
| 30 | + new ClientExampleRunner(example, false).run(); |
| 31 | + } |
25 | 32 |
|
26 | | - @Override |
27 | | - public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception { |
28 | | - client.setDataTypeManagerInitializer(new OpcUaClient.DefaultDataTypeManagerInitializer(JsonCodecFactory::create)); |
| 33 | + private final Logger logger = LoggerFactory.getLogger(getClass()); |
29 | 34 |
|
30 | | - client.connect(); |
| 35 | + @Override |
| 36 | + public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception { |
| 37 | + client.setDataTypeManagerInitializer( |
| 38 | + new OpcUaClient.DefaultDataTypeManagerInitializer(JsonCodecFactory::create)); |
31 | 39 |
|
32 | | - NodeId nodeId = NodeId.parse("ns=1;s=TighteningSystem/ResultManagement/Results/Result"); |
33 | | - DataValue value = client.readValue(0, TimestampsToReturn.Both, nodeId); |
| 40 | + client.connect(); |
34 | 41 |
|
35 | | - if (value.getValue().getValue() instanceof ExtensionObject xo) { |
36 | | - JsonStruct struct = (JsonStruct) xo.decode(client.getDynamicEncodingContext()); |
| 42 | + NodeId nodeId = NodeId.parse("ns=1;s=TighteningSystem/ResultManagement/Results/Result"); |
| 43 | + DataValue value = client.readValue(0, TimestampsToReturn.Both, nodeId); |
37 | 44 |
|
38 | | - System.out.println(struct); |
39 | | - } |
| 45 | + if (value.getValue().getValue() instanceof ExtensionObject xo) { |
| 46 | + JsonStruct struct = (JsonStruct) xo.decode(client.getDynamicEncodingContext()); |
40 | 47 |
|
41 | | - future.complete(client); |
| 48 | + System.out.println(struct); |
42 | 49 | } |
43 | 50 |
|
44 | | - @Override |
45 | | - public String getEndpointUrl() { |
46 | | - return "opc.tcp://10.211.55.3:40451"; |
47 | | - } |
| 51 | + future.complete(client); |
| 52 | + } |
48 | 53 |
|
49 | | - @Override |
50 | | - public SecurityPolicy getSecurityPolicy() { |
51 | | - return SecurityPolicy.None; |
52 | | - } |
| 54 | + @Override |
| 55 | + public String getEndpointUrl() { |
| 56 | + return "opc.tcp://10.211.55.3:40451"; |
| 57 | + } |
53 | 58 |
|
| 59 | + @Override |
| 60 | + public SecurityPolicy getSecurityPolicy() { |
| 61 | + return SecurityPolicy.None; |
| 62 | + } |
54 | 63 | } |
0 commit comments