|
@@ -12,17 +12,25 @@ import org.jinterop.dcom.core.JIVariant;
|
|
import org.openscada.opc.lib.common.ConnectionInformation;
|
|
import org.openscada.opc.lib.common.ConnectionInformation;
|
|
import org.openscada.opc.lib.common.NotConnectedException;
|
|
import org.openscada.opc.lib.common.NotConnectedException;
|
|
import org.openscada.opc.lib.da.*;
|
|
import org.openscada.opc.lib.da.*;
|
|
|
|
+import org.openscada.opc.lib.da.browser.FlatBrowser;
|
|
import org.openscada.opc.lib.list.Categories;
|
|
import org.openscada.opc.lib.list.Categories;
|
|
import org.openscada.opc.lib.list.Category;
|
|
import org.openscada.opc.lib.list.Category;
|
|
import org.openscada.opc.lib.list.ServerList;
|
|
import org.openscada.opc.lib.list.ServerList;
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
import java.net.UnknownHostException;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
|
+import java.util.List;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
public class OpcUAClientUtil {
|
|
public class OpcUAClientUtil {
|
|
|
|
|
|
|
|
+ public static String OPC_HOST = "192.168.108.108";
|
|
|
|
+ public static String OPC_USER = "Administrator";
|
|
|
|
+ public static String OPC_PASSWORD = "Hollysys";
|
|
|
|
+ public static String OPC_CLSID = "001AAAA6-FB54-4627-84B2-8777379E5868";
|
|
|
|
+
|
|
public static void run() throws Exception {
|
|
public static void run() throws Exception {
|
|
// 连接信息
|
|
// 连接信息
|
|
JISystem.setAutoRegisteration(true);
|
|
JISystem.setAutoRegisteration(true);
|
|
@@ -61,10 +69,7 @@ public class OpcUAClientUtil {
|
|
for (ClassDetails cds : classDetails) {
|
|
for (ClassDetails cds : classDetails) {
|
|
System.out.println(cds.getProgId() + "=" + cds.getDescription());
|
|
System.out.println(cds.getProgId() + "=" + cds.getDescription());
|
|
}
|
|
}
|
|
- Collection<String> items = server.getFlatBrowser().browse();
|
|
|
|
- for (String item : items) {
|
|
|
|
- System.out.println("item=" + item);
|
|
|
|
- }
|
|
|
|
|
|
+ findAllItem(server);
|
|
final String itemId = "Channel1.Device1.AT_11001_AV";
|
|
final String itemId = "Channel1.Device1.AT_11001_AV";
|
|
System.out.println("连接成功");
|
|
System.out.println("连接成功");
|
|
final AccessBase access = new SyncAccess(server, 1000);
|
|
final AccessBase access = new SyncAccess(server, 1000);
|
|
@@ -99,7 +104,37 @@ public class OpcUAClientUtil {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据类型读取数据
|
|
|
|
|
|
+ * 查找所有item
|
|
|
|
+ *
|
|
|
|
+ * @param server
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static List findAllItem(Server server) {
|
|
|
|
+ FlatBrowser flatBrowser = server.getFlatBrowser();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ if (flatBrowser == null) {
|
|
|
|
+ System.out.println("读取 空");
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ Collection<String> collection = flatBrowser.browse();
|
|
|
|
+ for (String item : collection) {
|
|
|
|
+ list.add(item);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("list: " + list.size());
|
|
|
|
+ } catch (JIException e) {
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ } catch (UnknownHostException e) {
|
|
|
|
+ System.out.println("host主机IP错误 = " + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 如果是 bool、string、short、int等直接返回字符串;
|
|
|
|
+ * 如果是 long 类型的数组,返回数字内容间加点,对应 long,数组,大小为6
|
|
|
|
+ * 如果是 float 类型的数组,返回数字内容间加逗号,对应 float,数组,大小为20
|
|
*
|
|
*
|
|
* @param var
|
|
* @param var
|
|
* @return
|
|
* @return
|