From 9e62d4c6dfcebf8510580d9141a8141f6b158818 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期二, 26 十二月 2023 09:34:41 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes

---
 springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java |  212 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 171 insertions(+), 41 deletions(-)

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 67666ae..0cae2f5 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
@@ -1,11 +1,15 @@
 package com.example.springboot.component;
 
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 
+import java.io.IOException;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import com.example.springboot.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.example.springboot.entity.Out_slice;
@@ -14,10 +18,7 @@
 import com.example.springboot.entity.alarmmg;
 import com.example.springboot.mapper.HomeMapper;
 import com.example.springboot.mapper.SpianMapper;
-import com.example.springboot.service.JdbcConnections;
-import com.example.springboot.service.North_Glass_Buffer1Service;
-import com.example.springboot.service.OutSliceServive;
-import com.example.springboot.service.SpianService;
+import com.example.springboot.service.StorageCageService;
 
 public class Plchome extends Thread {
 
@@ -30,10 +31,22 @@
     private JdbcConnections dbserve;
     // 鍑虹墖闃熷垪鏄惁鍏佽鍑虹墖
     public static Boolean isAllowQueue = true;
+    public static Boolean isAllowReordering = true;
     // 閾濇id
-    public static String FrameNo;
+    public static String FrameNo = "";
     // 鏄惁闇�瑕佹墜鍔ㄧ‘璁ょ幓鐠�
     public static Boolean isConfirm = false;
+
+    private Configuration config;
+
+
+
+    private  StorageCageService storageCageService;
+
+
+    public Plchome() throws IOException {
+        config = new Configuration("config.properties");
+    }
 
     // public static Map b=new HashMap<>();
     // b.put()
@@ -42,13 +55,14 @@
         while (this != null) {
             try {
                 Thread.sleep(1000);
-                
+
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             JSONObject jsonObject = new JSONObject();
 
             // 娉ㄥ叆mapper
+
             homeMapper = WebSocketServer.applicationContext.getBean(HomeMapper.class);
             spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class);
             spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
@@ -74,6 +88,31 @@
             // 鏌ヨ鎶ヨ淇℃伅
             List<alarmmg> alarmmg = homeMapper.SelectAlarmmgInfo();
             jsonObject.append("alarmmg", alarmmg);
+
+            // 浼� 鑾峰彇杩涙槸鍚︽湁寰呯‘璁ょ殑鐜荤拑id
+            String queid = spianMapper.Selectqueueid();
+            int state = spianMapper.Selectqueuestate();
+            jsonObject.append("queid", queid);
+            jsonObject.append("state", state);
+            // 鑾峰彇鎵爜浣嶄笌涓婄墖浣嶇幓鐠冧俊鎭�
+            Queue form2 = homeMapper.GetQueueInfo(2);
+            Queue form3 = homeMapper.GetQueueInfo(1);
+            if (form2.getglassId() != null && form2.getglassId() != "") {
+                jsonObject.append("form2", form2);
+            }
+            if (form3.getglassId() != null && form3.getglassId() != "") {
+                jsonObject.append("form3", form3);
+            }
+            // 鑾峰彇鍑虹墖闃熷垪淇℃伅
+            List<Out_slice> listoutslice = outSliceServive.SelectProductionqueue();
+            jsonObject.append("listoutslice", listoutslice);
+            // 鑾峰彇褰撳墠鍑虹墖闃熷垪鍑虹墖鐘舵��
+            jsonObject.append("isAllowQueue", Plchome.isAllowQueue);
+            // 鑾峰彇褰撳墠鍑虹墖闃熷垪璋冨簭鐘舵��
+            jsonObject.append("isAllowReordering", Plchome.isAllowReordering);
+            // 鏄惁闇�瑕佷汉宸ョ‘璁や笂鐗囩幓鐠�
+            jsonObject.append("isConfirm", isConfirm);
+
             // 璇诲幓Plc杩涚墖杞︿笌鍑虹墖杞︿綅缃甒
             List<String> addressList = new ArrayList<String>();
             addressList.add("DB106.12");
@@ -93,53 +132,74 @@
                 if (inglassInfo.size() > 0)
                     jsonObject.append("loadglassheight", inglassInfo.get(0) * 70);
             }
-            // 浼� 鑾峰彇杩涙槸鍚︽湁寰呯‘璁ょ殑鐜荤拑id
-            String queid = spianMapper.Selectqueueid();
-            int state = spianMapper.Selectqueuestate();
-            jsonObject.append("queid", queid);
-            jsonObject.append("state", state);
-            // 鑾峰彇鎵爜浣嶄笌涓婄墖浣嶇幓鐠冧俊鎭�
-            Queue form2 = homeMapper.GetQueueInfo(2);
-            Queue form3 = homeMapper.GetQueueInfo(1);
-            if (form2.getglassId() != null && form2.getglassId() != "") {
-                jsonObject.append("form2", form2);
-            }
-            if (form3.getglassId() != null && form3.getglassId() != "") {
-                jsonObject.append("form3", form3);
-            }
-            // 鑾峰彇鍑虹墖闃熷垪淇℃伅
-            List<Out_slice> listoutslice = outSliceServive.SelectProductionqueue();
-            jsonObject.append("listoutslice", listoutslice);
-            // 鑾峰彇褰撳墠鍑虹墖闃熷垪鐘舵��
-            jsonObject.append("isAllowQueue", Plchome.isAllowQueue);
 
             // 鑾峰彇閾濇idDB106.DBW64
-            // String frameno=spianService.queGlassid("DB103.270",14).toString();
-            // if(frameno!=Plchome.FrameNo&&frameno!=""){
-            // Plchome.FrameNo=frameno;
-            // }
-            // try {
-            // north_Glass_Buffer1Service.AddOutSliceS(Plchome.FrameNo);
-            // } catch (SQLException e) {
-            // // TODO Auto-generated catch block
-            // e.printStackTrace();
-            // }
-            // 鏄惁闇�瑕佷汉宸ョ‘璁や笂鐗囩幓鐠�
-            jsonObject.append("isConfirm", isConfirm);
+            String frameno = spianService.queGlassid("DB103.270", 14).toString();
+            // String frameno="X12345611002GV";
+            if (!frameno.equals(Plchome.FrameNo)) {
+                Plchome.FrameNo = frameno;
+                try {
+                    north_Glass_Buffer1Service.AddOutSliceS(Plchome.FrameNo);
+                } catch (SQLException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
 
-            //鑾峰彇杩涚墖璇锋眰鐘舵��
+            // 鑾峰彇杩涚墖璇锋眰鐘舵��
             List<Short> D01Request = S7control.getinstance().ReadWord("DB106.24", 1);
             boolean D01RequestState = D01Request.contains((short) 1);
             // boolean D01RequestState =true;
             jsonObject.append("D01RequestState", D01RequestState);
 
-            //澶嶄綅鍊掕鏃�
+            // 澶嶄綅鍊掕鏃�
             // 鍦板潃104.9.6
             List<Boolean> countdown = S7control.getinstance().ReadBits("DB104.9.6", 1);
             for (Boolean countdowns : countdown) {
                 jsonObject.append("countdown", countdowns);
             }
             // jsonObject.append("countdown", true);
+            // 澶嶄綅瀹屾垚淇″彿
+            List<Boolean> resets = S7control.getinstance().ReadBits("DB103.284", 1);
+            for (Boolean reset : resets) {
+                jsonObject.append("reset", reset);
+            }
+
+            // 鏄惁鎬ュ仠
+            List<Boolean> emergencystops = S7control.getinstance().ReadBits("DB104.5.1", 1);
+            for (Boolean emergencystop : emergencystops) {
+                jsonObject.append("emergencystop", emergencystop);
+            }
+
+            //缁堟缁х画鎸夐挳
+            List<String> niuanaddressList3 = Arrays.asList(config.getProperty("Parameter2.stop").split(","));
+            List<Boolean> anniuread = S7control.getinstance().readBits(niuanaddressList3);
+
+            short[] anniuparams = new short[anniuread.size()];
+            for (int i = 0; i < anniuread.size(); i++) {
+                boolean value = anniuread.get(i);
+                anniuparams[i] = value ? (short) 1 : (short) 0;
+            }
+
+
+            short[] resets2 = new short[resets.size()];
+            for (int i = 0; i < resets.size(); i++) {
+                boolean value = resets.get(i);
+                resets2[i] = value ? (short) 1 : (short) 0;
+            }
+
+//            System.out.println(resets);
+            for (short number : resets2) {
+
+                if (number == 1) {
+                    System.out.println(resets);
+                    jsonObject.append("Abort", anniuparams);
+
+                }
+
+            }
+
+
             // 閾濇绾夸氦浜�
 
             // //閾濇id璇锋眰瀛�
@@ -163,7 +223,7 @@
             // }
             // S7control.getinstance().WriteWord("閾濇缈昏浆鍙戦�佸湴鍧�", (short)send);
             // }
-
+            storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class);
             dbserve = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
             boolean dbconnected = false;
             try {
@@ -179,9 +239,79 @@
             if (sendwServer != null) {
                 for (WebSocketServer webserver : sendwServer) {
                     webserver.sendMessage(jsonObject.toString());
+
+                    if (webserver != null) {
+
+
+                        List<String> messages = webserver.getMessages();
+
+                        if (!messages.isEmpty()) {
+                            // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
+                            String lastMessage = messages.get(messages.size() - 1);
+//        System.out.println("lastMessage锛�" + lastMessage);
+                            JSONArray messageArray = new JSONArray(lastMessage);
+
+
+                            try {
+                                // 妫�鏌ョ储寮曟槸鍚︽湁鏁�
+                                if (messageArray.getJSONArray(0).size() > 0) {
+                                    // 鑾峰彇娑堟伅鏁扮粍
+                                    JSONArray jsonArray = messageArray.getJSONArray(0);
+                                    // 鍒涘缓涓�涓竷灏斿�煎垪琛�
+                                    List<Boolean> sValue = new ArrayList<>();
+                                    // 閬嶅巻娑堟伅鏁扮粍
+                                    for (int i = 0; i < jsonArray.size(); i++) {
+                                        // 鑾峰彇娑堟伅鏁扮粍涓殑鍊�
+                                        Object value = jsonArray.get(i);
+                                        // 妫�鏌ュ�兼槸鍚︽湁鏁�
+                                        if (value != null && !value.toString().equals("null")) {
+                                            try {
+                                                // 绉婚櫎闈炴暟瀛楀拰鏁板瓧瀛楃
+                                                String cleanedValue = value.toString().replaceAll("[^0-9-]", "");
+                                                // 瑙f瀽涓哄竷灏斿��
+                                                boolean val = "1".equals(cleanedValue.trim());
+                                                // 灏嗗竷灏斿�兼坊鍔犲埌甯冨皵鍊煎垪琛ㄤ腑
+                                                sValue.add(val);
+                                                System.out.println("messageValue: " + Arrays.asList(val) + " added to the list");
+
+
+                                            } catch (NumberFormatException e) {
+                                                // 濡傛灉鏃犳硶瑙f瀽涓� boolean 绫诲瀷锛屽垯蹇界暐璇ラ儴鍒�
+                                                System.err.println("Could not parse value: " + value);
+                                            }
+                                        }
+                                    }
+// 缁堟杩涚墖浠诲姟
+                                    boolean Value1 = sValue.get(0);
+                                    boolean Value2 = sValue.get(1);
+
+                                    if (Value1) {
+                                        storageCageService.EndTask(0);
+
+                                    }
+                                    if (Value2) {
+                                        storageCageService.EndTask(1);
+
+                                    }
+                                    // 妫�鏌ュ竷灏斿�煎垪琛ㄦ槸鍚︿负绌�
+                                    if (!sValue.isEmpty()) {
+
+                                        // 璋冪敤 S7control.getinstance().WriteBit 鏂规硶灏嗗竷灏斿�煎垪琛ㄥ啓鍏ュ湴鍧�鍒楄〃
+                                        S7control.getinstance().WriteBit(niuanaddressList3, sValue);
+                                        System.out.println("Values " + sValue + " written to PLC at address " + niuanaddressList3);
+                                    }
+                                }
+                            } catch (Exception e) {
+                                System.err.println("An error occurred while writing bit to PLC: " + e.getMessage());
+                            }
+                            webserver.clearMessages();
+                        }
+
+
+                    }
+
                 }
             }
-
         }
     }
 }

--
Gitblit v1.8.0