信号同步更新最新方法

This commit is contained in:
psh
2023-11-10 16:10:43 +08:00
parent 131ce3272a
commit abea8dfd01

View File

@@ -3,22 +3,17 @@ package org.nl.acs.opc;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.method.SpringCacheContext;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.opc.service.dto.OpcServerManageDto;
import org.nl.acs.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory;
import org.nl.acs.udw.UnifiedDataAppService;
import org.nl.config.SpringContextHolder;
import org.openscada.opc.lib.da.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Slf4j
@Service
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
List<OpcItemDto> protocols;
OpcServerManageDto OpcServer;
@@ -31,9 +26,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
private int all_null;
private Map<String, OpcItemDto> itemSearchCache;
// @Autowired
// OpcServerService opcServerService;
public DeviceOpcProtocolRunable() {
this.error_num = 0;
@@ -102,11 +94,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
server.disconnect();
log.trace("清理server...");
}
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
group =opcServerService.getServer(this.getOpcServer().getOpc_code());
// this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
// this.server.addStateListener(this);
// group = this.server.addGroup();
// group =opcServerService.getServer(this.getOpcServer().getOpc_code());
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
this.server.addStateListener(this);
group = this.server.addGroup();
List<String> itemsString = new ArrayList();
Iterator var3 = this.protocols.iterator();
@@ -196,7 +188,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
Object his = accessor_value.getValue(itemId);
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
valueAllNotNull = true;
valueAllNotNull = false;
}
if (!UnifiedDataAppService.isEquals(value, his)) {
@@ -230,7 +222,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random);
}
ThreadUtl.sleep((long) (5000 + random));
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000);
break start;
} else if (this.all_null < 6) {
if (log.isWarnEnabled()) {
log.warn(tag + "重新创建server");