代码更新

This commit is contained in:
ludj
2023-02-04 10:50:05 +08:00
parent 71c40a5ec4
commit 72d6f51598
3 changed files with 20 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory; 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.Group;
import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState; import org.openscada.opc.lib.da.ItemState;
@@ -15,18 +16,19 @@ import java.util.*;
@Slf4j @Slf4j
public class DeviceOpcProtocolRunable implements Runnable { public class DeviceOpcProtocolRunable implements Runnable {
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
List<OpcItemDto> protocols; List<OpcItemDto> protocols;
OpcServerManageDto OpcServer; OpcServerManageDto OpcServer;
int error_num; int error_num;
String message; String message;
private Server server;
Group group; Group group;
public DeviceOpcProtocolRunable() { public DeviceOpcProtocolRunable() {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
this.server = null;
} }
public List<OpcItemDto> getProtocols() { public List<OpcItemDto> getProtocols() {
@@ -64,14 +66,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() { public void run() {
while (true) { while (true) {
try { try {
server = group= opcServerService.getServer(this.OpcServer.getOpc_code());
OpcServerUtl.getServerWithOutException(
this.OpcServer.getOpc_host(),
this.OpcServer.getCls_id(),
this.OpcServer.getUser(),
this.OpcServer.getPassword(),
this.OpcServer.getDomain());
group = server.addGroup();
List<String> itemsString = new ArrayList(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@@ -196,14 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
if (this.server != null) {
try {
this.server.disconnect();
} catch (Exception var6) {
}
this.server = null;
}
if (group != null) { if (group != null) {
try { try {
group.clear(); group.clear();
@@ -213,6 +200,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.group = null; this.group = null;
} }
String error_message = "设备信息同步异常"; String error_message = "设备信息同步异常";
if (!StrUtil.equals(this.message, error_message)) { if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30); log.warn("", var30);

View File

@@ -127,7 +127,10 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
public synchronized void clearServer(String code) { public synchronized void clearServer(String code) {
try { try {
Server server = (Server) this.servers.get(code); Server server = (Server) this.servers.get(code);
if (server!=null){
server.disconnect(); server.disconnect();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("清理server异常,",e.getMessage()); log.error("清理server异常,",e.getMessage());

View File

@@ -18,8 +18,10 @@ import java.util.concurrent.Executors;
@Slf4j @Slf4j
public class OpcUtl { public class OpcUtl {
private static int timeout = 180000; private static int timeout = 300000;
private static String key = "rpc.socketTimeout"; private static String key = "rpc.socketTimeout";
private static int successNum=0;
private static int errNum=0;
public static void checkTimeout() { public static void checkTimeout() {
if (Integer.getInteger(key, 0).intValue() != timeout) { if (Integer.getInteger(key, 0).intValue() != timeout) {
@@ -204,9 +206,15 @@ public class OpcUtl {
server = new Server(getConnection(host, clsid, user, password, domain), server = new Server(getConnection(host, clsid, user, password, domain),
Executors.newSingleThreadScheduledExecutor()); Executors.newSingleThreadScheduledExecutor());
server.connect(); server.connect();
successNum++;
return server; return server;
} catch (Exception e) { } 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);
} }
} }