From e70689e688fdc7d228e1bbdc2aa6b0ab96665423 Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期三, 24 七月 2024 19:19:10 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java |   89 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 71 insertions(+), 18 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
index 5824fcf..1254d27 100644
--- a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
+++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
@@ -85,7 +85,14 @@
     @Value("${mes.glassGap}")
     private Integer glassGap;
 
-    @Scheduled(fixedDelay = 500)
+    @Value("${mes.xMaxSize}")
+    private Integer xMaxSize;
+
+
+    private String d01GlassId = "";
+    private String d04GlassId = "";
+
+    @Scheduled(fixedDelay = 300)
     public void plcToHomeEdgScan() {
         Date startDate = new Date();
         log.info("澶х悊鐗囩鎵爜浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate);
@@ -114,17 +121,23 @@
         }
         //鎸夌収绾胯矾鍙婄幓鐠僫d鑾峰彇鐩搁偦涓ゅ潡鐜荤拑 鍗ц浆绔嬩笂鐨勭幓鐠�:  鐘舵�佷负0涓嶆搷浣滐紙D01閫佺墖锛�0涓嶆搷浣滐紝1鍏佽閫佺墖锛夛紝璇锋眰瀛椾负1锛� 锛�02鐜荤拑id涓虹┖鎴栬�呭崸杞珛鏈惎鍔級
         if (!REQUEST_WORD.equals(mesD01Value) && REQUEST_WORD.equals(d01ToMES) && (StringUtils.isBlank(d02State) || !REQUEST_WORD.equals(d03State))) {
-            judgeGlassTypeStatus(d01Id, Const.A09_OUT_TARGET_POSITION, mesD01Address);
+            if (!d01GlassId.equals(d01Id)) {
+                judgeGlassTypeStatus(d01Id, Const.A09_OUT_TARGET_POSITION, mesD01Address);
+                d01GlassId = d01Id;
+            }
         }
 //        鐘舵�佷负0涓嶆搷浣滐紙D01閫佺墖锛�0涓嶆搷浣滐紝1鍏佽閫佺墖锛夛紝璇锋眰瀛椾负1锛� 鍗ц浆绔嬫湭鍚姩
         if (!REQUEST_WORD.equals(mesD04Value) && REQUEST_WORD.equals(d04ToMES) && !REQUEST_WORD.equals(d05State)) {
-            judgeGlassTypeStatus(d04Id, Const.A10_OUT_TARGET_POSITION, mesD04Address);
+            if (!d04GlassId.equals(d04Id)) {
+                judgeGlassTypeStatus(d04Id, Const.A10_OUT_TARGET_POSITION, mesD04Address);
+                d04GlassId = d04Id;
+            }
         }
         Date endDate = new Date();
         log.info("澶х悊鐗囩鎵爜浠诲姟缁撴潫鏃堕棿锛歿}锛屽叡鑰楁椂锛歿}ms,缁撴潫鎵爜浠诲姟", endDate, endDate.getTime() - startDate.getTime());
     }
 
-    @Scheduled(fixedDelay = 500)
+    @Scheduled(fixedDelay = 300)
     public void plcToHomeEdgFreeCarTask() {
         Date startDate = new Date();
         log.info("澶х悊鐗囩绌鸿溅杩涚墖浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate);
@@ -231,11 +244,16 @@
         log.info("澶х悊鐗囩绌鸿溅杩涚墖浠诲姟缁撴潫鏃堕棿锛歿}锛屽叡鑰楁椂锛歿}ms,缁撴潫鎵爜浠诲姟", endDate, endDate.getTime() - startDate.getTime());
     }
 
-    @Scheduled(fixedDelay = 500)
+    @Scheduled(fixedDelay = 300)
     public void plcToHomeEdgOutTask() {
         Date startDate = new Date();
         log.info("澶х悊鐗囩绌鸿溅杩涚墖浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate);
         PlcParameterObject plcMesObject = S7object.getinstance().PlcMesObject;
+        String e02State = plcMesObject.getPlcParameter("E02State").getAddress();
+        if (REQUEST_WORD.equals(e02State)) {
+            log.info("鍑虹墖蹇欑锛岀粨鏉熷嚭鐗囦换鍔�");
+            return;
+        }
         String mesToPLCAddress = plcMesObject.getPlcParameter("MESToPLC").getAddress();
         List<BigStorageCageOutTask> outingList = bigStorageCageOutTaskService.list(new LambdaQueryWrapper<BigStorageCageOutTask>().eq(BigStorageCageOutTask::getTaskState, Const.BIG_STORAGE_OUT_NEW));
         Assert.isTrue(CollectionUtils.isEmpty(outingList), "鏈夋鍦ㄦ墽琛屽嚭鐗囩殑浠诲姟锛岀粨鏉熷綋鍓嶅嚭鐗囩嚎绋�");
@@ -299,10 +317,18 @@
                     List<BigStorageCageDetails> list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                             .eq(BigStorageCageDetails::getSlot, first.getSlot()).eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN));
                     List<BigStorageCageOutTask> outTasks = list.stream().map(e -> new BigStorageCageOutTask(e.getGlassId(), first.getSlot(), second.getSlot(),
-                            slotWidth, 0, 0, 1)).collect(Collectors.toList());
+                            e.getWidth() * 10, e.getHeight() * 10, 0, 0, 1)).collect(Collectors.toList());
                     bigStorageCageOutTaskService.saveBatch(outTasks);
-                    S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
-                    log.info("宸插悜plc鍙戦�佸嚭鐗囦换鍔$‘璁わ紝鍦板潃涓猴細{}", mesToPLCAddress);
+
+                    //鍚憄lc鍐欏叆纭瀛�
+                    int returnData = 0;
+                    int count = 1;
+                    while (returnData == 0) {
+                        log.info("宸插悜plc绗瑊}娆¢�佸崗璁�", count);
+                        S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
+                        returnData = S7object.getinstance().plccontrol.readWord(mesToPLCAddress, 1).get(0);
+                        log.info("宸插悜plc绗瑊}娆″彂閫佸嚭鐗囦换鍔$‘璁わ紝鍦板潃涓猴細{},鍐欏叆鐨勫唴瀹逛负{}", count++, mesToPLCAddress, returnData);
+                    }
                     Date endDate = new Date();
                     log.info("澶х悊鐗囩鍑虹墖浠诲姟缁撴潫鏃堕棿锛歿}锛屽叡鑰楁椂锛歿}ms,缁撴潫鎵爜浠诲姟", endDate, endDate.getTime() - startDate.getTime());
                     return;
@@ -311,7 +337,7 @@
         }
     }
 
-    @Scheduled(fixedDelay = 500)
+    @Scheduled(fixedDelay = 300)
     public void updateOutGlassStateTask() {
         Date startDate = new Date();
         log.info("1銆佸ぇ鐞嗙墖绗煎嚭鐗囧畬鎴愬悗鏇存柊澶х悊鐗囩鏁版嵁浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate);
@@ -340,7 +366,7 @@
     /**
      * 澶勭悊鐮存崯琛ㄤ换鍔�
      */
-    @Scheduled(fixedDelay = 500)
+    @Scheduled(fixedDelay = 300)
     public void dealDamageTask() {
         Date startDate = new Date();
         log.info("澶х悊鐗囩鐮存崯鐜荤拑娓呴櫎浠诲姟寮�濮嬫墽琛屾椂闂达細{}", startDate);
@@ -450,7 +476,15 @@
         }
         //鍚憄lc鍙戦�佽繘鐗囩‘璁�
         if (flag) {
-            S7object.getinstance().plccontrol.writeWord(mesAddress, 1);
+            //鍚憄lc鍐欏叆纭瀛�
+            int returnData = 0;
+            int count = 1;
+            while (returnData == 0) {
+                S7object.getinstance().plccontrol.writeWord(mesAddress, 1);
+                returnData = S7object.getinstance().plccontrol.readWord(mesAddress, 1).get(0);
+                log.info("杩涘崸杞珛绗瑊}娆″彂閫佺‘璁ゅ瓧瀹屾垚锛屽湴鍧�涓猴細{},鍐欏叆鐨勫唴瀹逛负{}", count++, mesAddress, returnData);
+
+            }
         }
         //璁板綍鏃犳硶鏀句笅鐜荤拑锛屽悗缁垽鏂惎鍔�
         return flag;
@@ -557,8 +591,13 @@
             s7control.writeWord(plcMesObject.getPlcParameter("StartAddToImport" + i).getAddress(), taskList.get(i - 1).getLine());
             s7control.writeWord(plcMesObject.getPlcParameter("TargetAddToImport" + i).getAddress(), taskList.get(i - 1).getTargetSlot());
         }
-        s7control.writeWord(outLine, 2);
-        log.info("閫佺墖浠诲姟宸插彂閫佸畬鎴愶紝浠诲姟绾胯矾涓猴細{}锛屽惎鍔ㄥ湴鍧�涓簕},纭瀛椾负{}", line, outLine, 2);
+        int returnData = 0;
+        int count = 1;
+        while (returnData == 0) {
+            s7control.writeWord(outLine, 2);
+            returnData = s7control.readWord(outLine, 1).get(0);
+            log.info("宸插悜plc绗瑊}娆″彂閫佸嚭鐗囦换鍔$‘璁わ紝鍦板潃涓猴細{},鍐欏叆鐨勫唴瀹逛负{}", count++, outLine, returnData);
+        }
     }
 
     private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list, Boolean isTempering, String mesToPLCAddress) {
@@ -566,17 +605,25 @@
         List<BigStorageCageOutTask> bigStorageCageOutTaskList = new ArrayList<>();
         //鎵撹溅鍓╀綑灏哄
         Integer remainWidth = carWidth;
+        int maxX = 0;
         for (T e : list) {
             if (bigStorageCageOutTaskList.size() >= outCarMaxSize || e.getWidth() > remainWidth) {
                 break;
             }
             remainWidth = remainWidth - (int) e.getWidth() - glassGap;
             if (isTempering) {
-                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.TEMPERING_OUT_TARGET_POSITION,
-                        (int) e.getWidth() * 10, 0, 0, 1));
+                int minLength = Math.min((int) e.getWidth(), (int) e.getHeight());
+                if (maxX + minLength <= xMaxSize) {
+                    bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.TEMPERING_OUT_TARGET_POSITION,
+                            e.getWidth() * 10, e.getHeight() * 10, 0, 0, 1));
+                    maxX = Math.max(maxX, e.getXCoordinate());
+                } else {
+                    break;
+                }
+
             } else {
                 bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.ARTIFICIAL_OUT_TARGET_POSITION,
-                        (int) e.getWidth() * 10, 0, 0, 1));
+                        e.getWidth() * 10, e.getHeight(), 0, 0, 1));
             }
 
         }
@@ -590,8 +637,14 @@
                 .in(BigStorageCageDetails::getGlassId, glassIds));
         //鏇存柊绗煎瓙鍐呮牸瀛愮殑鍓╀綑灏哄
         updateSlotRemain(list, glassIds);
-        S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
-        log.info("宸插悜plc鍙戦�佸嚭鐗囦换鍔$‘璁わ紝鍦板潃涓猴細{}", mesToPLCAddress);
+
+        int returnData = 0;
+        int count = 1;
+        while (returnData == 0) {
+            S7object.getinstance().plccontrol.writeWord(mesToPLCAddress, 1);
+            returnData = S7object.getinstance().plccontrol.readWord(mesToPLCAddress, 1).get(0);
+            log.info("宸插悜plc绗瑊}娆″彂閫佸嚭鐗囦换鍔$‘璁わ紝鍦板潃涓猴細{},鍐欏叆鐨勫唴瀹逛负{}", count++, mesToPLCAddress, returnData);
+        }
         return Boolean.TRUE;
     }
 

--
Gitblit v1.8.0