|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.judong.chuanyiserver.config.KepOpcServerPoolFactory;
|
|
|
import com.judong.chuanyiserver.entity.ChannelSetting;
|
|
|
import com.judong.chuanyiserver.entity.DataSource;
|
|
|
-import com.judong.chuanyiserver.entity.RawData;
|
|
|
import com.judong.chuanyiserver.entity.ServerInformation;
|
|
|
import com.judong.chuanyiserver.enums.ConnectModeEnum;
|
|
|
import com.judong.chuanyiserver.enums.ResultEnum;
|
|
@@ -15,7 +14,10 @@ import org.jinterop.dcom.common.JIException;
|
|
|
import org.jinterop.dcom.core.JIVariant;
|
|
|
import org.openscada.opc.dcom.da.OPCSERVERSTATE;
|
|
|
import org.openscada.opc.lib.common.ConnectionInformation;
|
|
|
-import org.openscada.opc.lib.da.*;
|
|
|
+import org.openscada.opc.lib.da.Group;
|
|
|
+import org.openscada.opc.lib.da.Item;
|
|
|
+import org.openscada.opc.lib.da.ItemState;
|
|
|
+import org.openscada.opc.lib.da.Server;
|
|
|
import org.openscada.opc.lib.da.browser.Branch;
|
|
|
import org.openscada.opc.lib.da.browser.Leaf;
|
|
|
import org.openscada.opc.lib.da.browser.TreeBrowser;
|
|
@@ -23,7 +25,6 @@ import org.openscada.opc.lib.da.browser.TreeBrowser;
|
|
|
import java.net.UnknownHostException;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Executors;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* KepOpcServer协议工具类
|
|
@@ -166,8 +167,8 @@ public class KepOpcServerUtil {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static Result opcReadItemTree(DataSource dataSource) {
|
|
|
+ Server server = KepOpcServerUtil.createServer(dataSource);
|
|
|
try {
|
|
|
- Server server = KepOpcServerUtil.createServer(dataSource);
|
|
|
server.connect();
|
|
|
if (null == server.getServerState()) {
|
|
|
throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
|
|
@@ -178,6 +179,8 @@ public class KepOpcServerUtil {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
|
|
|
+ } finally {
|
|
|
+ server.dispose();
|
|
|
}
|
|
|
throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
|
|
|
}
|
|
@@ -279,6 +282,8 @@ public class KepOpcServerUtil {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ server.dispose();
|
|
|
}
|
|
|
return null;
|
|
|
}
|