springboot 整合milo连接opcua

1.导入依赖

        <dependency>
			<groupId>org.eclipse.milo</groupId>
			<artifactId>sdk-client</artifactId>
			<version>0.6.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.milo</groupId>
			<artifactId>dictionary-reader</artifactId>
			<version>0.6.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.milo</groupId>
			<artifactId>sdk-server</artifactId>
			<version>0.6.0-SNAPSHOT</version>
		</dependency>

2.编写代码块


    @Test
    public void createOpcClient() throws Exception {
        //opc ua服务端地址
        String endPointUrl = "opc.tcp://127.0.0.1:49320";

        Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), 
        "security");
        Files.createDirectories(securityTempDir);
        if (!Files.exists(securityTempDir)) {
            throw new Exception("unable to create security dir: " + securityTempDir);
        }
        OpcUaClient opcUaClient = OpcUaClient.create(endPointUrl,
                endpoints ->
                        endpoints.stream()
                                .filter(e -> 
         e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri()))
                                .findFirst(),
                configBuilder ->
                        configBuilder
                                .setApplicationName(LocalizedText.english("eclipse milo 
         opc-ua client"))
                                .setApplicationUri("urn:eclipse:milo:examples:client")
                                //访问方式
                                .setIdentityProvider(new AnonymousProvider())
                                .setRequestTimeout(UInteger.valueOf(500))
                                .build()
        );


        opcUaClient.connect().get();
    }

3. 测试输出


        NodeId nodeId = new NodeId(2, "OPC_Test.设备 1.TAG1");

        //读取节点数据
        DataValue value = opcUaClient.readValue(0.0, TimestampsToReturn.Neither, 
        nodeId).get();

        // 状态
        System.out.println("Status: " + value.getStatusCode());

        //标识符
        String id = String.valueOf(nodeId.getIdentifier());
        System.out.println(id + ": " + value.getValue().getValue());

连接时出现的依赖冲突:

此依赖在很多帖子中没有导入 了解到此依赖是谷歌的一个工具类 疑惑的是跟opcua 的连接又有什么联系 可能是本身导入的依赖出现了版本问题或者是冲突 不管咋说希望大家养成一个文件管理的好习惯

我在上面尝试了很多方式建立连接 始终没有获取到节点的值 网上很多帖子没有这个依赖 

<!--谷歌的官方的第三方库-->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>22.0</version>
</dependency>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值