OPC API 简介
————————————————
版权声明:本文为CSDN博主「lgbisha」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lgbisha/article/details/82898228
1. 列举某Server下的所有OPC连接
ServerList serverList = new ServerList("10.1.5.123", "freud",
"password", "");
Collection<ClassDetails> classDetails = serverList
.listServersWithDetails(new Category[] {
Categories.OPCDAServer10, Categories.OPCDAServer20,
Categories.OPCDAServer30 }, new Category[] {});
for (ClassDetails cds : classDetails) {
System.out.println(cds.getProgId() + "=" + cds.getDescription());
}
2.列举连接下的所有Group和Item
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
server.connect();
dumpTree(server.getTreeBrowser().browse(), 0);
dumpFlat(server.getFlatBrowser());
server.disconnect();
}
private static void dumpFlat(final FlatBrowser browser)
throws IllegalArgumentException, UnknownHostException, JIException {
for (String name : browser.browse()) {
System.out.println(name);
}
}
private static void dumpTree(final Branch branch, final int level) {
for (final Leaf leaf : branch.getLeaves()) {
dumpLeaf(leaf, level);
}
for (final Branch subBranch : branch.getBranches()) {
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");
}
return sb.toString();
}
private static void dumpLeaf(final Leaf leaf, final int level) {
System.out.println(printTab(level) + "Leaf: " + leaf.getName() + ":"
+ leaf.getItemId());
}
private static void dumpBranch(final Branch branch, final int level) {
System.out.println(printTab(level) + "Branch: " + branch.getName());
}
3.Item的同步查询
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());
server.connect();
Group group = server.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 : items.entrySet()) {
dumpItem(temp.getValue());
}
server.dispose();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
+ "],value:" + item.read(false).getValue());
}
private static int count;
4.Item的异步查询
private static final int PERIOD = 100;
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());
server.connect();
AccessBase access = new SyncAccess(server, PERIOD);
access.addItem("Random.Real5", new DataCallback() {
private int i;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
+ "],value:" + itemstate.getValue());
}
});
access.bind();
Thread.sleep(SLEEP);
access.unbind();
server.dispose();
}
5.Item的发布订阅查询
private static final int PERIOD = 100;
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());
server.connect();
AccessBase access = new Async20Access(server, PERIOD, false);
access.addItem("Random.Real5", new DataCallback() {
private int count;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++count) + "],ItemName:["
+ item.getId() + "],value:" + itemstate.getValue());
}
});
access.bind();
Thread.sleep(SLEEP);
access.unbind();
server.dispose();
}
6.自动重连Item异步读取
private static final int PERIOD = 100;
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());
AutoReconnectController controller = new AutoReconnectController(server);
controller.connect();
AccessBase access = new SyncAccess(server, PERIOD);
access.addItem("Random.Real5", new DataCallback() {
private int i;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
+ "],value:" + itemstate.getValue());
}
});
access.bind();
Thread.sleep(SLEEP);
access.unbind();
controller.disconnect();
}
7.Item同步写入
public static void main(String[] args) throws Exception {
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());
server.connect();
Group group = server.addGroup();
Item item = group.addItem("Square Waves.Real4");
final Float[] integerData = new Float[] { 1202f, 1203f, 1204f };
final JIArray array = new JIArray(integerData, false);
final JIVariant value = new JIVariant(array);
item.write(value);
Thread.sleep(2000);
dumpItem(item);
server.dispose();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
+ "],value:" + item.read(true).getValue());
}
private static int count;
8.Item异步写入
OPC API 简介的更多相关文章
- Web Api 简介
ASP.NET Web API 简介 ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP. ...
- ZooKeeper系列4:ZooKeeper API简介及编程
问题导读: 1.ZooKeeper API 共包含几个包? 2.如何使用ZooKeeper API 创建zookeeper应用程序? 1)ZooKeeper API 简介 ZooKeeper AP ...
- WebSocket API简介
WebSocket是html5新增加的一种通信协议,目前流行的浏览器都支持这个协议,例如Chrome,Safari,Firefox,Opera,IE等等,对该协议支持最早的应该是chrome,从chr ...
- 构建简单的 C++ 服务组件,第 1 部分: 服务组件体系结构 C++ API 简介
构建简单的 C++ 服务组件,第 1 部分: 服务组件体系结构 C++ API 简介 熟悉将用于 Apache Tuscany SCA for C++ 的 API.您将通过本文了解该 API 的主要组 ...
- Raphael Js矢量库API简介:
Raphael Js矢量库API简介:Raphael Javascript 是一个 Javascript的矢量库. 2010年6月15日,著名的JavaScript库ExtJS与触摸屏代码库项目jQT ...
- 开放数据接口 API 简介与使用场景、调用方法
此文章对开放数据接口 API 进行了功能介绍.使用场景介绍以及调用方法的说明,供用户在使用数据接口时参考之用. 在给大家分享的一系列软件开发视频课程中,以及在我们的社区微信群聊天中,都积极地鼓励大家开 ...
- Monkey脚本API简介
一.API简介 LaunchActivity(pkg_name, cl_name):启动应用的Activity.参数:包名和启动的Activity. Tap(x, y, tapDuration): 模 ...
- web API简介(四):客户端储存之IndexedDB API
概述 前篇:web API简介(三):客户端储存之Web Storage API 客户端储存从某一方面来说和动态网站差不多.动态网站是用服务端来储存数据,而客户端储存是用客户端来储存数据. Index ...
- web API简介(三):客户端储存之Web Storage API
概述 前篇:web API简介(二):客户端储存之document.cookie API 客户端储存从某一方面来说和动态网站差不多.动态网站是用服务端来储存数据,而客户端储存是用客户端来储存数据. W ...
随机推荐
- JS 自定义组件
经常会用到JS插件,但从未研究过插件的写法 目前主流的写法有多种,各有各的优缺点,下面,我就以最常规的一种写法举例 // plugin.js ;(function(undefined) {//防止出现 ...
- setuptools 版本太旧
第二是 setuptools 版本太旧,所以出现以下问题Command "python setup.py egg_info" failed with error code 1 in ...
- [唐胡璐]Selenium技巧- Highlight页面元素
大家都知道QTP的对象高亮显示功能特别强大, Selenium Webderiver也可以实现此功能。 高亮显示有时候对Debug还是相当有用的。 解决脚本: 调用脚本: 结果显示:
- 使用jdk自带的线程池。加载10个线程。
在开发中使用线程,经常不经意间就new Thread()一个出来,然后发现,这样做不是很好,特别是很多线程同时处理的时候,会出现CPU被用光导致机器假死,线程运行完成自动销毁后,又复活的情况. 所以在 ...
- 慕课网SSMOA办公系统
目录 需求分析 1 用例图 系统设计 包及全局配置 数据库设计 工具类 具体功能实现 1 dao层功能实现 2 编码过滤器及登陆拦截器 3 单元测试 遇到的问题总结 1 新建一个Modul不会打开新页 ...
- CF70E Information Reform
题意:给你一棵树,要选择若干节点,若一个点i没有选择,则有\(d(dis(i,j))\)的代价,其中j被选择.选择一个点代价为k,求最小代价. 首先,考虑这样一个问题: 如果距离a的最近被选点为i,距 ...
- 在Vue中使用TypeScript
TypeScript基础学习 初始化TS项目 Vue装饰器 vue-typescript-admin框架 1.TypeScript基础学习 2.初始化TS项目 3.Vue装饰器 Vue装饰器常用的有下 ...
- uname/hostname
uname 显示操作系统相关信息的命令. hostname 显示或者设置当前系统的主机名 修改hostname
- 【概率论】1-4:事件的的并集(Union of Events and Statical Swindles)
title: [概率论]1-4:事件的的并集(Union of Events and Statical Swindles) categories: Mathematic Probability key ...
- msf端口扫描
使用MSF发现主机和端口扫描 使用search命令查找需要的模块 MSF模块太多,记不住怎么办!!! 我们不需要记住所有模块,我们只要能找到我们想用的模块就行,平时积累使用的模块也行哦! 比如,我们通 ...