hjp 4 bulan lalu
induk
melakukan
5e66bffc22
1 mengubah file dengan 9 tambahan dan 9 penghapusan
  1. 9 9
      src/main/java/com/jg/service/impl/ModBusServiceImpl.java

+ 9 - 9
src/main/java/com/jg/service/impl/ModBusServiceImpl.java

@@ -34,6 +34,8 @@ import java.util.*;
 public class ModBusServiceImpl implements ModBusService {
 
     private static final Map<Long, ModbusMaster> MASTER_MAP = new HashMap<>(64);
+    private static JSONArray array = new JSONArray();
+    private String show;
 
     @Value("${modbus.host}")
     private String host;
@@ -70,19 +72,16 @@ public class ModBusServiceImpl implements ModBusService {
 //        log.warn("[开始连接采集模块]: {}", JSON.toJSONString(collectModuleInfoList));
         ModbusMaster master = ModBusUtil.createMaster(host, port);
         MASTER_MAP.put(1l, master);
-    }
-
-    @Scheduled(fixedRate = 1000)
-    private void readTagsValue(){
-//        ArrayList<ShowVo> showVos = new ArrayList<>();
-        JSONArray array = new JSONArray();
-        String s = "";
         try {
-            s = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("tag.json").toURI())), StandardCharsets.UTF_8);
+            show = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("tag.json").toURI())), StandardCharsets.UTF_8);
         } catch (Exception e) {
             e.printStackTrace();
         }
-        List<TagVo> tagVos = JSON.parseArray(s, TagVo.class);
+    }
+
+    @Scheduled(fixedRate = 1000)
+    private void readTagsValue(){
+        List<TagVo> tagVos = JSON.parseArray(show, TagVo.class);
         BatchRead<String> batch = new BatchRead<>();
         for (TagVo tagVo: tagVos){
             Integer slaveId = tagVo.getSlaveId();
@@ -126,6 +125,7 @@ public class ModBusServiceImpl implements ModBusService {
 //                showVos.add(showVo);
                 array.add(showVo);
             }
+//            log.info(array.toString());
             webSocketServer.sendInfo(array.toString(), "push");
             modbusMaster.destroy();
         } catch (Exception e) {