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