From 462f9f9c9ac5aa6585a0a5cbac5da402672d4f56 Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Wed, 29 Mar 2023 18:30:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0opc=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index a36059d..6bb4ed4 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -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());