javaopcclient开源Utgard学习及踩坑

更新时间:2023-08-12 05:17:00 阅读: 评论:0

javaopcclient开源Utgard学习及踩坑
最近的项⽬中需要运⽤到opc client。需要从opc rver中获取数据,或修改参数。主要运⽤的语⾔为java。
准备知识:opc rver 协议
OPC DA: Data Access协议,是最基本的OPC协议。OPC DA服务器本⾝不存储数据,只负责显⽰数据收集点的当前值。客户端可以设置⼀个refresh interval,定期刷新这个值。⽬前常见的协议版本号为2.0和3.0,两个协议不完全兼容。也就是⽤OPC DA 2.0协议的客户端连不上OPC DA 3.0的Server
OPC HDA: Historical Data Access协议。前⾯说过DA只显⽰当前状态值,不存储数据。⽽HDA协议是由数据库提供,提供了历史数据访问的能⼒。⽐如价格昂贵的Historian数据库,就是提供HDA协议接⼝访问OPC的历史数据。HDA的Java客户端⽬前我没找到免费的。
OPC UA: Unified Architecture统⼀架构协议。诞⽣于2008年,摒弃了前⾯⽼的OPC协议繁杂,互不兼容等劣势,并且不再需要COM⼝访问,⼤⼤简化了编程的难度。基于OPC UA的开源客户端⾮常多。不过由于诞⽣时间较晚,⽬前在国内⼯业上未⼤规模应⽤,并且这个协议本⾝就跟旧的DA协议不兼容,客户端没法通⽤。
com:Component Object Model对象组件模型,是微软定义的⼀套软件的⼆进制接⼝,可以实现跨编程语⾔的进程间通信,进⽽实现复⽤。
dcom:Microsoft Distributed Component Object Model,⽹络传输数据的COM协议,客户端也可以通过互联⽹分布在各个⾓落。然后准备开⼯,⼀番查找后,发现存在两个开源类库
1.
2.
JEasy是java调⽤动态连接库,底层⽤的是jni,dll库⽐较⽼。
Utgard则是纯java编写,就是不⽀持opc 3.0协议。
JEasy在调⽤的时候,jni总是报错,⽆⼒解决。
最终使⽤了Utgard的库,在其官⽹上学习使⽤⽅法,最终还是跑起来了,其中opc服务端的配置,⼀般⼯程⼈员会配置好,不需要操⼼dcom配置之类的问题。最终项⽬是maven配置完成。最终运⾏的时候,发现⼀个group死活发现不了,跟我说是新增加的,但是opc 服务端却没有重新配置,导致⽆法发现,最后还是研究了⼿册,⾃⼰⼿动配置完成了。
关键API⽰例
列举某Server下的所有OPC连接
ServerList rverList = new ServerList("10.1.5.123", "freud",
"password", "");
Collection<ClassDetails> classDetails = rverList
.listServersWithDetails(new Category[] {
Categories.OPCDAServer10, Categories.OPCDAServer20,
appearanceCategories.OPCDAServer30 }, new Category[] {});
for (ClassDetails cds : classDetails) {
System.out.ProgId() + "=" + Description());
}
awkward列举连接下的所有Group和Item
ConnectionInformation ci = new ConnectionInformation();
ci.tHost("10.1.5.123");
ci.tDomain("");
ci.tUr("freud");
ci.tPassword("password");
ci.tClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server rver = new Server(ci, wSingleThreadScheduledExecutor()); t();
TreeBrowr().brow(), 0);
FlatBrowr());
rver.disconnect();
}
private static void dumpFlat(final FlatBrowr browr)
throws IllegalArgumentException, UnknownHostException, JIException {
for (String name : browr.brow()) {
System.out.println(name);
}
}
private static void dumpTree(final Branch branch, final int level) {
for (final Leaf leaf : Leaves()) {
dumpLeaf(leaf, level);
}
for (final Branch subBranch : Branches()) {
dumpBranch(subBranch, level);
dumpTree(subBranch, level + 1);
}
}
private static String printTab(int level) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < level; i++) {
sb.append("\t");
}
String();
}
private static void dumpLeaf(final Leaf leaf, final int level) {
System.out.println(printTab(level) + "Leaf: " + Name() + ":"
+ ItemId());
}
private static void dumpBranch(final Branch branch, final int level) {
System.out.println(printTab(level) + "Branch: " + Name());
}
the awful truthItem的同步查询
ConnectionInformation ci = new ConnectionInformation();
ci.tHost("10.1.5.123");
ci.tDomain("");
ci.tUr("freud");
ci.tPassword("password");
ci.tClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server rver = new Server(ci,
Group group = rver.addGroup();
Item item = group.addItem("Random.Real5");
Map<String, Item> items = group.addItems("Random.Real1",
"Random.Real2", "Random.Real3", "Random.Real4");
dumpItem(item);
for (Entry<String, Item> temp : Set()) {
Value());
}
rver.dispo();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + Id()  + "],value:" + ad(fal).getValue());
}
private static int count;
Item的异步查询
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.tHost("10.1.5.123");
ci.tDomain("");
ci.tUr("freud");
ci.tPassword("password");
ci.tClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server rver = new Server(ci,
AccessBa access = new SyncAccess(rver, PERIOD);
stylinaccess.addItem("Random.Real5", new DataCallback() {
private int i;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++i) + "],ItemName:[" + Id()    + "],value:" + Value());
}
});
no gain
access.bind();
抚顺翻译公司Thread.sleep(SLEEP);
access.unbind();
rver.dispo();优惠价
}
Item的发布订阅查询
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
limited是什么意思ci.tHost("10.1.5.123");
ci.tDomain("");
ci.tUr("freud");
ci.tPassword("password");
ci.tClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server rver = new Server(ci,苏格兰议会选举结果出炉
AccessBa access = new Async20Access(rver, PERIOD, fal); access.addItem("Random.Real5", new DataCallback() {
private int count;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++count) + "],ItemName:["
+ Id() + "],value:" + Value());
}
});
access.bind();
Thread.sleep(SLEEP);
access.unbind();
rver.dispo();
}
波兰人英文⾃动重连Item异步读取

本文发布于:2023-08-12 05:17:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1129740.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:协议   发现   配置
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图