wu
2024-01-18 65bed7f78be75f0ba279885de647d76bc91d9336
springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
@@ -16,6 +16,7 @@
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.alarmmg;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.mapper.HomeMapper;
import com.example.springboot.mapper.SpianMapper;
@@ -31,20 +32,22 @@
    // 出片队列是否允许出片
    public static Boolean isAllowQueue = true;
    public static Boolean isAllowReordering = true;
    //出片队列警告
    public static Boolean isQueueWarning=false;
    // 出片队列警告
    public static Boolean isQueueWarning = false;
    // 铝框id
    public static String FrameNo = "";
    // 是否需要手动确认玻璃
    public static Boolean isConfirm = false;
    // 待确认的出片队列
    public static List<north_glass_buffer1> AluminumFrame;
    private Configuration config;
    // private Configuration config;
    private StorageCageService storageCageService;
    public Plchome() throws IOException {
        config = new Configuration("config.properties");
    }
    // public Plchome() throws IOException {
    // config = new Configuration("config.properties");
    // }
    // public static Map b=new HashMap<>();
    // b.put()
@@ -106,23 +109,75 @@
            jsonObject.append("listoutslice", listoutslice);
            // 获取当前出片队列出片状态
            jsonObject.append("isAllowQueue", Plchome.isAllowQueue);
            //获取出片队列警告状态
            // 获取出片队列警告状态
            jsonObject.append("isQueueWarning", Plchome.isQueueWarning);
            // 获取当前出片队列调序状态
            jsonObject.append("isAllowReordering", Plchome.isAllowReordering);
            // 是否需要人工确认上片玻璃
            jsonObject.append("isConfirm", isConfirm);
            // String framenos="X21763329601FB";
            //     if (!framenos.equals(Plchome.FrameNo)) {
            //         Plchome.FrameNo = framenos;
            //         try {
            //             north_Glass_Buffer1Service.AddOutSliceS(Plchome.FrameNo);
            //         } catch (SQLException e) {
            //             // TODO Auto-generated catch block
            //             e.printStackTrace();
            // 查询当前铝框信息
            Out_slice CurrentFrame = outSliceServive.SelectCurrentFrame();
            jsonObject.append("CurrentFrame", CurrentFrame);
            // List<Short> listd17 = S7control.getinstance().ReadWord("DB17.0",10);
            // String id=spianService.queGlassid("DB17.10", 14).toString();
            //
            // // 铝框线交互
            // try {
            //     if (CurrentFrame != null) {
            //         spianService.outmesid(CurrentFrame.getBarCode(), "DB17.0");
            //     }
            //     List<Short> framerequests = S7control.getinstance().ReadWord("铝框id请求字地址", 1);
            //     for (Short framerequest : framerequests) {
            //         if (framerequest == 1) {
            //             // 铝框id
            //             String franmeno = spianService.queGlassid("DB17.10", 14).toString();
            //             String position;
            //             try {
            //                 position = dbserve.SelectPositionByFrameBarcode(franmeno);
            //             } catch (SQLException e) {
            //                 // TODO Auto-generated catch block
            //                 position = "0";
            //                 e.printStackTrace();
            //             }
            //             Short send;
            //             if (position == "0") {
            //                 send = 0;
            //             } else {
            //                 send = 1;
            //             }
            //             S7control.getinstance().WriteWord("铝框翻转发送地址", (short) send);
            //         }
            //     }
            // } catch (Exception e) {
            //     // TODO: handle exception
            // }
            if (S7control.getinstance().CheckConnected() == true) {
                // 获取当前扫码方式
                List<Short> Scanningmethod = S7control.getinstance().ReadWord("DB103.255", 1);
                jsonObject.append("Scanningmethod", Scanningmethod);
                // 获取D01-D06,A01,A02,B01,B02状态
                List<Short> DeviceList = S7control.getinstance().ReadWord("DB103.0", 10);
                jsonObject.append("DeviceList", DeviceList);
                // 获取D01-D06,A01,A02,B01,B02玻璃id
                List<String> GlassIdList = new ArrayList<String>();
                GlassIdList.add(spianService.queGlassid("DB103.40", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.58", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.184", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.212", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.128", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.142", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.156", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.72", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.86", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.100", 14).toString());
                GlassIdList.add(spianService.queGlassid("DB103.114", 14).toString());
                jsonObject.append("GlassIdList", GlassIdList);
                // 读去Plc进片车与出片车位置W
                List<String> addressList = new ArrayList<String>();
                addressList.add("DB106.12");
@@ -147,19 +202,33 @@
                    }
                }
                // 获取铝框idDB106.DBW64,添加到出片队列
                // // 获取铝框idDB106.DBW64,添加到出片队列
                // String frameno="X21763329601FB";
                String frameno = spianService.queGlassid("DB103.270", 14).toString();
                // String frameno="X12345611002GV";
                // frameno="X21763329601FB";
                if (!frameno.equals(Plchome.FrameNo)) {
                    Plchome.FrameNo = frameno;
                    try {
                        north_Glass_Buffer1Service.AddOutSliceS(Plchome.FrameNo);
                        Short num = 0;
                        List<north_glass_buffer1> north_glass_buffer1s = north_Glass_Buffer1Service
                                .SelectAluminumFrameInfoById(Plchome.FrameNo);
                        for (north_glass_buffer1 north_glass_buffer1 : north_glass_buffer1s) {
                            if (north_glass_buffer1.getstorageCage() == null) {
                                break;
                            }
                            num++;
                        }
                        if (num == north_glass_buffer1s.size()) {
                            north_Glass_Buffer1Service.AddOutSliceS(Plchome.FrameNo);
                        } else {
                            Plchome.AluminumFrame = north_glass_buffer1s;
                        }
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                if (AluminumFrame != null) {
                    jsonObject.append("AluminumFrame", AluminumFrame);
                }
                // 获取进片请求状态
@@ -184,63 +253,40 @@
                // 是否急停
                List<Boolean> emergencystops = S7control.getinstance().ReadBits("DB104.5.1", 1);
                for (Boolean emergencystop : emergencystops) {
                    jsonObject.
                    append("emergencystop", emergencystop);
                    jsonObject.append("emergencystop", emergencystop);
                }
                // // 终止继续按钮
                // List<String> niuanaddressList3 = Arrays.asList(config.getProperty("Parameter2.stop").split(","));
                // List<Boolean> anniuread = S7control.getinstance().readBits(niuanaddressList3);
                // List<String> niuanaddressList3 =
                // Arrays.asList(config.getProperty("Parameter2.stop").split(","));
                // List<Boolean> anniuread =
                // S7control.getinstance().readBits(niuanaddressList3);
                // // Boolean[] value4 = { false, false};
                // // List<Boolean> anniuread = new ArrayList<>(Arrays.asList(value4));
                // Boolean[] value5 = { true };
                // List<Boolean> resets = new ArrayList<>(Arrays.asList(value5));
                // 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;
                // 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;
                // boolean value = resets.get(i);
                // resets2[i] = value ? (short) 1 : (short) 0;
                // }
                // for (short number : resets2) {
                //     if (number == 1) {
                //         jsonObject.append("Abort", anniuparams);
                // if (number == 1) {
                // jsonObject.append("Abort", anniuparams);
                //     }
                // }
                // }
            }
            // 铝框线交互
            // //铝框id请求字
            // List<Short> framerequest = S7control.getinstance().ReadWord("铝框id请求字地址", 1);
            // if(framerequest!=null){
            // //铝框id
            // String franmeno= spianService.queGlassid("铝框id地址", 14).toString();
            // String position;
            // try {
            // position=dbserve.SelectPositionByFrameBarcode(franmeno);
            // } catch (SQLException e) {
            // // TODO Auto-generated catch block
            // position="0";
            // e.printStackTrace();
            // }
            // Short send;
            // if(position=="0"){
            // send=0;
            // }else{
            // send=1;
            // }
            // S7control.getinstance().WriteWord("铝框翻转发送地址", (short)send);
            // }
            storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class);
            dbserve = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
            boolean dbconnected = false;
@@ -264,63 +310,6 @@
                        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-]", "");
                            //                     // 解析为布尔值
                            //                     boolean val = "1".equals(cleanedValue.trim());
                            //                     // 将布尔值添加到布尔值列表中
                            //                     sValue.add(val);
                            //                     System.out.println(
                            //                             "messageValue: " + Arrays.asList(val) + " added to the list");
                            //                 } catch (NumberFormatException e) {
                            //                     // 如果无法解析为 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();
                        }