opc 带有session
现在使用java来做工控系统的几种方式:
知识储备:
一、OPC Server端目前常见的有以下几种协议:
参考博客:
https://www.cnblogs.com/ioufev/articles/9697717.html
https://www.cnblogs.com/ioufev/articles/9697890.html
二、DOCM的配置
可以参考https://www.cnblogs.com/ioufev/p/9365919.html
三、OPCServer服务器属性
java 获取OPCServer的方式有两种,
1、jeasyopc:适用于32位操作系统
2、Utgrad :可跨平台
可以根据具体情况具体分析,相比较对于初次接触来说jeasyopc相对简单。
四、试验模拟OPC
1、实验用模拟OPCServer(50M):MatrikonOPC
2、实际OPCServer使用(450M,中文):KEPServer V6
Utgard:
官网:http://openscada.org/projects/utgard/
博客参考
https://www.cnblogs.com/ioufev/articles/9894452.html
https://elfasd.iteye.com/blog/2064410
JeasyOPC:
博客参考:
https://blog.csdn.net/qq_33720460/article/details/78478430
https://blog.csdn.net/wangzhi291/article/details/45029799
https://blog.csdn.net/diyu122222/article/details/77645668
五:本人只采用了UtgradUt开发用例
/**
* OPCServer 客户端连接
*/
public class UtgrandClient {
private final String LOCAL_HOST="10.0.0.17";//OPCServer服务器IP
private final String USER_NAME ="OPCServer";//DOCM配置时OPCServer的用户名
private final String PASS_WORD ="Admin123";//密码
private final String CLS_ID ="7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729";//cls_id
private final String DOMAIN ="";
private int count;
Server server =null;
public void utGrandReadData(){
System.out.print("*********************************");
System.out.print("************启动加载配置项*********");
System.out.print("*********************************");
final ConnectionInformation ci =new ConnectionInformation();
ci.setHost(LOCAL_HOST);
ci.setUser(USER_NAME);
ci.setPassword(PASS_WORD);
ci.setClsid(CLS_ID);
ci.setDomain(DOMAIN);
if (ci.getClsid() !=null ){
JISession session = JISession.createSession ( ci.getDomain (),ci.getUser (),ci.getPassword () );
session.setGlobalSocketTimeout ((int) System.currentTimeMillis());
session.useSessionSecurity(true);
server =new Server(ci,Executors.newSingleThreadScheduledExecutor());
}else if (ci.getProgId () !=null){
JISession session = JISession.createSession ( ci.getDomain (), ci.getUser (), ci.getPassword () );
session.setGlobalSocketTimeout ((int) System.currentTimeMillis());
session.useSessionSecurity(true);
server =new Server(ci,Executors.newSingleThreadScheduledExecutor());
}
try {
server.connect();
Group group = server.addGroup("VC");
Item item = group.addItem("k.k.k");
// Map items = group.addItems("Random.Real1",
// "Random.Real2", "Random.Real3", "Random.Real4");
dumpItem(item);
// for (Entry temp : items.entrySet()) {
// dumpItem(temp.getValue());
// }
}catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取监测点
* @param item
* @throws JIException
*/
private void dumpItem(Item item)throws JIException {
System.out.println("[" + (++count) +"],ItemName:[" + item.getId()
+"],value:" + item.read(true).getValue());
}
}
/**
* 使用线程来控制 opc client连接,优化运行机内存。(48小时测试内存无增长)
*/
public class ThreadUtgrad {
private Date date;//对象锁
private boolean flag =false;//控制唤醒或等待线程
public ThreadUtgrad() {
date =new Date();
}
public ThreadUtgrad(Date date){
this.date = date;
}
public void run() {
while(true){
synchronized(date){
if(flag){
try {
Thread.sleep(500);
}catch (InterruptedException e) {
e.printStackTrace();
}
date.notify();
flag =false;
}
}
}
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
class PrintMessageextends Thread{
@Override
public void run() {
UtgrandClient utgrandClient =new UtgrandClient();
while(true){
synchronized(date){
if(!flag){
try {
flag =true;
date.wait();
}catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("0.5秒的消息");
utgrandClient.utGrandReadData();
}
}
}
}
@PostConstruct
public void startUtgrandClient() {
Date date =new Date();
//打印5秒消息的线程
ThreadUtgrad threadUtgrad =new ThreadUtgrad(date);
PrintMessage printMessage = threadUtgrad.new PrintMessage();
printMessage.start();
threadUtgrad.run();
// //不影响打印线程的7秒消息线程
// new Thread(new Runnable(){
//
// @Override
// public void run() {
// while(true){
// try {
// Thread.sleep(7000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// System.out.println("7秒的消息");
// }
//
// }
//
// }).start();
}
作者:MartinX_c56e
链接:https://www.jianshu.com/p/afb45f585731
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
最新文章
- 用任务计划管理计划任务对付任务计划-禁止WPS提示升级
- Dapper入门学习
- javascript版快速排序和冒泡排序
- jQueryNotes仿QQ空间添加标记
- jquery阻止事件冒泡的3种方式
- ES6 module export options 模块导出、导入语法
- 数据结构Java实现03----单向链表的插入和删除
- ToDictionary,ToLookup
- c++的操作符格式记录
- Ubuntu 12.04 安装sougou for linux
- codecomb 2098【stone】
- Apple Catching(dp)
- Girls' research(manacher)
- 数据库及SQL优化
- Boost库安装(实测vs2012)
- 常系数齐次线性递推 &; 拉格朗日插值
- git 提示error setting certificate verify locations 解决方案
- Python-cookie,session
- Spring MVC自定义403,404,500状态码返回页面
- Lodop获取全部JS代码,传统JS模版的生成
热门文章
- HTML5游戏2D开发引擎
- MySQL快速生成100W条测试数据
- mysql 5.7 版本 You must reset your password using ALTER USER statement before executing this statement报错处理
- SpringBoot 项目启动 Failed to convert value of type 'java.lang.String' to required type 'cn.com.goldenwater.dcproj.dao.TacPageOfficePblmListDao';
- c语言1博客作业10
- JS客户端类型的判断
- [Google Guava] 4-函数式编程
- SQL的左连接与右链接
- linux mint 19 打开 Windows 下制作的 TXT 文件时‘乱码’
- Android系统输入事件分发详解