From 9f43608f758609cb9c14790d036400cf7f5c0ac7 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Thu, 9 Feb 2023 11:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../led/MaGangLedDeviceDriver.java | 2 +- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 131 ++++++------------ .../quartz/task/QueryXZAgvDeviceStatus.java | 13 +- .../src/main/resources/config/application.yml | 2 +- 4 files changed, 50 insertions(+), 98 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/led/MaGangLedDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/led/MaGangLedDeviceDriver.java index 1e5f593..07b0ae1 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/led/MaGangLedDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/led/MaGangLedDeviceDriver.java @@ -87,7 +87,7 @@ public class MaGangLedDeviceDriver extends AbstractOpcDeviceDriver implements De public void execute() throws Exception { String message = null; device_code = this.getDeviceCode(); - //D01 = this.itemProtocol.getD01(); + D01 = this.itemProtocol.getD01(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index d3b12ec..e9d34de 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -159,37 +159,26 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC String item = protocol.getItem_code(); itemsString.add(item); } - - Map itemsMap = new LinkedHashMap(); + // Map itemsMap = new LinkedHashMap(); boolean is_error = false; StringBuilder err_message = new StringBuilder(); - Iterator var6 = itemsString.iterator(); - - while (var6.hasNext()) { - String string = (String) var6.next(); - - try { - Item item = group.addItem(string); - itemsMap.put(string, item); - log.trace("添加成功 {}", string); - } catch (Exception var26) { - err_message.append(string + ":" + var26.getMessage()); - if (!is_error) { - is_error = true; - } - } - } + log.info("开始添加组数据....."); + long start = System.currentTimeMillis(); + Map itemMap = group.addItems(itemsString.toArray(new String[itemsString.size()])); + Set itemSet = new HashSet(itemMap.values()); + Item[] itemArr = new Item[itemSet.size()]; + itemSet.toArray(itemArr); + long end = System.currentTimeMillis(); + log.info("组数据添加完成.....{},耗时:{}毫秒", itemSet, (end - start)); String tag; if (is_error) { tag = err_message.toString(); log.warn("{}:{}", OpcConfig.resource_code, tag); } - if (!OpcStartTag.is_run) { OpcStartTag.is_run = true; } - tag = ""; if (log.isWarnEnabled()) { tag = Thread.currentThread().getName(); @@ -202,107 +191,67 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC boolean time_out = false; while (DeviceOpcSynchronizeAutoRun.isRun) { + log.info("开始读取组数据....."); long begin = System.currentTimeMillis(); - if (log.isTraceEnabled()) { -// log.trace("{} 开始计时{}", tag, DateUtl.formatDateTime(new Date())); - } - - Map itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); - long end = System.currentTimeMillis(); - long duration = end - begin; - if (log.isTraceEnabled()) { -// log.trace("{} 读取耗时:{}", tag, DateUtl.formatDuring(duration)); - } - + Map itemStatus = group.read(true, itemArr); + long endRead = System.currentTimeMillis(); + log.info("读取组数据完成.....,总共读取:{}条,耗时:{}毫秒", itemStatus.size(), (endRead - begin)); + long duration = endRead - begin; if (duration > 1000L) { if (!time_out) { log.warn("{} 读取超时 : {}", tag, duration); } - time_out = true; } else { time_out = false; } - boolean valueAllNotNull = false; - Set items = itemStatus.keySet(); - - Iterator var18 = items.iterator(); - if (!var18.hasNext()){ - log.info("查询到的为空!"); - } - - while (var18.hasNext()) { - Item item = (Item) var18.next(); - ItemState itemState = (ItemState) itemStatus.get(item); + for (Item item : itemStatus.keySet()) { + ItemState itemState = itemStatus.get(item); Object value = OpcUtl.getValue(item, itemState); - if (value != null) { + if (value == null) { valueAllNotNull = true; - }else { - log.info("查询到的值为空"); + log.info("读取到值为空,设备号:{},健康值:{}", item.getId(), itemState.getQuality()); + break; } - String itemId = item.getId(); Object his = accessor_value.getValue(itemId); if (!ObjectUtil.equals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); } - if (!UnifiedDataAppService.isEquals(value, his)) { OpcItemDto itemDto = this.getItem(itemId); if (Boolean.TRUE.equals(itemDto.getNeed_log())) { this.logItemChanged(itemId, accessor_value, value, itemDto); } - accessor_value.setValue(itemId, value); } } - end = System.currentTimeMillis(); - if (log.isTraceEnabled()) { - log.trace("{}", itemsString); -// log.trace("{} 计算完成耗时{}", tag, DateUtl.formatDuring(end - begin)); - } - - ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond); - if (this.error_num != 0) { - this.error_num = 0; - this.message = null; - } - - if (!valueAllNotNull) { - int random = (new Random()).nextInt(10) + 1; - random *= 1000; - if (this.all_null < 3) { - if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空,暂定{}s", tag, 5000 + random); + if (valueAllNotNull) { + ThreadUtl.sleep(3000L); + log.info("读取组数据不健康,重新读取......"); + itemStatus = group.read(true, itemArr); + for (Item item : itemStatus.keySet()) { + ItemState itemState = itemStatus.get(item); + Object value = OpcUtl.getValue(item, itemState); + if (value == null){ + log.info("再次读取组数据为空,终止读取,设备号:{}",item.getId()); + break; } - - ThreadUtl.sleep((long) (5000 + random)); - } else if (this.all_null < 6) { - if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + random); + String itemId = item.getId(); + Object his = accessor_value.getValue(itemId); + if (!UnifiedDataAppService.isEquals(value, his)) { + OpcItemDto itemDto = this.getItem(itemId); + if (Boolean.TRUE.equals(itemDto.getNeed_log())) { + this.logItemChanged(itemId, accessor_value, value, itemDto); + } + accessor_value.setValue(itemId, value); } - - ThreadUtl.sleep((long) (30000 + random)); - } else if (this.all_null < 12) { - if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + random); - } - - ThreadUtl.sleep((long) ('\uea60' + random)); - } else { - if (log.isWarnEnabled()) { - log.warn("{} 所有内容都为空,暂定{}ms", tag, 120000 + random); - } - - ThreadUtl.sleep((long) (120000 + random)); } - - ++this.all_null; - } else { - this.all_null = 0; } + end = System.currentTimeMillis(); + ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond); } log.warn("opc线程停止。。。"); @@ -310,7 +259,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC } catch (Exception var27) { if (this.server != null) { try { - this.server.disconnect(); + this.server.dispose(); } catch (Exception var25) { } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java index 627cbae..098e3c8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java @@ -45,7 +45,7 @@ public class QueryXZAgvDeviceStatus { JSONArray ja = body.getJSONArray("report"); for (int i = 0; i < ja.size(); i++) { System.out.println(ja.getJSONObject(1)); - if (i == 1){ + if (i == 1) { System.out.println(i); } System.out.println("此刻i=" + i); @@ -83,7 +83,7 @@ public class QueryXZAgvDeviceStatus { status = "5"; task_type = "0"; } else { - if (procBusiness) { + if (procBusiness && !is_error) { //工作中 status = "1"; } else { @@ -95,7 +95,6 @@ public class QueryXZAgvDeviceStatus { if (is_error) { //故障 status = "3"; - task_type = "0"; } else { //休息中 status = "4"; @@ -145,7 +144,9 @@ public class QueryXZAgvDeviceStatus { MaGangLedDeviceDriver maGangLedDeviceDriver; if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); - maGangLedDeviceDriver.writing("D01", 1); + if (maGangLedDeviceDriver.getD01() != 1) { + maGangLedDeviceDriver.writing("D01", 1); + } } } else { String name = jsonObject.getString("name"); @@ -156,7 +157,9 @@ public class QueryXZAgvDeviceStatus { MaGangLedDeviceDriver maGangLedDeviceDriver; if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); - maGangLedDeviceDriver.writing("D01", 0); + if (maGangLedDeviceDriver.getD01() != 0) { + maGangLedDeviceDriver.writing("D01", 0); + } } } } diff --git a/acs/nladmin-system/src/main/resources/config/application.yml b/acs/nladmin-system/src/main/resources/config/application.yml index 7e3fbea..a4d00ab 100644 --- a/acs/nladmin-system/src/main/resources/config/application.yml +++ b/acs/nladmin-system/src/main/resources/config/application.yml @@ -2,7 +2,7 @@ spring: freemarker: check-template-location: false profiles: - active: dev + active: prod jackson: time-zone: GMT+8 data: