Browse Source

更新

master
gengby 2 years ago
parent
commit
9f43608f75
  1. 2
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/led/MaGangLedDeviceDriver.java
  2. 129
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java
  3. 7
      acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java
  4. 2
      acs/nladmin-system/src/main/resources/config/application.yml

2
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 { public void execute() throws Exception {
String message = null; String message = null;
device_code = this.getDeviceCode(); device_code = this.getDeviceCode();
//D01 = this.itemProtocol.getD01(); D01 = this.itemProtocol.getD01();
} }

129
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(); String item = protocol.getItem_code();
itemsString.add(item); itemsString.add(item);
} }
// Map<String, Item> itemsMap = new LinkedHashMap();
Map<String, Item> itemsMap = new LinkedHashMap();
boolean is_error = false; boolean is_error = false;
StringBuilder err_message = new StringBuilder(); 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<String, Item> 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; String tag;
if (is_error) { if (is_error) {
tag = err_message.toString(); tag = err_message.toString();
log.warn("{}:{}", OpcConfig.resource_code, tag); log.warn("{}:{}", OpcConfig.resource_code, tag);
} }
if (!OpcStartTag.is_run) { if (!OpcStartTag.is_run) {
OpcStartTag.is_run = true; OpcStartTag.is_run = true;
} }
tag = ""; tag = "";
if (log.isWarnEnabled()) { if (log.isWarnEnabled()) {
tag = Thread.currentThread().getName(); tag = Thread.currentThread().getName();
@ -202,107 +191,67 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
boolean time_out = false; boolean time_out = false;
while (DeviceOpcSynchronizeAutoRun.isRun) { while (DeviceOpcSynchronizeAutoRun.isRun) {
log.info("开始读取组数据.....");
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
if (log.isTraceEnabled()) { Map<Item, ItemState> itemStatus = group.read(true, itemArr);
// log.trace("{} 开始计时{}", tag, DateUtl.formatDateTime(new Date())); long endRead = System.currentTimeMillis();
} log.info("读取组数据完成.....,总共读取:{}条,耗时:{}毫秒", itemStatus.size(), (endRead - begin));
long duration = endRead - begin;
Map<Item, ItemState> 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));
}
if (duration > 1000L) { if (duration > 1000L) {
if (!time_out) { if (!time_out) {
log.warn("{} 读取超时 : {}", tag, duration); log.warn("{} 读取超时 : {}", tag, duration);
} }
time_out = true; time_out = true;
} else { } else {
time_out = false; time_out = false;
} }
boolean valueAllNotNull = false; boolean valueAllNotNull = false;
Set<Item> items = itemStatus.keySet(); for (Item item : itemStatus.keySet()) {
ItemState itemState = itemStatus.get(item);
Iterator var18 = items.iterator();
if (!var18.hasNext()){
log.info("查询到的为空!");
}
while (var18.hasNext()) {
Item item = (Item) var18.next();
ItemState itemState = (ItemState) itemStatus.get(item);
Object value = OpcUtl.getValue(item, itemState); Object value = OpcUtl.getValue(item, itemState);
if (value != null) { if (value == null) {
valueAllNotNull = true; valueAllNotNull = true;
}else { log.info("读取到值为空,设备号:{},健康值:{}", item.getId(), itemState.getQuality());
log.info("查询到的值为空"); break;
} }
String itemId = item.getId(); String itemId = item.getId();
Object his = accessor_value.getValue(itemId); Object his = accessor_value.getValue(itemId);
if (!ObjectUtil.equals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { if (!ObjectUtil.equals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
} }
if (!UnifiedDataAppService.isEquals(value, his)) { if (!UnifiedDataAppService.isEquals(value, his)) {
OpcItemDto itemDto = this.getItem(itemId); OpcItemDto itemDto = this.getItem(itemId);
if (Boolean.TRUE.equals(itemDto.getNeed_log())) { if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
this.logItemChanged(itemId, accessor_value, value, itemDto); this.logItemChanged(itemId, accessor_value, value, itemDto);
} }
accessor_value.setValue(itemId, value); accessor_value.setValue(itemId, value);
} }
} }
end = System.currentTimeMillis(); if (valueAllNotNull) {
if (log.isTraceEnabled()) { ThreadUtl.sleep(3000L);
log.trace("{}", itemsString); log.info("读取组数据不健康,重新读取......");
// log.trace("{} 计算完成耗时{}", tag, DateUtl.formatDuring(end - begin)); itemStatus = group.read(true, itemArr);
} for (Item item : itemStatus.keySet()) {
ItemState itemState = itemStatus.get(item);
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond); Object value = OpcUtl.getValue(item, itemState);
if (this.error_num != 0) { if (value == null){
this.error_num = 0; log.info("再次读取组数据为空,终止读取,设备号:{}",item.getId());
this.message = null; break;
}
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);
}
ThreadUtl.sleep((long) (5000 + random));
} else if (this.all_null < 6) {
if (log.isWarnEnabled()) {
log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + random);
} }
String itemId = item.getId();
ThreadUtl.sleep((long) (30000 + random)); Object his = accessor_value.getValue(itemId);
} else if (this.all_null < 12) { if (!UnifiedDataAppService.isEquals(value, his)) {
if (log.isWarnEnabled()) { OpcItemDto itemDto = this.getItem(itemId);
log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + random); if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
this.logItemChanged(itemId, accessor_value, value, itemDto);
} }
accessor_value.setValue(itemId, value);
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线程停止。。。"); log.warn("opc线程停止。。。");
@ -310,7 +259,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
} catch (Exception var27) { } catch (Exception var27) {
if (this.server != null) { if (this.server != null) {
try { try {
this.server.disconnect(); this.server.dispose();
} catch (Exception var25) { } catch (Exception var25) {
} }
} }

7
acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvDeviceStatus.java

@ -83,7 +83,7 @@ public class QueryXZAgvDeviceStatus {
status = "5"; status = "5";
task_type = "0"; task_type = "0";
} else { } else {
if (procBusiness) { if (procBusiness && !is_error) {
//工作中 //工作中
status = "1"; status = "1";
} else { } else {
@ -95,7 +95,6 @@ public class QueryXZAgvDeviceStatus {
if (is_error) { if (is_error) {
//故障 //故障
status = "3"; status = "3";
task_type = "0";
} else { } else {
//休息中 //休息中
status = "4"; status = "4";
@ -145,8 +144,10 @@ public class QueryXZAgvDeviceStatus {
MaGangLedDeviceDriver maGangLedDeviceDriver; MaGangLedDeviceDriver maGangLedDeviceDriver;
if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) {
maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver();
if (maGangLedDeviceDriver.getD01() != 1) {
maGangLedDeviceDriver.writing("D01", 1); maGangLedDeviceDriver.writing("D01", 1);
} }
}
} else { } else {
String name = jsonObject.getString("name"); String name = jsonObject.getString("name");
Device device = deviceAppService.findDeviceByCode(name); Device device = deviceAppService.findDeviceByCode(name);
@ -156,11 +157,13 @@ public class QueryXZAgvDeviceStatus {
MaGangLedDeviceDriver maGangLedDeviceDriver; MaGangLedDeviceDriver maGangLedDeviceDriver;
if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) { if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) {
maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver(); maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver();
if (maGangLedDeviceDriver.getD01() != 0) {
maGangLedDeviceDriver.writing("D01", 0); maGangLedDeviceDriver.writing("D01", 0);
} }
} }
} }
} }
}
} catch (Exception e) { } catch (Exception e) {
} }

2
acs/nladmin-system/src/main/resources/config/application.yml

@ -2,7 +2,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: dev active: prod
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
data: data:

Loading…
Cancel
Save