From 733aaaac3ed6a41b78f74c0bcb4d5de7725d788c Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期一, 15 一月 2024 16:32:02 +0800
Subject: [PATCH] 更新已有未完成任务提示

---
 springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java |   79 +++++++++------------------------------
 1 files changed, 19 insertions(+), 60 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java b/springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java
index 6c3299a..e62345d 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/PlcPositioning1.java
@@ -17,54 +17,17 @@
 import org.apache.commons.io.FileUtils;
 
 public class PlcPositioning1 extends Thread {
-    String name = "";
-    Integer count = 0;
 
-    public static String readFileToString(String filePath) throws IOException {
-        File file = new File(filePath);
-        return FileUtils.readFileToString(file, "UTF-8");
+    // 鐢ㄤ簬瀛樺偍搴旂敤绋嬪簭鐨勯厤缃俊鎭�
+    private Configuration config;
+
+    // 鍒涘缓涓�涓嚜瀹氫箟鐨� S7 鎺у埗鍣ㄦ秷鎭鐞嗗櫒瀵硅薄
+    MessageHandler customS7Control = new MessageHandler();
+
+
+    public PlcPositioning1() throws IOException {
+        config = new Configuration("config.properties");
     }
-
-    public void readValue() {
-        String str = "";
-        BufferedReader bufferedReader = null;
-        FileInputStream fileInputStream;
-        try {
-            // 浠庢枃浠朵腑璇诲彇瀛楄妭鏁版嵁瀛樺叆 fileInputStream
-            fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/address.json");
-            // 璇诲彇 fileInputStream 涓瓧鑺傚苟灏嗗叾瑙g爜涓哄瓧绗�
-            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
-            // 鎻愰珮璇诲彇鏁堢巼锛屽湪 BufferedReader 鍐呭寘瑁� InputStreamReader
-            bufferedReader = new BufferedReader(inputStreamReader);
-            String line = null;
-            // 灏� bufferedReader 鍐呭涓�琛屼竴琛岃祴鍊肩粰str
-            while ((line = bufferedReader.readLine()) != null) {
-                str += line;
-            }
-
-            // 灏唖tr瀛楃涓叉牸寮忚浆涓簀son
-            JSONObject jsonObject = new JSONObject(str);
-
-            // 鑾峰彇json涓殑鍊�
-            JSONArray address = jsonObject.getJSONArray("Positioning1");
-            for (int i = 0; i < address.size(); i++) {
-                JSONObject ress = (JSONObject) address.get(i);
-
-                this.name = ress.getStr("name");
-                this.count = ress.getInt("count");
-                System.out.println("messageValues锛�" + this.name);
-                System.out.println("messageValues锛�" + this.count);
-            }
-
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
     @Override
     public void run() {
         while (this != null) {
@@ -74,21 +37,17 @@
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
-//        this.readValue();
-//            String PlcAddress = this.name;
-//            Integer Plccount = this.count;
+
 
             // System.out.println(stt);
             //瀛樼墖鏍�  鍑虹墖鏍艰鍙�
-  List<Short> arraylist = S7control.getinstance().ReadWord("DB100.42", 33);
+
+            String address = config.getProperty("PlcPositioning1.address");
+          List<Short> arraylist = S7control.getinstance().ReadWord(address, 33);
 //            System.out.println(arraylist);
-//            Short[] 瀛樼墖 = { 1 };
-//            List<Short> 瀛樼墖1 = new ArrayList<>(Arrays.asList(瀛樼墖));
-//            Short[] 鎺ョ墖 = { 1 };
-//            List<Short> 鎺ョ墖1 = new ArrayList<>(Arrays.asList(鎺ョ墖));
-//            Short[] 闂磋窛 = { 1 };
-//            List<Short> 闂磋窛1 = new ArrayList<>(Arrays.asList(闂磋窛));
-//            Short[] values1 = {1,1,1, 1,2, 3, 4, 5, 6, 7, 8, 9, 10,11, 12,13,14,15,16,17,18,19,20 };
+
+
+//            Short[] values1 = {1,1,1, 1,2, 3, 4, 5, 6, 7, 8, 9, 10,11, 12,13,14,15,16,17,18,19,20,11, 12,13,14,15,16,17,18,19,20 };
 //            List<Short> arraylist = new ArrayList<>(Arrays.asList(values1));
 
 
@@ -112,7 +71,7 @@
                     if (webserver != null) {
                         List<String> messages = webserver.getMessages();
                         //瀛樼墖鏍�  鍑虹墖鏍煎湴鍧�
-                        String addressList3 = "DB100.42";
+
 
                         if (!messages.isEmpty()) {
                             // 灏嗘渶鍚庝竴涓秷鎭浆鎹负 short 绫诲瀷鐨勫垪琛�
@@ -142,8 +101,8 @@
 
                             // 鍐欏叆瀛樼墖鏍�  鍑虹墖鏍间綅缃瀹氭暟鎹�
                             if (!mergedList.isEmpty()) {
-                                S7control.getinstance().WriteWord(addressList3, mergedList);
-                                System.out.println("messageValue锛�" + mergedList + " written to PLC at address " + addressList3);
+                                S7control.getinstance().WriteWord(address, mergedList);
+                                System.out.println("messageValue锛�" + mergedList + " written to PLC at address " + address);
                             }
 
                             // 娓呯┖娑堟伅鍒楄〃

--
Gitblit v1.8.0