代码更新
This commit is contained in:
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
@@ -15,18 +16,19 @@ import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
public class DeviceOpcProtocolRunable implements Runnable {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
|
||||
List<OpcItemDto> protocols;
|
||||
OpcServerManageDto OpcServer;
|
||||
int error_num;
|
||||
String message;
|
||||
private Server server;
|
||||
|
||||
Group group;
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
public List<OpcItemDto> getProtocols() {
|
||||
@@ -64,14 +66,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
server =
|
||||
OpcServerUtl.getServerWithOutException(
|
||||
this.OpcServer.getOpc_host(),
|
||||
this.OpcServer.getCls_id(),
|
||||
this.OpcServer.getUser(),
|
||||
this.OpcServer.getPassword(),
|
||||
this.OpcServer.getDomain());
|
||||
group = server.addGroup();
|
||||
group= opcServerService.getServer(this.OpcServer.getOpc_code());
|
||||
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator it = this.protocols.iterator();
|
||||
@@ -196,14 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
}
|
||||
}
|
||||
} catch (Exception var30) {
|
||||
if (this.server != null) {
|
||||
try {
|
||||
this.server.disconnect();
|
||||
} catch (Exception var6) {
|
||||
}
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
if (group != null) {
|
||||
try {
|
||||
group.clear();
|
||||
@@ -213,6 +200,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
this.group = null;
|
||||
}
|
||||
|
||||
|
||||
String error_message = "设备信息同步异常";
|
||||
if (!StrUtil.equals(this.message, error_message)) {
|
||||
log.warn("", var30);
|
||||
|
||||
@@ -127,7 +127,10 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
public synchronized void clearServer(String code) {
|
||||
try {
|
||||
Server server = (Server) this.servers.get(code);
|
||||
server.disconnect();
|
||||
if (server!=null){
|
||||
server.disconnect();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("清理server异常,",e.getMessage());
|
||||
|
||||
@@ -18,8 +18,10 @@ import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
public class OpcUtl {
|
||||
private static int timeout = 180000;
|
||||
private static int timeout = 300000;
|
||||
private static String key = "rpc.socketTimeout";
|
||||
private static int successNum=0;
|
||||
private static int errNum=0;
|
||||
|
||||
public static void checkTimeout() {
|
||||
if (Integer.getInteger(key, 0).intValue() != timeout) {
|
||||
@@ -204,9 +206,15 @@ public class OpcUtl {
|
||||
server = new Server(getConnection(host, clsid, user, password, domain),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
server.connect();
|
||||
successNum++;
|
||||
return server;
|
||||
} catch (Exception e) {
|
||||
throw new WDKException(e);
|
||||
errNum++;
|
||||
throw new WDKException(e.getMessage());
|
||||
}finally{
|
||||
System.out.println("successNum:"+successNum);
|
||||
System.out.println("errNum:"+errNum);
|
||||
System.out.println(11);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user