acs代码更新
This commit is contained in:
@@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
@@ -16,16 +15,11 @@ import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
public class DeviceOpcProtocolRunable implements Runnable {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
|
||||
List<OpcItemDto> protocols;
|
||||
OpcServerManageDto OpcServer;
|
||||
int error_num;
|
||||
String message;
|
||||
|
||||
Group group;
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
@@ -66,8 +60,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
group= opcServerService.getServer(this.OpcServer.getOpc_code());
|
||||
|
||||
Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||
Group group = server.addGroup();
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator it = this.protocols.iterator();
|
||||
|
||||
@@ -97,49 +91,33 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
}
|
||||
|
||||
if (is_error) {
|
||||
log.info("设备OPC数据同步配置异常," + err_message);
|
||||
log.info("设备OPC数据同步配置异常");
|
||||
}
|
||||
|
||||
if (!OpcStartTag.is_run) {
|
||||
OpcStartTag.is_run = true;
|
||||
}
|
||||
|
||||
// 线程名
|
||||
//线程名
|
||||
String tag = Thread.currentThread().getName();
|
||||
if (this.OpcServer != null) {
|
||||
tag = tag + this.OpcServer.getOpc_code();
|
||||
}
|
||||
UnifiedDataAccessor accessor_value =
|
||||
UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
|
||||
boolean time_out = false;
|
||||
|
||||
label97:
|
||||
while (true) {
|
||||
// System.out.println("label97");
|
||||
long begin = System.currentTimeMillis();
|
||||
Map<Item, ItemState> itemStatus =null;
|
||||
|
||||
try{
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}catch (Exception e){
|
||||
try{
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}catch (Exception e2){
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO 读完释放server可行否?
|
||||
|
||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
long end = System.currentTimeMillis();
|
||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
long duration = end - begin;
|
||||
log.trace("{} 读取耗时:{}", tag, duration);
|
||||
if (duration > 1000L) {
|
||||
if (!time_out) {
|
||||
log.warn(" {} 读取超时 : {} ", tag, duration);
|
||||
log.warn("{} 读取超时 : {}", tag, duration);
|
||||
}
|
||||
|
||||
time_out = true;
|
||||
@@ -147,16 +125,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
time_out = false;
|
||||
}
|
||||
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (true) {
|
||||
Item item;
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
|
||||
// 当前值
|
||||
//当前值
|
||||
Object value;
|
||||
// 旧的值
|
||||
//旧的值
|
||||
Object his;
|
||||
do {
|
||||
if (!var18.hasNext()) {
|
||||
@@ -168,24 +144,22 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
}
|
||||
// 所有信号读完并且没有变化的值
|
||||
continue label97;
|
||||
}
|
||||
|
||||
item = (Item) var18.next();
|
||||
ItemState itemState = itemStatus.get(item);
|
||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||
value = OpcUtl.getValue(item, itemState);
|
||||
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());
|
||||
}
|
||||
} while (ObjectUtil.equal(value, his)); // 如果两次的值相等,不走下面的代码
|
||||
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
|
||||
|
||||
OpcItemDto itemDto = this.getItem(item.getId());
|
||||
if (itemDto.getNeed_log() != null && itemDto.getNeed_log()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 设备的ITEM项
|
||||
//设备的ITEM项
|
||||
List<String> relate_items = itemDto.getRelate_items();
|
||||
Iterator var26 = relate_items.iterator();
|
||||
|
||||
@@ -195,25 +169,15 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
sb.append("key:" + relate + "value:" + obj + ";");
|
||||
}
|
||||
|
||||
log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb});
|
||||
log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb});
|
||||
|
||||
}
|
||||
// 设置值
|
||||
//设置值
|
||||
accessor_value.setValue(item.getId(), value);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception var30) {
|
||||
|
||||
if (group != null) {
|
||||
try {
|
||||
group.getServer().dispose();
|
||||
group.clear();
|
||||
group.remove();
|
||||
} catch (Exception var6) {
|
||||
}
|
||||
this.group = null;
|
||||
}
|
||||
|
||||
|
||||
String error_message = "设备信息同步异常";
|
||||
if (!StrUtil.equals(this.message, error_message)) {
|
||||
log.warn("", var30);
|
||||
@@ -223,6 +187,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
++this.error_num;
|
||||
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||
@@ -232,4 +197,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDuring(long mss) {
|
||||
long days = mss / 86400000L;
|
||||
long hours = mss % 86400000L / 3600000L;
|
||||
long minutes = mss % 3600000L / 60000L;
|
||||
long seconds = mss % 60000L / 1000L;
|
||||
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user