From 6c2ff1c7c8e0aba3af92110b76687b78f8278e86 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 03 一月 2025 09:57:37 +0800
Subject: [PATCH] 动态数据长度

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/collector/KingIOCollector.java |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/collector/KingIOCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/collector/KingIOCollector.java
index 3dd07c6..4ee8b2a 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/collector/KingIOCollector.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/kio/collector/KingIOCollector.java
@@ -1,14 +1,17 @@
 package com.iailab.module.data.channel.kio.collector;
 
+import com.iailab.module.data.channel.kio.entity.ChannelKioDeviceEntity;
+import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService;
+import com.iailab.module.data.channel.opcua.collector.OpcUaUtils;
+import com.iailab.module.data.common.enums.CommonConstant;
 import com.iailab.module.data.common.enums.DataSourceType;
 import com.iailab.module.data.common.utils.TagUtils;
-import com.iailab.module.data.channel.kio.dto.ChannelKioDeviceDTO;
-import com.iailab.module.data.channel.kio.service.ChannelKioDeviceService;
 import lombok.extern.slf4j.Slf4j;
-import javax.annotation.Resource;
+import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -31,15 +34,15 @@
 
     private Map<String, KingIOClient> clientMap = new ConcurrentHashMap<>();
 
-    private Map<String, ChannelKioDeviceDTO> deviceMap = new HashMap<>();
+    private Map<String, ChannelKioDeviceEntity> deviceMap = new HashMap<>();
 
     public synchronized KingIOClient getClient(String sourceId) throws Exception {
         if (!clientMap.containsKey(sourceId)) {
-            ChannelKioDeviceDTO deviceDto = channelKioDeviceService.get(sourceId);
-            deviceMap.put(sourceId, deviceDto);
-            KingIOClient kingIOClient = new KingIOClient(deviceDto.getInstanceName());
+            ChannelKioDeviceEntity deviceEntity = channelKioDeviceService.info(sourceId);
+            deviceMap.put(sourceId, deviceEntity);
+            KingIOClient kingIOClient = new KingIOClient(deviceEntity.getInstanceName());
             clientMap.put(sourceId, kingIOClient);
-            if (!kingIOClient.login(deviceDto.getAddress(), deviceDto.getPort(), deviceDto.getUsername(), deviceDto.getPassword())) {
+            if (!kingIOClient.login(deviceEntity.getAddress(), deviceEntity.getPort(), deviceEntity.getUsername(), deviceEntity.getPassword())) {
                 throw new Exception("登录异常");
             }
         }
@@ -50,9 +53,15 @@
         return kingIOClient;
     }
 
-    public String getTagValue(String sourceId, String tagName) throws Exception {
-        KingIOClient client = this.getClient(sourceId);
-        String value = client.getTagValue(tagName);
+    public String getTagValue(String sourceId, String tagName) {
+        String value = CommonConstant.BAD_VALUE.toString();
+        try{
+            KingIOClient client = this.getClient(sourceId);
+            value = client.getTagValue(tagName);
+        }catch (Exception ex){
+            ex.printStackTrace();
+            return value;
+        }
         return value;
     }
 

--
Gitblit v1.9.3