import javafish.clients.opc.JOpc; import javafish.clients.opc.componentname import.OpcItem; 需要导什么包

jEasyOpc心得_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&10W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
jEasyOpc心得
&&jeasyopc学习过程中总结出的注意事项和重要方法步骤
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
加入VIP
还剩6页未读,
定制HR最喜欢的简历
你可能喜欢Property file javafish.clients.opc.JCustomOpc doesn't exist. System terminated.
[问题点数:20分,结帖人hidafa]
本版专家分:0
结帖率 100%
CSDN今日推荐
匿名用户不能发表回复!|
CSDN今日推荐只要想学,什么时候都不晚!
JAVA使用JeasyOPC读取OPC 服务器数据
首先在src下新建包javafish.clients.opc 将JCustomOpc.properties 拷贝到包中, 然后导入三个jar包jeasyopc.jar commons-logging-1.1.jar和log4j-1.2.13.jar 在项目下新建一个lib目录,也可以自定义名字和路径,但是在JCustomOpc.properties 配置中能指定这个目录。将JCustomOpc.dll拷贝到 你定义好的目录下。写一个测试类,添加以下代码。[java]
确保自己机器已经运行了服务端。如图:JCustomOpc.properties 和JCustomOpc.dll 目录要准确,不然就容易报错找不到配置文件。
没有更多推荐了,只要是大神,都是我师傅
java 连接opc
第一种:用utgard连接opc,以下代码为官方的代码,改为自己的就可以了。&dependency&
&groupId&org.openscada.external&/groupId&
&artifactId&org.openscada.external.jcifs&/artifactId&
&version&1.2.25&/version&
&/dependency&
&dependency&
&groupId&org.openscada.jinterop&/groupId&
&artifactId&org.openscada.jinterop.core&/artifactId&
&version&2.1.8&/version&
&/dependency&
&dependency&
&groupId&org.openscada.jinterop&/groupId&
&artifactId&org.openscada.jinterop.deps&/artifactId&
&version&1.5.0&/version&
&/dependency&
&dependency&
&groupId&org.openscada.utgard&/groupId&
&artifactId&org.openscada.opc.dcom&/artifactId&
&version&1.5.0&/version&
&/dependency&
&dependency&
&groupId&org.openscada.utgard&/groupId&
&artifactId&org.openscada.opc.lib&/artifactId&
&version&1.5.0&/version&
&/dependency&
&dependency&
&groupId&org.bouncycastle&/groupId&
&artifactId&bcprov-jdk15on&/artifactId&
&version&1.59&/version&
&/dependency&public static void main(String[] args) throws Exception{
final ConnectionInformation ci = new ConnectionInformation();
ci.setHost("localhost");
ci.setUser("Administrator");
ci.setPassword("gl");
ci.setProgId("Matrikon.OPC.Simulation.1");
final String itemId = "Bucket Brigade.Int4";
// create a new server
final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
// connect to server
server.connect();
System.out.println("连接成功");
final AccessBase access = new SyncAccess(server, <span style="color:#);
access.addItem(itemId, new DataCallback() {
public void changed(Item item, ItemState state) {
// also dump value
if (state.getValue().getType() == JIVariant.VT_UI4) {
System.out.println("&&& " + state + " / value = " + state.getValue().getObjectAsUnsigned().getValue());
System.out.println("&&& " + state + " / ------value = " + state.getValue().getObject());
} catch (JIException e) {
e.printStackTrace();
// Add a new group
final Group group = server.addGroup("test");
// Add a new item to the group
final Item item = group.addItem(itemId);
// start reading
access.bind();
// add a thread for writing a value every 3 seconds
ScheduledExecutorService writeThread = Executors.newSingleThreadScheduledExecutor();
final AtomicInteger i = new AtomicInteger(0);
writeThread.scheduleWithFixedDelay(new Runnable() {
public void run() {
final JIVariant value = new JIVariant(i.incrementAndGet());
System.out.println("&&& " + "writing value " + i.get());
item.write(value);
} catch (JIException e) {
e.printStackTrace();
}, 5, 3, TimeUnit.SECONDS);
// wait a little bit
Thread.sleep(20 * <span style="color:#);
writeThread.shutdownNow();
// stop reading
access.unbind();
} catch (final JIException e) {
System.out.println(String.format("%08X: %s", e.getErrorCode(), server.getErrorMessage(e.getErrorCode())));
}第二种:使用jOpc连接 opc服务器,只支持32位的package com.kaiya.svg.opc;
import javafish.clients.opc.JOpc;
import javafish.clients.opc.asynch.AsynchEvent;
import javafish.clients.opc.asynch.OpcAsynchGroupListener;
import javafish.clients.opc.component.OpcGroup;
import javafish.clients.opc.component.OpcItem;
import javafish.clients.opc.exception.Asynch10ReadException;
import javafish.clients.opc.exception.Asynch10UnadviseException;
import javafish.clients.opc.exception.CoInitializeException;
import javafish.clients.opc.exception.ComponentNotFoundException;
import javafish.clients.opc.exception.ConnectivityException;
import javafish.clients.opc.exception.CoUninitializeException;
import javafish.clients.opc.exception.GroupActivityException;
import javafish.clients.opc.exception.GroupUpdateTimeException;
import javafish.clients.opc.exception.UnableAddGroupException;
import javafish.clients.opc.exception.UnableAddItemException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
public class AsynchReadAndGroupActivityExample {
* @param args
* @throws InterruptedException
public static void main(String[] args) throws InterruptedException {
AsynchReadAndGroupActivityExample test = new AsynchReadAndGroupActivityExample();
/**初始化服务**/
JOpc.coInitialize();
catch (CoInitializeException e1) {
e1.printStackTrace();
/**建立server对象jopc(IP ,OPCServer名称 ,任意)**/
JOpc jopc = new JOpc("localhost", "Matrikon.OPC.Simulation.1", "JOPC1");
/**建立一个组((用户组的标识名称),开始活动的组(true 开始 false 不开始) 默认true,刷新组的时间 毫秒,默认 0.0f)**/
OpcGroup group = new OpcGroup("test", true, 20, <span style="color:#f);
/**name属性表示OPC服务器中的ItemID**/
OpcItem item1 = new OpcItem("Bucket Brigade.Int1", true, "");
OpcItem item2 = new OpcItem("Bucket Brigade.Int4", true, "");
/**添加到组**/
group.addItem(item1);
group.addItem(item2);
jopc.addGroup(group);
/**调用JCustomOpc.connect()连接服务器**/
jopc.connect();
System.out.println("OPC client is connected...");
System.out.println("OPC 服务器连接成功...");
/** 调用JOpc.registerGroups()注册所有的组使用registerGroups()方法注册则OpcItem不用单独注册。如果调用registerGroup(OpcGroup)注册OpcGroup,则还需调用registerItem(OpcGroup,OpcItem)**/
jopc.registerGroups();
System.out.println("OPC groups are registered...");
System.out.println("OPC groups 注册成功...");
/** 调用JOpc.asynch10Read()异步读数据**/
jopc.asynch10Read(group);
System.out.println("OPC asynchronous reading is applied...");
System.out.println("OPC 正在异步读取数据...");
OpcGroup downGroup;
/**当前时间秒数**/
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) & <span style="color:#) {
jopc.ping();
downGroup = jopc.getDownloadGroup();
if (downGroup != null) {
System.out.println(downGroup);
if ((System.currentTimeMillis() - start) &= <span style="color:#) {
jopc.setGroupActivity(group, false);
synchronized(test) {
/**间隔50毫秒**/
test.wait(<span style="color:#);
// change activity
jopc.setGroupActivity(group, true);
// change updateTime
jopc.setGroupUpdateTime(group, <span style="color:#);
start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) & <span style="color:#) {
jopc.ping();
downGroup = jopc.getDownloadGroup();
if (downGroup != null) {
System.out.println(downGroup);
synchronized(test) {
test.wait(<span style="color:#);
/**断开异步读取**/
jopc.asynch10Unadvise(group);
System.out.println("OPC asynchronous reading is unadvise...");
System.out.println("OPC 断开异步读取...");
/**断开连接**/
JOpc.coUninitialize();
System.out.println("Program terminated...");
System.out.println("断开服务器连接...");
catch (ConnectivityException e) {
e.printStackTrace();
catch (UnableAddGroupException e) {
e.printStackTrace();
catch (UnableAddItemException e) {
e.printStackTrace();
catch (ComponentNotFoundException e) {
e.printStackTrace();
catch (Asynch10ReadException e) {
e.printStackTrace();
catch (Asynch10UnadviseException e) {
e.printStackTrace();
catch (GroupUpdateTimeException e) {
e.printStackTrace();
catch (GroupActivityException e) {
e.printStackTrace();
catch (CoUninitializeException e) {
e.printStackTrace();
如果报这样的错:Property file javafish.clients.opc.JCustomOpc doesn't exist. System terminated那你就建立javafish.clients.opc这个文件夹,把JCustomOpc.properties
文件放入下面,文件内容如下在与src同目录下建立lib文件夹,放入JCustomOpc.dll
文件(自己下吧),当然你还需要jeasyopc.jar文件。难得写还是给你个链接吧: https://download.csdn.net/download/qq_65135
没有更多推荐了,超详细Java使用Jop读取OPC服务器数据
package javafish.clients.opc;
import javafish.clients.opc.asynch.AsynchEvent;
import javafish.clients.opc.asynch.OpcAsynchGroupListener;
import javafish.clients.opc.component.OpcGroup;
import javafish.clients.opc.component.OpcItem;
import javafish.clients.opc.exception.Asynch10ReadException;
import javafish.clients.opc.exception.Asynch10UnadviseException;
import javafish.clients.opc.exception.CoInitializeException;
import javafish.clients.opc.exception.ComponentNotFoundException;
import javafish.clients.opc.exception.ConnectivityException;
import javafish.clients.opc.exception.CoUninitializeException;
import javafish.clients.opc.exception.GroupActivityException;
import javafish.clients.opc.exception.GroupUpdateTimeException;
import javafish.clients.opc.exception.UnableAddGroupException;
import javafish.clients.opc.exception.UnableAddItemException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
public class AsynchReadAndGroupActivityExample {
* @param args
* @throws InterruptedException
public static void main(String[] args) throws InterruptedException {
AsynchReadAndGroupActivityExample test = new AsynchReadAndGroupActivityExample();
/**初始化服务**/
JOpc.coInitialize();
catch (CoInitializeException e1) {
e1.printStackTrace();
/**建立server对象jopc(IP ,OPCServer名称 ,任意)**/
JOpc jopc = new JOpc("localhost", "KEPware.KEPServerEx.V6", "JOPC1");
/**建立一个组((用户组的标识名称),开始活动的组(true 开始 false 不开始) 默认true,刷新组的时间 毫秒,默认 0.0f)**/
OpcGroup group = new OpcGroup("group1", true, 20, <span style="color:#f);
/**name属性表示OPC服务器中的ItemID**/
OpcItem item1 = new OpcItem("c1.d1.m1", true, "");
OpcItem item2 = new OpcItem("c1.d1.m2", true, "");
/**添加到组**/
group.addItem(item1);
group.addItem(item2);
jopc.addGroup(group);
/**调用JCustomOpc.connect()连接服务器**/
jopc.connect();
System.out.println("OPC client is connected...");
System.out.println("OPC 服务器连接成功...");
/** 调用JOpc.registerGroups()注册所有的组使用registerGroups()方法注册则OpcItem不用单独注册。如果调用registerGroup(OpcGroup)注册OpcGroup,则还需调用registerItem(OpcGroup,OpcItem)**/
jopc.registerGroups();
System.out.println("OPC groups are registered...");
System.out.println("OPC groups 注册成功...");
/** 调用JOpc.asynch10Read()异步读数据**/
jopc.asynch10Read(group);
System.out.println("OPC asynchronous reading is applied...");
System.out.println("OPC 正在异步读取数据...");
OpcGroup downGroup;
/**当前时间秒数**/
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) & <span style="color:#) {
jopc.ping();
downGroup = jopc.getDownloadGroup();
if (downGroup != null) {
System.out.println(downGroup);
if ((System.currentTimeMillis() - start) &= <span style="color:#) {
jopc.setGroupActivity(group, false);
synchronized(test) {
/**间隔50毫秒**/
test.wait(<span style="color:#);
// change activity
jopc.setGroupActivity(group, true);
// change updateTime
jopc.setGroupUpdateTime(group, <span style="color:#);
start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) & <span style="color:#) {
jopc.ping();
downGroup = jopc.getDownloadGroup();
if (downGroup != null) {
System.out.println(downGroup);
synchronized(test) {
test.wait(<span style="color:#);
/**断开异步读取**/
jopc.asynch10Unadvise(group);
System.out.println("OPC asynchronous reading is unadvise...");
System.out.println("OPC 断开异步读取...");
/**断开连接**/
JOpc.coUninitialize();
System.out.println("Program terminated...");
System.out.println("断开服务器连接...");
catch (ConnectivityException e) {
e.printStackTrace();
catch (UnableAddGroupException e) {
e.printStackTrace();
catch (UnableAddItemException e) {
e.printStackTrace();
catch (ComponentNotFoundException e) {
e.printStackTrace();
catch (Asynch10ReadException e) {
e.printStackTrace();
catch (Asynch10UnadviseException e) {
e.printStackTrace();
catch (GroupUpdateTimeException e) {
e.printStackTrace();
catch (GroupActivityException e) {
e.printStackTrace();
catch (CoUninitializeException e) {
e.printStackTrace();
没有更多推荐了,

我要回帖

更多关于 componentname import 的文章

 

随机推荐