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. 9
      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 {
String message = null;
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();
itemsString.add(item);
}
Map<String, Item> itemsMap = new LinkedHashMap();
// Map<String, Item> 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<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;
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<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));
}
Map<Item, ItemState> 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<Item> 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);
}
ThreadUtl.sleep((long) (5000 + random));
} else if (this.all_null < 6) {
if (log.isWarnEnabled()) {
log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + 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) (30000 + random));
} else if (this.all_null < 12) {
if (log.isWarnEnabled()) {
log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + 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);
}
ThreadUtl.sleep((long) ('\uea60' + random));
} else {
if (log.isWarnEnabled()) {
log.warn("{} 所有内容都为空,暂定{}ms", tag, 120000 + random);
accessor_value.setValue(itemId, value);
}
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) {
}
}

9
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,8 +144,10 @@ public class QueryXZAgvDeviceStatus {
MaGangLedDeviceDriver maGangLedDeviceDriver;
if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) {
maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver();
if (maGangLedDeviceDriver.getD01() != 1) {
maGangLedDeviceDriver.writing("D01", 1);
}
}
} else {
String name = jsonObject.getString("name");
Device device = deviceAppService.findDeviceByCode(name);
@ -156,11 +157,13 @@ public class QueryXZAgvDeviceStatus {
MaGangLedDeviceDriver maGangLedDeviceDriver;
if (device.getDeviceDriver() instanceof MaGangLedDeviceDriver) {
maGangLedDeviceDriver = (MaGangLedDeviceDriver) device.getDeviceDriver();
if (maGangLedDeviceDriver.getD01() != 0) {
maGangLedDeviceDriver.writing("D01", 0);
}
}
}
}
}
} catch (Exception e) {
}

2
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:

Loading…
Cancel
Save