更新opc线程

This commit is contained in:
USER-20220102CG\noblelift
2023-03-29 18:30:05 +08:00
parent 4c7d2654b5
commit 462f9f9c9a

View File

@@ -12,6 +12,8 @@ import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Slf4j
public class DeviceOpcProtocolRunable implements Runnable {
@@ -19,6 +21,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
OpcServerManageDto OpcServer;
int error_num;
String message;
int maxResartNum;
private Server server;
public DeviceOpcProtocolRunable() {
@@ -172,8 +175,24 @@ public class DeviceOpcProtocolRunable implements Runnable {
value = OpcUtl.getValue(item, itemState);
his = accessor_value.getValue(item.getId());
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
maxResartNum ++;
log.warn("opc 值不健康 item: {}, 状态: {},当前读取值:{}, 系统内存值{} ", item.getId(), itemState.getQuality(), value, his);
}
if(maxResartNum>1000){
if (this.server != null) {
try {
this.server.disconnect();
} catch (Exception var25) {
log.warn("{} : server disconnect", var25);
}
}
DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable();
runable.setProtocols(protocols);
runable.setOpcServer(OpcServer);
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.submit(runable);
log.warn("opc 值不健康 item: {}, 重新创建连接", item.getId());
}
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
OpcItemDto itemDto = this.getItem(item.getId());