From d8156c25a0af7841a91a6fe6ea5d114680672245 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期一, 11 九月 2023 09:51:13 +0800
Subject: [PATCH] 修改遗漏错误

---
 springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java |    1 
 springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java        |   19 +++++----
 springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java         |   21 ++++++----
 springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java        |    6 +++
 springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java         |    3 +
 springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java         |   19 +++------
 6 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
index f4daa38..f007033 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java
@@ -6,7 +6,9 @@
 import javax.websocket.Session;
 
 import com.example.springboot.controller.SpianController;
+import com.example.springboot.service.SpianService;
 import com.example.springboot.mapper.AlarmMapper;
+import com.example.springboot.mapper.HomeMapper;
 
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
@@ -15,8 +17,11 @@
 
   private AlarmMapper alarmMapper;
 
+  private SpianService spianService;
+
   @Override
   public void run() {
+    
     while (this != null) {
       try {
 
@@ -44,20 +49,20 @@
       if(exist=true){
         //褰撹繘鐗囪溅绌洪棽鏃�
         if(exist=true){
-        List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13);
+        //List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13);
+        List<Short> datas1ListID=new ArrayList<>();
+        datas1ListID.add((short)001);
+        spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
         //鑾峰彇鐜荤拑id
-        for(Short list1:datas1ListID)
-        spianController.selectAll(list1);
+        for(Short list1:datas1ListID){
+         spianService.selectAll(list1);
         }
         //System.out.println(exist);
-
       }
+    }
             //鑾峰彇杩涚墖id
             // List<Short> datas1ListID=S7control.getinstance().ReadWord("DB106.26", 13);
-            
-            
-            
-        
+
       
       // 鏌ヨ鏁版嵁搴�
       // 鎺ㄩ�佸埌鍓嶇
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
index 01d9ef1..91b1802 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
@@ -21,6 +21,11 @@
 
       List<Boolean> plclist = S7control.getinstance().ReadBits("DB104.DBx0.0", 40);
 
+      if(plclist==null){
+
+      }else{
+
+      
       JSONObject jsonObject = new JSONObject();
 
       jsonObject.append("params", plclist);
@@ -88,5 +93,6 @@
         }
       }
     }
+    }
   }
 }
\ No newline at end of file
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
index 4ba4874..026cace 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
@@ -49,26 +49,19 @@
             jsonObject.append("alarmmg", alarmmg);
             //璇诲幓Plc杩涚墖杞︿笌鍑虹墖杞︿綅缃甒
             List<String> addressList = new ArrayList<String>();
-            addressList.add("DB100.DBW0");
-            addressList.add("DB100.DBW12");
+            addressList.add("DB105.DBW0");
+            addressList.add("DB105.DBW12");
             List<Short> paramlist = S7control.getinstance().ReadWord(addressList);
             //灏嗛泦鍚堣浆涓烘暟缁�
-            Short[] paramlists = paramlist.toArray(new Short[0]);
-            jsonObject.append("params", paramlists);
+            if(paramlist!=null){
+                Short[] paramlists = paramlist.toArray(new Short[0]);
+                jsonObject.append("params", paramlists);
+            }
             // jsonObject.append("params", new short[] { 30, 40, });
             WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Home");
-
             if (sendwServer != null) {
                 sendwServer.sendMessage(jsonObject.toString());
             }
-
-            // JSONObject jsonObject = new JSONObject();
-            // jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
-            // 11, });
-            // WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Home");
-            // if (sendwServer != null) {
-            // sendwServer.sendMessage(jsonObject.toString());
-            // }
 
         }
     }
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java
index b641602..4fd48c7 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plcsign.java
@@ -16,7 +16,9 @@
       }
 
       List<Boolean> plclist = S7control.getinstance().ReadBits("DB102.DBX0.0", 58);
+      if(plclist==null){
 
+      }else{
       JSONObject jsonObject = new JSONObject();
       // jsonObject3.append("sig",
       // new short[] { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -30,5 +32,6 @@
       }
 
     }
+    }
   }
 }
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java b/springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java
index b3556f7..478a339 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java
@@ -16,16 +16,19 @@
       }
 
       List<Short> plclist = S7control.getinstance().ReadWord("DB103.DBW0", 10);
+      if (plclist == null) {
 
-      JSONObject jsonObject = new JSONObject();
-      // jsonObject.append("sta",
-      // new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
-      jsonObject.append("sta", plclist);
-      WebSocketServer sendwServer = WebSocketServer.sessionMap.get("State");
-      if (sendwServer != null) {
-        sendwServer.sendMessage(jsonObject.toString());
+      } else {
+        JSONObject jsonObject = new JSONObject();
+        // jsonObject.append("sta",
+        // new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
+        jsonObject.append("sta", plclist);
+        WebSocketServer sendwServer = WebSocketServer.sessionMap.get("State");
+        if (sendwServer != null) {
+          sendwServer.sendMessage(jsonObject.toString());
+        }
+
       }
-
     }
   }
 }
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
index 8749b5e..ebdc697 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
@@ -5,7 +5,6 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.catalina.core.ApplicationContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

--
Gitblit v1.8.0