本文整理汇总了Java中org.eclipse.milo.opcua.sdk.client.OpcUaClient类的典型用法代码示例。如果您正苦于以下问题:Java OpcUaClient类的具体用法?Java OpcUaClient怎么用?Java OpcUaClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpcUaClient类属于org.eclipse.milo.opcua.sdk.client包,在下文中一共展示了OpcUaClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static void main(final String[] args) throws InterruptedException, ExecutionException {
final Semaphore s = new Semaphore(0);
connect()
.whenComplete((client, e) -> {
// called when the connect operation finished ... either way
if (e == null) {
System.out.println("Connected");
} else {
System.err.println("Failed to connect");
e.printStackTrace();
}
})
.thenCompose(OpcUaClient::disconnect)
.thenRun(s::release); // wake up s.acquire() below
System.out.println("Wait for completion");
s.acquire(); // what could could wrong?
System.out.println("Bye bye");
}
示例2: translate
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static CompletableFuture<BrowsePathResult> translate(
final OpcUaClient client,
final NodeId startingNode,
final String... path) {
Objects.requireNonNull(startingNode);
Objects.requireNonNull(path);
// convert to elements
final RelativePathElement[] elements = new RelativePathElement[path.length];
for (int i = 0; i < path.length; i++) {
elements[i] = new RelativePathElement(
Identifiers.HierarchicalReferences,
false, true,
QualifiedName.parse(path[i]));
}
// translate
final BrowsePath request = new BrowsePath(startingNode, new RelativePath(elements));
return client.translateBrowsePaths(singletonList(request)).thenApply(response -> response.getResults()[0]);
}
示例3: populateNodes
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public void populateNodes(String indent, OpcUaClient client, NodeId browseRoot) {
try {
List<Node> nodes = client.getAddressSpace().browse(browseRoot).get();
for (Node node : nodes) {
logger.info("{} Node={}", indent, node.getBrowseName().get().getName());
String nodeName = node.getBrowseName().get().getName();
NodeId nodeId = node.getNodeId().get();
activeNodes.put(nodeName, node);
nodeIdToString.put(nodeId, nodeName);
// recursively browse to children
populateNodes(indent + " ", client, nodeId);
}
} catch (InterruptedException | ExecutionException e) {
logger.error("Browsing nodeId={} failed: {}", browseRoot, e.getMessage(), e);
}
}
示例4: sqrt
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
private CompletableFuture<Double> sqrt(OpcUaClient client, Double input) {
NodeId objectId = NodeId.parse("ns=2;s=HelloWorld");
NodeId methodId = NodeId.parse("ns=2;s=HelloWorld/sqrt(x)");
CallMethodRequest request = new CallMethodRequest(
objectId, methodId, new Variant[]{new Variant(input)});
return client.call(request).thenCompose(result -> {
StatusCode statusCode = result.getStatusCode();
if (statusCode.isGood()) {
Double value = (Double) l(result.getOutputArguments()).get(0).getValue();
return CompletableFuture.completedFuture(value);
} else {
CompletableFuture<Double> f = new CompletableFuture<>();
f.completeExceptionally(new UaException(statusCode));
return f;
}
});
}
示例5: run
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
client.connect().get();
DataValue dataValue = client.readValue(
0.0,
TimestampsToReturn.Neither,
NodeId.parse("ns=2;s=Demo.Static.Scalar.WorkOrder")
).get();
ExtensionObject xo = (ExtensionObject) dataValue.getValue().getValue();
// Decoding a struct with custom DataType requires a DataTypeManager
// that has the codec registered with it. OpcUaClient automatically
// reads any DataTypeDictionary nodes present in the server upon
// connecting and dynamically generates codecs for custom structures.
Object value = xo.decode(client.getDataTypeManager());
logger.info("value: {}", value);
future.complete(client);
}
示例6: OpcUaSubscriptionManager
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public OpcUaSubscriptionManager(OpcUaClient client) {
this.client = client;
deliveryQueue = new ExecutionQueue(client.getConfig().getExecutor());
processingQueue = new ExecutionQueue(client.getConfig().getExecutor());
client.addSessionActivityListener(new SessionActivityListener() {
@Override
public void onSessionInactive(UaSession session) {
// This allows a session that gets re-activated to immediately start
// publishing again instead of waiting for outstanding PublishRequests
// from before the re-activation to expire/timeout.
pendingCountMap.replace(session.getSessionId(), new AtomicLong(0));
}
});
}
示例7: browseNode
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
private void browseNode(String indent, OpcUaClient client, NodeId browseRoot) {
BrowseDescription browse = new BrowseDescription(
browseRoot,
BrowseDirection.Forward,
Identifiers.References,
true,
uint(NodeClass.Object.getValue() | NodeClass.Variable.getValue()),
uint(BrowseResultMask.All.getValue())
);
try {
BrowseResult browseResult = client.browse(browse).get();
List<ReferenceDescription> references = toList(browseResult.getReferences());
for (ReferenceDescription rd : references) {
logger.info("{} Node={}", indent, rd.getBrowseName().getName());
// recursively browse to children
rd.getNodeId().local().ifPresent(nodeId -> browseNode(indent + " ", client, nodeId));
}
} catch (InterruptedException | ExecutionException e) {
logger.error("Browsing nodeId={} failed: {}", browseRoot, e.getMessage(), e);
}
}
示例8: run
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
// synchronous read request via VariableNode
VariableNode node = client.getAddressSpace().createVariableNode(Identifiers.Server_ServerStatus_StartTime);
DataValue value = node.readValue().get();
logger.info("StartTime={}", value.getValue().getValue());
// asynchronous read request
readServerStateAndTime(client).thenAccept(values -> {
DataValue v0 = values.get(0);
DataValue v1 = values.get(1);
logger.info("State={}", ServerState.from((Integer) v0.getValue().getValue()));
logger.info("CurrentTime={}", v1.getValue().getValue());
future.complete(client);
});
}
示例9: read
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static CompletableFuture<List<DataValue>> read(
final OpcUaClient client,
final AttributeId attributeId,
final NodeId... nodeIds) {
return client
.read(
0,
Both,
asList(nodeIds),
nCopies(nodeIds.length, attributeId.uid()));
}
示例10: createClient
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static CompletableFuture<OpcUaClient> createClient() {
final String endpoint = String.format("opc.tcp://%s:%s", Constants.HOST, Constants.PORT);
return UaTcpStackClient
.getEndpoints(endpoint) // look up endpoints from remote
.thenApply(endpoints -> new OpcUaClient(buildConfiguration(endpoints)));
}
示例11: createClientSync
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static OpcUaClient createClientSync() throws InterruptedException, ExecutionException {
final String endpoint = String.format("opc.tcp://%s:%s", Constants.HOST, Constants.PORT);
final EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints(endpoint)
.get();
return new OpcUaClient(buildConfiguration(endpoints));
}
示例12: connectSync
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static OpcUaClient connectSync() throws InterruptedException, ExecutionException {
final OpcUaClient client = createClientSync();
client.connect()
.get();
return client;
}
示例13: main
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
final OpcUaClient client = Connect.connect().get();
try {
System.out.format("%-60s %-15s %s%n", "Name", "Type", "NodeID");
System.out.println(
"==========================================================================================");
browse(client, Identifiers.RootFolder, "");
} finally {
client.disconnect().get();
}
}
示例14: write
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static CompletableFuture<StatusCode> write(
final OpcUaClient client,
final NodeId nodeId,
final Object value) {
return client.writeValue(nodeId, new DataValue(new Variant(value)));
}
示例15: newClient
import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
private CompletableFuture<OpcUaClient> newClient(OpcUaClientConfig config) {
return CompletableFuture.supplyAsync(() -> {
OpcUaClient c = new OpcUaClient(config);
c.addFaultListener(fault -> logger.error("fault on {}", fault.getResponseHeader().getServiceResult()));
c.addSessionActivityListener(this);
client.set(c);
return c;
}, pool);
}