acs代码更新

This commit is contained in:
ludj
2023-02-10 10:16:09 +08:00
parent 837c9d96f3
commit 2d14b4cc64

View File

@@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory; 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.Group;
import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState; import org.openscada.opc.lib.da.ItemState;
@@ -16,16 +15,11 @@ import java.util.*;
@Slf4j @Slf4j
public class DeviceOpcProtocolRunable implements Runnable { public class DeviceOpcProtocolRunable implements Runnable {
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
List<OpcItemDto> protocols; List<OpcItemDto> protocols;
OpcServerManageDto OpcServer; OpcServerManageDto OpcServer;
int error_num; int error_num;
String message; String message;
Group group;
public DeviceOpcProtocolRunable() { public DeviceOpcProtocolRunable() {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
@@ -66,8 +60,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() { public void run() {
while (true) { while (true) {
try { 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(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@@ -97,7 +91,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
if (is_error) { if (is_error) {
log.info("设备OPC数据同步配置异常," + err_message); log.info("设备OPC数据同步配置异常");
} }
if (!OpcStartTag.is_run) { if (!OpcStartTag.is_run) {
@@ -109,30 +103,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
if (this.OpcServer != null) { if (this.OpcServer != null) {
tag = tag + this.OpcServer.getOpc_code(); tag = tag + this.OpcServer.getOpc_code();
} }
UnifiedDataAccessor accessor_value = UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
boolean time_out = false; boolean time_out = false;
label97: label97:
while (true) { while (true) {
// System.out.println("label97");
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
Map<Item, ItemState> itemStatus =null; Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
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可行否?
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
log.trace("{} 开始记时{}", tag, DateUtil.now()); log.trace("{} 开始记时{}", tag, DateUtil.now());
long duration = end - begin; long duration = end - begin;
@@ -147,13 +125,11 @@ public class DeviceOpcProtocolRunable implements Runnable {
time_out = false; time_out = false;
} }
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
Set<Item> items = itemStatus.keySet(); Set<Item> items = itemStatus.keySet();
Iterator var18 = items.iterator(); Iterator var18 = items.iterator();
while (true) { while (true) {
Item item; Item item;
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
//当前值 //当前值
Object value; Object value;
//旧的值 //旧的值
@@ -168,16 +144,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
} }
// 所有信号读完并且没有变化的值
continue label97; continue label97;
} }
item = (Item) var18.next(); item = (Item) var18.next();
ItemState itemState = itemStatus.get(item); ItemState itemState = (ItemState) itemStatus.get(item);
value = OpcUtl.getValue(item, itemState); value = OpcUtl.getValue(item, itemState);
his = accessor_value.getValue(item.getId()); his = accessor_value.getValue(item.getId());
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
&& his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
} }
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
@@ -196,24 +170,14 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb});
} }
//设置值 //设置值
accessor_value.setValue(item.getId(), value); accessor_value.setValue(item.getId(), value);
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
if (group != null) {
try {
group.getServer().dispose();
group.clear();
group.remove();
} catch (Exception var6) {
}
this.group = null;
}
String error_message = "设备信息同步异常"; String error_message = "设备信息同步异常";
if (!StrUtil.equals(this.message, error_message)) { if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30); log.warn("", var30);
@@ -223,6 +187,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Thread.currentThread().interrupt();
} }
++this.error_num; ++this.error_num;
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) { 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 ";
}
} }