|
@@ -1,5 +1,6 @@
|
|
|
package com.platform.opc.util;
|
|
|
|
|
|
+import com.platform.common.util.RedisUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jinterop.dcom.common.JIErrorCodes;
|
|
|
import org.jinterop.dcom.common.JIException;
|
|
@@ -11,6 +12,7 @@ import org.openscada.opc.lib.da.*;
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* @Auther: 熊
|
|
@@ -23,34 +25,16 @@ public class OpcDAClient {
|
|
|
public static String user = "Administrator";
|
|
|
public static String password = "Hollysys";
|
|
|
public static String clsId = "001AAAA6-FB54-4627-84B2-8777379E5868";
|
|
|
+ public static String progId = "Hollysys.HOLLiASiComm.1";
|
|
|
public static String tag_prefix = "Channel1.Device1.";
|
|
|
private Server server;
|
|
|
- private String bakHost;
|
|
|
private Group group = null;
|
|
|
private Map<String, Item> groupItems = null;
|
|
|
|
|
|
/**
|
|
|
* 初始化连接信息
|
|
|
- *
|
|
|
- * @param host
|
|
|
- * @param user
|
|
|
- * @param password
|
|
|
- * @param clsId
|
|
|
*/
|
|
|
- public OpcDAClient(String host, String user, String password, String clsId) {
|
|
|
- this.host = host;
|
|
|
- this.user = user;
|
|
|
- this.password = password;
|
|
|
- this.clsId = clsId;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置备用服务地址
|
|
|
- *
|
|
|
- * @param bakHost
|
|
|
- */
|
|
|
- public void setBakHost(String bakHost) {
|
|
|
- this.bakHost = bakHost;
|
|
|
+ public OpcDAClient() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -66,7 +50,8 @@ public class OpcDAClient {
|
|
|
ci.setUser(user);
|
|
|
ci.setPassword(password);
|
|
|
ci.setClsid(clsId);
|
|
|
- server = new Server(ci, null);
|
|
|
+ ci.setProgId(progId);
|
|
|
+ server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
|
|
|
try {
|
|
|
server.connect();
|
|
|
} catch (UnknownHostException e) {
|
|
@@ -77,7 +62,6 @@ public class OpcDAClient {
|
|
|
log.error("opc 连接失败:", e);
|
|
|
log.info("开始连接备用服务...");
|
|
|
try {
|
|
|
- ci.setHost(bakHost);
|
|
|
server = new Server(ci, null);
|
|
|
server.connect();
|
|
|
} catch (Exception e2) {
|
|
@@ -125,7 +109,6 @@ public class OpcDAClient {
|
|
|
groupItems = group.addItems(items);
|
|
|
log.info("组建完成,开始查询数据...");
|
|
|
}
|
|
|
-
|
|
|
Set itemSet = new HashSet(groupItems.values());
|
|
|
Item[] itemArr = new Item[itemSet.size()];
|
|
|
itemSet.toArray(itemArr);
|
|
@@ -229,7 +212,8 @@ public class OpcDAClient {
|
|
|
public static String[] tagList = new String[]{"AT_11001_AV", "AT_11002_AV", "AT_11003_AV", "AT_11004_AV", "AT_11005_AV", "AT_11006_AV", "AT_11007_AV", "AT_11008_AV", "AT_7101A_AV", "AT_7101B_AV", "AT_7101C_AV"};
|
|
|
|
|
|
public static void run() {
|
|
|
- OpcDAClient opcDAClient = new OpcDAClient(OpcDAClient.host, OpcDAClient.user, OpcDAClient.password, OpcDAClient.clsId);
|
|
|
+ // RedisUtils.set("test", 1);
|
|
|
+ OpcDAClient opcDAClient = new OpcDAClient();
|
|
|
opcDAClient.connect();
|
|
|
List<String> itemList = new ArrayList<>();
|
|
|
for (String tag : tagList) {
|