设置值日志输出

This commit is contained in:
ludj
2023-02-01 19:22:10 +08:00
parent 2c6602c528
commit 59cfb37148

View File

@@ -62,7 +62,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() {
while (true) {
try {
server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
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();
@@ -100,19 +105,22 @@ public class DeviceOpcProtocolRunable implements Runnable {
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 = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
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;
@@ -131,10 +139,11 @@ public class DeviceOpcProtocolRunable implements Runnable {
Iterator var18 = items.iterator();
while (true) {
System.out.println("label98");
Item item;
//当前值
// 当前值
Object value;
//旧的值
// 旧的值
Object his;
do {
if (!var18.hasNext()) {
@@ -150,18 +159,19 @@ public class DeviceOpcProtocolRunable implements Runnable {
}
item = (Item) var18.next();
ItemState itemState = (ItemState) itemStatus.get(item);
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();
@@ -171,12 +181,11 @@ 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});
}
//设置值
System.out.println("设置值:【"+item.getId()+"】-->"+value);
// 设置值
accessor_value.setValue(item.getId(), value);
}
}
} catch (Exception var30) {
@@ -185,7 +194,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.server.disconnect();
} catch (Exception var6) {
}
this.server = null;
}
@@ -208,11 +216,4 @@ 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 ";
}
}