Created
March 5, 2018 16:24
-
-
Save kevinherron/be1dab4a94c6d9bce37d985d590da890 to your computer and use it in GitHub Desktop.
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
/* | |
* Copyright (c) 2017 Kevin Herron | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* and Eclipse Distribution License v1.0 which accompany this distribution. | |
* | |
* The Eclipse Public License is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* and the Eclipse Distribution License is available at | |
* http://www.eclipse.org/org/documents/edl-v10.html. | |
*/ | |
package org.eclipse.milo.examples.client; | |
import java.util.List; | |
import java.util.concurrent.CompletableFuture; | |
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; | |
import org.eclipse.milo.opcua.stack.core.AttributeId; | |
import org.eclipse.milo.opcua.stack.core.Identifiers; | |
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; | |
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName; | |
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn; | |
import org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse; | |
import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import static com.google.common.collect.Lists.newArrayList; | |
public class ReadAttributeExample implements ClientExample { | |
public static void main(String[] args) throws Exception { | |
ReadAttributeExample example = new ReadAttributeExample(); | |
new ClientExampleRunner(example).run(); | |
} | |
private final Logger logger = LoggerFactory.getLogger(getClass()); | |
@Override | |
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception { | |
// synchronous connect | |
client.connect().get(); | |
// Read BrowseName and DisplayName attributes of CurrentTime node | |
List<ReadValueId> readValueIds = newArrayList( | |
new ReadValueId( | |
Identifiers.Server_ServerStatus_CurrentTime, | |
AttributeId.BrowseName.uid(), | |
null, | |
QualifiedName.NULL_VALUE), | |
new ReadValueId( | |
Identifiers.Server_ServerStatus_CurrentTime, | |
AttributeId.DisplayName.uid(), | |
null, | |
QualifiedName.NULL_VALUE) | |
); | |
ReadResponse response = client.read(0.0, TimestampsToReturn.Server, readValueIds).get(); | |
DataValue[] results = response.getResults(); | |
assert results != null; | |
logger.info("BrowseName={} DisplayName={}", | |
results[0].getValue().getValue(), | |
results[1].getValue().getValue() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment