设置值日志输出

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() { public void run() {
while (true) { while (true) {
try { 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(); Group group = server.addGroup();
List<String> itemsString = new ArrayList(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@@ -105,14 +110,17 @@ 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 = 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: label97:
while (true) { while (true) {
System.out.println("label97");
long begin = System.currentTimeMillis(); 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(); long end = System.currentTimeMillis();
log.trace("{} 开始记时{}", tag, DateUtil.now()); log.trace("{} 开始记时{}", tag, DateUtil.now());
long duration = end - begin; long duration = end - begin;
@@ -131,6 +139,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
Iterator var18 = items.iterator(); Iterator var18 = items.iterator();
while (true) { while (true) {
System.out.println("label98");
Item item; Item item;
// 当前值 // 当前值
Object value; Object value;
@@ -150,10 +159,11 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
item = (Item) var18.next(); item = (Item) var18.next();
ItemState itemState = (ItemState) itemStatus.get(item); 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) && 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());
} }
} while (ObjectUtil.equal(value, his)); // 如果两次的值相等,不走下面的代码 } while (ObjectUtil.equal(value, his)); // 如果两次的值相等,不走下面的代码
@@ -172,11 +182,10 @@ public class DeviceOpcProtocolRunable implements Runnable {
} }
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); accessor_value.setValue(item.getId(), value);
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
@@ -185,7 +194,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.server.disconnect(); this.server.disconnect();
} catch (Exception var6) { } catch (Exception var6) {
} }
this.server = null; 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 ";
}
} }