如何用hurence读取java中的opc-ua变量

问题描述

我正在尝试从OPC-UA服务器读取变量。我正在使用com.hurence.opc库。我的代码是

<resultMap id="authorMap" type="Author" autoMapping="true">
    <id column="dummy_id" />
</resultMap>

<resultMap id="booksMap" type="Book" autoMapping="true">
    <id property="id_book" column="id_book" />
    <association property="author" resultMap="authorMap" columnPrefix="a_" />
</resultMap>

<select id="getBooks" resultMap="booksMap">
   SELECT 
       id_book,title,year,genre,author_name AS a_author_name,author_surname AS a_author_surname,auhtor_age AS a_author_age 
   FROM book
</select>

enter image description here

enter image description here

我正在测试opc服务器参考实现。但是我无法引用该变量,但出现异常

    OpcUaConnectionProfile connectionProfile = new OpcUaConnectionProfile()
            .withConnectionUri(URI.create("opc.tcp://localhost:62541/Quickstarts/ReferenceServer"))
            .withClientIdUri("imp:ladisa").withClientName("GestionaleLadisa")
            .withSocketTimeout(Duration.ofSeconds(15));

    // Create an instance of a ua operations
    OpcUaOperations opcUaOperations = new OpcUaTemplate();
    // connect using our profile
    opcUaOperations.connect(connectionProfile).doOnError(throwable -> System.out.println(throwable.getMessage()))
            .ignoreElement().blockingAwait();

    
      OpcUaSessionProfile sessionProfile = new OpcUaSessionProfile()
                //the publication window
                .withPublicationInterval(Duration.ofMillis(100));
      
      
      
        try (OpcSession session = opcUaOperations.createSession(sessionProfile).blockingGet()) {
            List<OpcData> result = session.read("Objects.CTT.Scalar.Scalar_Instructions").blockingGet();
            for(var dt:result) {
                System.out.println( dt.getValue());
            }
            
            
            
        }         

指向OPC-UA树中的节点的正确方法是什么?

解决方法

我发现的方式是:

List<OpcData> result = session.read("ns=2;s=Scalar_Instructions").blockingGet();

使用nodeId。 我希望这可以对某人有所帮助。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...