From 0613a5b982c6521560ea17eda7c07bb97e6ec5e9 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期三, 17 一月 2024 09:14:43 +0800
Subject: [PATCH] 修改交互状态页面

---
 springboot-vue3/src/main/java/com/example/springboot/component/S7control.java |   47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java b/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
index 95ebb15..ce4f674 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/S7control.java
@@ -37,13 +37,21 @@
         }
         return instance;
     }
-
+    
     /**
      * 鍏抽棴瑗块棬瀛恠7閫氳杩炴帴
      */
     public void CloseS7client() {
         if (s7PLC == null)
             s7PLC.close();
+            s7PLC.checkConnected();
+    }
+
+    /**
+     * s7閫氳杩炴帴鐘舵��
+     */
+    public boolean CheckConnected() {
+        return s7PLC.checkConnected();
     }
 
     /**
@@ -281,6 +289,41 @@
 }
 
 
+
+
+
+    public List<String> readStringsandword(List<String> addressList) {
+        if (s7PLC == null) {
+            return null;
+        }
+        List<String> result = new ArrayList<>();
+        for (String address : addressList) {
+            try {
+                if (address.contains("-")) {
+                    address = address.substring(0, address.indexOf("-"));
+
+                    byte[] bytes = s7PLC.readByte(address, 14);
+                    if (bytes != null) {
+                        String str = new String(bytes, StandardCharsets.UTF_8);
+                        result.add(str);
+                    }
+
+                } else {
+                    Short value = s7PLC.readInt16(address);
+                    result.add(value.toString());
+
+                }
+            } catch (Exception e) {
+                System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage());
+                result.add(null);
+            }
+        }
+
+        return result;
+    }
+
+
+
 //涓嶈繛缁湴鍧�鍐欏叆Word
     public void WriteWord(List<String> address, List<Short> datas) {
         if (s7PLC == null)
@@ -345,7 +388,7 @@
     try {
         return s7PLC.readTime(address);
     } catch (Exception e) {
-        e.printStackTrace();
+        System.out.println("璇诲彇 " + address + " 澶辫触锛�" + e.getMessage());
         return null;
     }
 }

--
Gitblit v1.8.0