From 31ec51457b9eebcd6f0d087b5134a00bd708159e Mon Sep 17 00:00:00 2001
From: pjb <pjb@>
Date: 星期三, 06 五月 2026 16:44:29 +0800
Subject: [PATCH] WCS功能完善

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |  172 ++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 114 insertions(+), 58 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index d5fe86f..96d786b 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -8,7 +8,6 @@
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
-import com.core.exception.CoolException;
 import com.zy.core.DevpThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
@@ -26,10 +25,7 @@
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -45,21 +41,79 @@
     private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
     private short heartBeatVal = 1;
     private StaError1 staError1;
-    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
-        add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);
-    }};
 
-    public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{
-        add(1); add(2);
+    // 绔欑偣
+    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
+        for(int i = 1 ;i <= 21; i ++) {add(1100+i);}
     }};
-    public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
-        add(101); add(103);
+    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
+        for(int i = 1 ;i <= 21; i ++) {add(1200+i);}
     }};
+    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{
+        for(int i = 1 ;i <= 21; i ++) {add(1300+i);}
+    }};
+    public static final ArrayList<Integer> staNos4 = new ArrayList<Integer>() {{
+        for(int i = 1 ;i <= 21; i ++) {add(1400+i);}
+    }};
+    private ArrayList<Integer> getStaNo() {
+        switch (this.slave.getId()) {
+            case 1: return staNos1;
+            case 2: return staNos2;
+            case 3: return staNos3;
+            case 4: return staNos4;
+            default:
+        }
+        return new ArrayList<>();
+    }
 
-    /**
-     * 鏉$爜鏁伴噺
-     */
-    private int barcodeSize = 2;
+    // 鏉$爜鎵弿鍣�
+    public static final ArrayList<Integer> barcodeList1 = new ArrayList<Integer>(){{
+        add(2);add(1);
+    }};
+    public static final ArrayList<Integer> barcodeList2 = new ArrayList<Integer>(){{
+        add(3);
+    }};
+    public static final ArrayList<Integer> barcodeList3 = new ArrayList<Integer>(){{
+        add(4);
+    }};
+    public static final ArrayList<Integer> barcodeList4 = new ArrayList<Integer>(){{
+        add(6);add(5);
+    }};
+    private ArrayList<Integer> getBarcodeList() {
+        switch (this.slave.getId()) {
+            case 1: return barcodeList1;
+            case 2: return barcodeList2;
+            case 3: return barcodeList3;
+            case 4: return barcodeList4;
+            default:
+        }
+        return new ArrayList<>();
+    }
+
+
+    // 澶栧舰妫�娴�
+    public static final ArrayList<Integer> shapeDetectionList1 = new ArrayList<Integer>(){{
+        add(1112);add(1109);
+    }};
+    public static final ArrayList<Integer> shapeDetectionList2 = new ArrayList<Integer>(){{
+        add(1209);
+    }};
+    public static final ArrayList<Integer> shapeDetectionList3 = new ArrayList<Integer>(){{
+        add(1309);
+    }};
+    public static final ArrayList<Integer> shapeDetectionList4 = new ArrayList<Integer>(){{
+        add(1407);add(1402);
+    }};
+    private ArrayList<Integer> getShapeDetectionList() {
+        switch (this.slave.getId()) {
+            case 1: return shapeDetectionList1;
+            case 2: return shapeDetectionList2;
+            case 3: return shapeDetectionList3;
+            case 4: return shapeDetectionList4;
+            default:
+        }
+        return new ArrayList<>();
+    }
 
     /**
      * 鍏ュ嚭搴撴ā寮�
@@ -71,12 +125,10 @@
      */
     public IoModeType ioModeOf101 = IoModeType.NONE;
 
+    private int pathStatus  = 0;
+
     public SiemensDevpThread(DevpSlave slave) {
         this.slave = slave;
-    }
-
-    private ArrayList<Integer> getStaNo() {
-        return staNos;
     }
 
     @Override
@@ -183,11 +235,11 @@
      */
     private void read() {
 
-        // 璇讳竴妤艰繛缁�8涓珯鐐�
-        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (8*8));
+        // 绔欑偣淇℃伅
+        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (getStaNo().size()*8));
         if (result.IsSuccess) {
-            for (int i = 0; i < 8; i++) {
-                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
+            for (int i = 0; i < getStaNo().size(); i++) {
+                Integer siteId = getStaNo().get(i); // 绔欑偣缂栧彿
                 StaProtocol staProtocol = station.get(siteId);
                 if (null == staProtocol) {
                     staProtocol = new StaProtocol();
@@ -206,20 +258,26 @@
                 staProtocol.setEmptyMk(status[4]);  // 绌烘澘淇″彿
                 staProtocol.setFullPlt(status[5]);  // 婊℃墭鐩�
                 staProtocol.setHigh(status[6]);     // 楂樺簱浣�
-                staProtocol.setLow(status[7]);      // 浣庡簱浣�
+                staProtocol.setLow(status[7]);      // 涓簱浣�
+                staProtocol.setCenter(status[8]);   // 浣庡簱浣�
 
                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                     staProtocol.setPakMk(true);
                 }
             }
+        } else {
+            initSite();
+            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栬緭閫佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
+            News.error("SiemensCrn"+" - 4"+" - 璇诲彇杈撻�佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+            return;
         }
 
         // 鏉$爜鎵弿鍣�
-        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.1672", (short) ((BarcodeList.size()+1) * 8)); // 涓嶈繛缁�
+        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.600", (short) (getBarcodeList().size() * 10));
         if (barcodeResult.IsSuccess) {
-            for (int i = 0; i < BarcodeList.size(); i++) {
-                String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*16,8, "UTF-8");
-                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, BarcodeList.get(i));
+            for (int i = 0; i < getBarcodeList().size(); i++) {
+                String barcode = siemensS7Net.getByteTransform().TransString(barcodeResult.Content,i*10 + 2,8, "UTF-8");
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, getBarcodeList().get(i));
                 if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                     barcodeThread.setBarcode(barcode);
                 }
@@ -227,27 +285,30 @@
         }
 
         // 澶栧舰妫�娴�
-        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.1652", (short) ((staNosErrList.size()+1)*4)); // 涓嶈繛缁紝澶氳涓棿涓�涓�
+        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.700", (short) (getShapeDetectionList().size() *6));
         if (resultErr.IsSuccess){
-            for (int i = 0;i<staNosErrList.size();i++){
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*8+2, 1);
-                StaProtocol staProtocol = station.get(staNosErrList.get(i));
+            for (int i = 0;i<getShapeDetectionList().size();i++){
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*6+2, 1);
+                StaProtocol staProtocol = station.get(getShapeDetectionList().get(i));
                 staProtocol.setFrontErr(status[0]);
                 staProtocol.setBackErr(status[1]);
                 staProtocol.setHighErr(status[2]);
                 staProtocol.setLeftErr(status[3]);
                 staProtocol.setRightErr(status[4]);
-                staProtocol.setWeightErr(status[5]);
+                staProtocol.setGroupSupportErr(status[5]);
                 staProtocol.setBarcodeErr(status[6]);
+                staProtocol.setWeightErr(status[7]);
+                short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 6);
+                staProtocol.setGoodsHeight(goodsHeight);
             }
         }
 
-        // 璇讳竴妤艰繛缁�8涓珯鐐癸紝鏁呴殰淇℃伅鍙嶉
-        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.3312", (short) (8*2));
+        // 鏁呴殰淇℃伅鍙嶉
+        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.400", (short) (getStaNo().size() * 4));
         if (resultErr2.IsSuccess) {
-            for (int i = 0; i < 8; i++) {
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*2 + 1, 1);
-                StaProtocol staProtocol = station.get(staNos.get(i)); // 绔欑偣缂栧彿
+            for (int i = 0; i < getStaNo().size(); i++) {
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4 + 2, 1);
+                StaProtocol staProtocol = station.get(getStaNo().get(i)); // 绔欑偣缂栧彿
                 staProtocol.setBreakerErr(status[0]);
                 staProtocol.setInfraredErr(status[1]);
                 staProtocol.setOutTimeErr(status[2]);
@@ -267,7 +328,7 @@
             // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
             try {
                 List<BasDevp> basDevps = new ArrayList<>();
-                for (Integer siteId : staNos) {
+                for (Integer siteId : getStaNo()) {
                     StaProtocol staProtocol = station.get(siteId);
                     basDevps.add(staProtocol.toSqlModel());
                 }
@@ -289,6 +350,13 @@
         }
     }
 
+    public void updatePathStatus(int status) {
+        if (this.pathStatus == status) return;
+        this.pathStatus = status;
+        siemensS7Net.Write("DB100.300", (short) status);
+        log.info("鏇存柊杈撻�佺嚎璺緞鐘舵�佹垚鍔� ===>> [id:{}] [status: {}]", slave.getId(), status);
+    }
+
     /**
      * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
      */
@@ -297,35 +365,22 @@
             return;
         }
 
-        int address = -1;
-        switch (staProtocol.getSiteId()) {
-            case 100: address = 0; break;
-            case 101: address = 4; break;
-            case 102: address = 8; break;
-            case 103: address = 12; break;
-            case 104: address = 16; break;
-            case 105: address = 20; break;
-            case 106: address = 24; break;
-            case 107: address = 28; break;
-            default:
-        }
-        if(address == -1) {
-            throw new CoolException("鍐欏叆绔欑偣寮傚父锛�" + staProtocol.getSiteId());
-        }
+        int address = getStaNo().indexOf(staProtocol.getSiteId()) * 6;
+
         OperateResult write;
         OperateResult write1;
         //浠诲姟涓嬪彂娆℃暟
         int writeCount = 0;
         do {
-            write1 = siemensS7Net.Write("DB100." + (address+2), staProtocol.getStaNo());    // 鐩爣绔�
-            write = siemensS7Net.Write("DB100." + address, staProtocol.getWorkNo().shortValue());    // 宸ヤ綔鍙�
+            write = siemensS7Net.Write("DB100." + (address), staProtocol.getWorkNo());    // 宸ヤ綔鍙�
+            write1 = siemensS7Net.Write("DB100." + (address + 4), staProtocol.getStaNo());    // 鐩爣绔�
             Thread.sleep(200);
             if(write.IsSuccess && write1.IsSuccess){
                 break;
             }
             else {
                 writeCount++;
-                log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
+                News.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
             }
         }while (writeCount<5);
 
@@ -340,6 +395,7 @@
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
             News.info("SiemensDevp"+" - 5"+" - 杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
         }
+        read();
     }
 
     /**

--
Gitblit v1.9.1