From e7eaa7bb402aae3bb88d9219e50f0e1179f3257f Mon Sep 17 00:00:00 2001 From: wuyouming666 <2265557248@qq.com> Date: 星期二, 26 十二月 2023 09:28:52 +0800 Subject: [PATCH] layout 布局页增加A01 A02终止继续后选择 弹框 --- springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java | 152 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 133 insertions(+), 19 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 9de15ae..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() @@ -49,6 +62,7 @@ JSONObject jsonObject = new JSONObject(); // 娉ㄥ叆mapper + homeMapper = WebSocketServer.applicationContext.getBean(HomeMapper.class); spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class); spianService = WebSocketServer.applicationContext.getBean(SpianService.class); @@ -92,8 +106,10 @@ // 鑾峰彇鍑虹墖闃熷垪淇℃伅 List<Out_slice> listoutslice = outSliceServive.SelectProductionqueue(); jsonObject.append("listoutslice", listoutslice); - // 鑾峰彇褰撳墠鍑虹墖闃熷垪鐘舵�� + // 鑾峰彇褰撳墠鍑虹墖闃熷垪鍑虹墖鐘舵�� jsonObject.append("isAllowQueue", Plchome.isAllowQueue); + // 鑾峰彇褰撳墠鍑虹墖闃熷垪璋冨簭鐘舵�� + jsonObject.append("isAllowReordering", Plchome.isAllowReordering); // 鏄惁闇�瑕佷汉宸ョ‘璁や笂鐗囩幓鐠� jsonObject.append("isConfirm", isConfirm); @@ -116,20 +132,19 @@ if (inglassInfo.size() > 0) jsonObject.append("loadglassheight", inglassInfo.get(0) * 70); } - // 鑾峰彇閾濇idDB106.DBW64 - String frameno=spianService.queGlassid("DB103.270",14).toString(); - if(frameno!=Plchome.FrameNo&&frameno!=""){ - Plchome.FrameNo=frameno; + 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(); + } } - 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); @@ -156,6 +171,35 @@ 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璇锋眰瀛� @@ -179,7 +223,7 @@ // } // S7control.getinstance().WriteWord("閾濇缈昏浆鍙戦�佸湴鍧�", (short)send); // } - + storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class); dbserve = WebSocketServer.applicationContext.getBean(JdbcConnections.class); boolean dbconnected = false; try { @@ -195,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