From 54c7981d6f05ce0e3b59df3c4e23cd06a81a059b Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期四, 14 十二月 2023 09:15:01 +0800
Subject: [PATCH] 后端代码改为大部分使用消息处理对象写入

---
 springboot-vue3/src/main/java/com/example/springboot/component/MessageHandler.java |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/MessageHandler.java b/springboot-vue3/src/main/java/com/example/springboot/component/MessageHandler.java
index c380a42..ae39320 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/MessageHandler.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/MessageHandler.java
@@ -66,7 +66,7 @@
         }
     }
 
-    //鍐欏叆Word
+    //涓嶈繛缁湴鍧� 鍐欏叆Word
     public void WriteWordToPLC(JSONArray messageArray, List<String> addresses, int index) {
         try {
             if (messageArray.getJSONArray(index).size() > 0) {
@@ -95,6 +95,26 @@
         }
     }
 
+
+
+    public void WriteWordsToPLC(JSONArray jsonArray,  String address,int index) {
+        if (jsonArray.getJSONArray(index).size() > 0) {
+            Object value = jsonArray.getJSONArray(index).get(0);
+            if (value != null && !value.toString().equals("null")) {
+                try {
+                    String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
+                    short sValue = Short.parseShort(cleanedValue.trim());
+                    S7control.getinstance().WriteWord(address, Arrays.asList(sValue));
+                    System.out.println("messageValue锛�" + Arrays.asList(sValue) + " written to PLC at address " + address);
+                } catch (NumberFormatException e) {
+                    // 濡傛灉鏃犳硶瑙f瀽涓� short 绫诲瀷锛屽垯蹇界暐璇ラ儴鍒�
+                    System.err.println("Could not parse value: " + value);
+                }
+            }
+        }
+    }
+
+
     //鍐欏叆String
     public void writeStringToPLC(JSONArray messageArray, String addresses, int index) {
         try {

--
Gitblit v1.8.0