OPC线程同步
This commit is contained in:
@@ -18,10 +18,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
List<OpcItemDto> protocols;
|
List<OpcItemDto> protocols;
|
||||||
OpcServerManageDto OpcServer;
|
OpcServerManageDto OpcServer;
|
||||||
int error_num;
|
int error_num;
|
||||||
|
int all_null;
|
||||||
String message;
|
String message;
|
||||||
|
|
||||||
public DeviceOpcProtocolRunable() {
|
public DeviceOpcProtocolRunable() {
|
||||||
this.error_num = 0;
|
this.error_num = 0;
|
||||||
|
this.all_null = 0;
|
||||||
this.message = null;
|
this.message = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +127,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
} else {
|
} else {
|
||||||
time_out = false;
|
time_out = false;
|
||||||
}
|
}
|
||||||
|
boolean valueAllNotNull = false;
|
||||||
Set<Item> items = itemStatus.keySet();
|
Set<Item> items = itemStatus.keySet();
|
||||||
Iterator var18 = items.iterator();
|
Iterator var18 = items.iterator();
|
||||||
|
|
||||||
@@ -145,12 +147,38 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
this.error_num = 0;
|
this.error_num = 0;
|
||||||
this.message = null;
|
this.message = null;
|
||||||
}
|
}
|
||||||
|
if (!valueAllNotNull) {
|
||||||
|
int random = (new Random()).nextInt(10) + 1;
|
||||||
|
random *= 1000;
|
||||||
|
if (this.all_null < 3) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 5000 + random);
|
||||||
|
ThreadUtl.sleep((long)(5000 + random));
|
||||||
|
} else if (this.all_null < 6) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + random);
|
||||||
|
ThreadUtl.sleep((long)(30000 + random));
|
||||||
|
} else if (this.all_null < 12) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + random);
|
||||||
|
ThreadUtl.sleep((long)('\uea60' + random));
|
||||||
|
} else {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, 120000 + random);
|
||||||
|
ThreadUtl.sleep((long)(120000 + random));
|
||||||
|
}
|
||||||
|
|
||||||
|
++this.all_null;
|
||||||
|
} else {
|
||||||
|
this.all_null = 0;
|
||||||
|
}
|
||||||
continue label97;
|
continue label97;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = (Item) var18.next();
|
item = (Item) var18.next();
|
||||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||||
value = OpcUtl.getValue(item, itemState);
|
value = OpcUtl.getValue(item, itemState);
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
valueAllNotNull = true;
|
||||||
|
}
|
||||||
|
|
||||||
his = accessor_value.getValue(item.getId());
|
his = accessor_value.getValue(item.getId());
|
||||||
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
||||||
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
|
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
|
||||||
@@ -178,6 +206,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("opc线程停止。。。");
|
||||||
|
return;
|
||||||
} catch (Exception var30) {
|
} catch (Exception var30) {
|
||||||
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
||||||
System.out.println("opc线程停止2。。。");
|
System.out.println("opc线程停止2。。。");
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ldjun
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023年01月06日 11:23
|
||||||
|
* @desc desc
|
||||||
|
*/
|
||||||
|
public class ThreadUtl {
|
||||||
|
private ThreadUtl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sleep(long times) throws RuntimeException {
|
||||||
|
try {
|
||||||
|
Thread.sleep(times);
|
||||||
|
} catch (InterruptedException var3) {
|
||||||
|
throw new RuntimeException(var3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user