From 715416ffffca786c83eeb0d12bde008ee8e5403b Mon Sep 17 00:00:00 2001
From: clll <1320612696@qq.com>
Date: 星期二, 12 九月 2023 18:12:12 +0800
Subject: [PATCH] 将获取的PLc数据类型转换成需要使用的类型

---
 springboot-vue3/src/main/java/com/example/springboot/component/Plcstate.java |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

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 ba8d08b..69a97b7 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
@@ -4,6 +4,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Arrays;
 
 public class Plcstate extends Thread {
   @Override
@@ -16,14 +17,18 @@
       }
 
       List<Short> plclist = S7control.getinstance().ReadWord("DB103.DBW0", 10);
-      if (plclist == null) {
+      // Short[] values = { 0, 1, 1, 0, 1, 0, 1, 0,
+      // 1, 0, };
+      // List<Short> plclist = new ArrayList<>(Arrays.asList(values));
+      if (plclist != null) {
 
-      } else {
+        List<String> Intlist = new ArrayList<>();
+        for (Short value : plclist) {
+          Intlist.add(value == 1 ? "鑷姩" : "鎵嬪姩");
 
+        }
         JSONObject jsonObject = new JSONObject();
-        // jsonObject.append("sta",
-        // new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, });
-        jsonObject.append("sta", plclist);
+        jsonObject.append("sta", Intlist);
         WebSocketServer sendwServer = WebSocketServer.sessionMap.get("State");
         if (sendwServer != null) {
           sendwServer.sendMessage(jsonObject.toString());

--
Gitblit v1.8.0