• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OpcUaClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.milo.opcua.sdk.client.OpcUaClient的典型用法代码示例。如果您正苦于以下问题:Java OpcUaClient类的具体用法?Java OpcUaClient怎么用?Java OpcUaClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OpcUaClient类属于org.eclipse.milo.opcua.sdk.client包,在下文中一共展示了OpcUaClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
    }
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:25,代码来源:Connect.java


示例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]);
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:24,代码来源:Lookup.java


示例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);
	}
}
 
开发者ID:ashfaqfarooqui,项目名称:OPCUA-AMQ,代码行数:18,代码来源:OpcComm.java


示例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;
        }
    });
}
 
开发者ID:eclipse,项目名称:milo,代码行数:21,代码来源:MethodExample.java


示例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);
}
 
开发者ID:eclipse,项目名称:milo,代码行数:23,代码来源:UnifiedAutomationReadCustomDataTypeExample.java


示例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));
        }
    });
}
 
开发者ID:eclipse,项目名称:milo,代码行数:17,代码来源:OpcUaSubscriptionManager.java


示例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);
    }
}
 
开发者ID:eclipse,项目名称:milo,代码行数:26,代码来源:BrowseExample.java


示例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);
    });
}
 
开发者ID:eclipse,项目名称:milo,代码行数:23,代码来源:ReadExample.java


示例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()));
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:13,代码来源:Read.java


示例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)));
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:8,代码来源:Connect.java


示例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));
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:9,代码来源:Connect.java


示例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;
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:9,代码来源:Connect.java


示例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();
        }
    }
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:15,代码来源:Browse.java


示例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)));
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:8,代码来源:Write.java


示例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);
}
 
开发者ID:comtel2000,项目名称:opc-ua-client,代码行数:10,代码来源:OpcUaClientConnector.java


示例16: 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();

    // start browsing at root folder
    Node rootNode = client.getAddressSpace().getNodeInstance(Identifiers.RootFolder).get();

    Tree<Node> tree = new Tree<>(rootNode);

    long startTime = System.nanoTime();
    browseRecursive(client, tree).get();
    long endTime = System.nanoTime();

    traverse(tree, 0, (depth, n) -> {
        try {
            logger.info(indent(depth) + n.getBrowseName().get().getName());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    });

    logger.info(
        "Browse took {}ms",
        TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS));

    future.complete(client);
}
 
开发者ID:eclipse,项目名称:milo,代码行数:29,代码来源:BrowseAsyncExample.java


示例17: 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();

    // start browsing at root folder
    browseNode("", client, Identifiers.RootFolder);

    future.complete(client);
}
 
开发者ID:eclipse,项目名称:milo,代码行数:11,代码来源:BrowseExample.java


示例18: 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();

    // Get a typed reference to the Server object: ServerNode
    ServerNode serverNode = client.getAddressSpace().getObjectNode(
        Identifiers.Server,
        ServerNode.class
    ).get();

    // Read properties of the Server object...
    String[] serverArray = serverNode.getServerArray().get();
    String[] namespaceArray = serverNode.getNamespaceArray().get();

    logger.info("ServerArray={}", Arrays.toString(serverArray));
    logger.info("NamespaceArray={}", Arrays.toString(namespaceArray));

    // Read the value of attribute the ServerStatus variable component
    ServerStatusDataType serverStatus = serverNode.getServerStatus().get();

    logger.info("ServerStatus={}", serverStatus);

    // Get a typed reference to the ServerStatus variable
    // component and read value attributes individually
    ServerStatusNode serverStatusNode = serverNode.getServerStatusNode().get();
    BuildInfo buildInfo = serverStatusNode.getBuildInfo().get();
    DateTime startTime = serverStatusNode.getStartTime().get();
    DateTime currentTime = serverStatusNode.getCurrentTime().get();
    ServerState state = serverStatusNode.getState().get();

    logger.info("ServerStatus.BuildInfo={}", buildInfo);
    logger.info("ServerStatus.StartTime={}", startTime);
    logger.info("ServerStatus.CurrentTime={}", currentTime);
    logger.info("ServerStatus.State={}", state);

    future.complete(client);
}
 
开发者ID:eclipse,项目名称:milo,代码行数:39,代码来源:ReadNodeExample.java


示例19: browseNode

import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
private void browseNode(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());

            // recursively browse to children
            browseNode(indent + "  ", client, node.getNodeId().get());
        }
    } catch (InterruptedException | ExecutionException e) {
        logger.error("Browsing nodeId={} failed: {}", browseRoot, e.getMessage(), e);
    }
}
 
开发者ID:eclipse,项目名称:milo,代码行数:15,代码来源:BrowseNodeExample.java


示例20: connect

import org.eclipse.milo.opcua.sdk.client.OpcUaClient; //导入依赖的package包/类
public static CompletableFuture<OpcUaClient> connect() {
    return createClient()
            .thenCompose(OpcUaClient::connect) // trigger connect
            .thenApply(c -> (OpcUaClient) c); // cast result of connect from UaClient to OpcUaClient
}
 
开发者ID:ctron,项目名称:milo-ece2017,代码行数:6,代码来源:Connect.java



注:本文中的org.eclipse.milo.opcua.sdk.client.OpcUaClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TransformerFactoryImpl类代码示例发布时间:2022-05-23
下一篇:
Java CachingHttpClientBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap