如何解决如何用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>
我正在测试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。 我希望这可以对某人有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。