|
|
@ -54,12 +54,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
this.OpcServer = opcServer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private OpcItemDto getItem(String item) { |
|
|
|
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item); |
|
|
|
if (x == null) { |
|
|
|
Iterator var3 = this.protocols.iterator(); |
|
|
|
|
|
|
|
while (var3.hasNext()) { |
|
|
|
OpcItemDto dto = (OpcItemDto) var3.next(); |
|
|
|
if (StrUtil.equals(item, dto.getItem_code())) { |
|
|
@ -69,11 +67,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return x; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
if (OpcConfig.opc_item_read_using_callback) { |
|
|
@ -83,7 +79,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void runOld() { |
|
|
|
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class); |
|
|
|
while (true) { |
|
|
@ -142,6 +137,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
OpcStartTag.is_run = true; |
|
|
|
} |
|
|
|
|
|
|
|
//线程名
|
|
|
|
tag = ""; |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
tag = Thread.currentThread().getName(); |
|
|
@ -149,10 +145,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
tag = tag + this.getOpcGroupID(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key); |
|
|
|
boolean time_out = false; |
|
|
|
|
|
|
|
label97: |
|
|
|
while (DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
|
long begin = System.currentTimeMillis(); |
|
|
|
if (log.isTraceEnabled()) { |
|
|
@ -165,7 +161,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
if (log.isTraceEnabled()) { |
|
|
|
log.trace("{} 读取耗时:{}", tag, duration); |
|
|
|
} |
|
|
|
|
|
|
|
if (duration > 1000L) { |
|
|
|
if (!time_out) { |
|
|
|
log.warn("{} 读取超时 : {}", tag, duration); |
|
|
@ -192,10 +187,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
Object his = accessor_value.getValue(itemId); |
|
|
|
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { |
|
|
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); |
|
|
|
// valueAllNotNull = false;
|
|
|
|
|
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
|
break start; |
|
|
|
} |
|
|
|
|
|
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
|
@ -203,9 +194,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
if (true) { |
|
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
|
} |
|
|
|
if(!ObjectUtil.isEmpty(value)){ |
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
} |
|
|
|
|
|
|
|
accessor_value.setValue(itemId, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -226,17 +216,17 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
random *= 1000; |
|
|
|
if (this.all_null < 3) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 5000 + random); |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (5000 + random)); |
|
|
|
} else if (this.all_null < 6) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
|
log.warn(tag + "重新创建server"); |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random); |
|
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 30000 + random); |
|
|
|
} |
|
|
|
// ThreadUtl.sleep((long) (30000 + random));
|
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); |
|
|
|
break start; |
|
|
|
} else if (this.all_null < 12) { |
|
|
|
if (log.isWarnEnabled()) { |
|
|
@ -250,8 +240,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
} |
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (120000 + random)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
++this.all_null; |
|
|
|
} else { |
|
|
|
this.all_null = 0; |
|
|
@ -267,9 +257,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
try { |
|
|
|
this.server.disconnect(); |
|
|
|
} catch (Exception var25) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.server = null; |
|
|
|
if (!DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
|
log.warn("opc线程停止2。。。"); |
|
|
@ -356,7 +346,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void connectionStateChanged(boolean connected) { |
|
|
|
if (!connected) { |
|
|
|
this.server = null; |
|
|
@ -377,8 +366,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
long seconds = mss % 60000L / 1000L; |
|
|
|
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds "; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void changed(Item item, ItemState itemState) { |
|
|
|
String itemId = item.getId(); |
|
|
|
|
|
|
@ -420,30 +407,23 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
|
Object obj = accessor_value.getValue(relate); |
|
|
|
sb.append("key:" + relate + "value:" + obj + ";"); |
|
|
|
} |
|
|
|
//log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
|
|
|
|
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { |
|
|
|
if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){ |
|
|
|
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb);
|
|
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
|
} |
|
|
|
} |
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); |
|
|
|
// 存在上次点位值为null情况 则不记录日志
|
|
|
|
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ |
|
|
|
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
|
|
|
|
} else { |
|
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
//log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
|
|
|
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { |
|
|
|
// 存在上次点位值为null情况 则不记录日志
|
|
|
|
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ |
|
|
|
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
System.out.println("his:"+his + ",value:"+ value); |
|
|
|
} else { |
|
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
|
} |
|
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); |
|
|
|
// 存在上次点位值为null情况 则不记录日志
|
|
|
|
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ |
|
|
|
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
|
|
|
|
// if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){
|
|
|
|
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb);
|
|
|
|
// lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
// }
|
|
|
|
} else { |
|
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|