From 7ed8a3db0115b19349cbdad55c91c353a0e8e300 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期日, 26 四月 2026 16:29:19 +0800
Subject: [PATCH] 一楼输送线出入库冲突控制

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |  133 ++++++++++++++++++++++++++++++++------------
 1 files changed, 96 insertions(+), 37 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index cfc018f..872532d 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -25,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;
 
 /**
@@ -44,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(104); add(106);
+    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<>();
+    }
 
     /**
      * 鍏ュ嚭搴撴ā寮�
@@ -70,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,10 +236,10 @@
     private void read() {
 
         // 绔欑偣淇℃伅
-        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 < staNos.size(); 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();
@@ -220,11 +273,11 @@
         }
 
         // 鏉$爜鎵弿鍣�
-        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.400", (short) (BarcodeList.size() * 10));
+        OperateResultExOne<byte[]> barcodeResult = siemensS7Net.Read("DB101.600", (short) (getBarcodeList().size() * 10));
         if (barcodeResult.IsSuccess) {
-            for (int i = 0; i < BarcodeList.size(); 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, BarcodeList.get(i));
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, getBarcodeList().get(i));
                 if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
                     barcodeThread.setBarcode(barcode);
                 }
@@ -232,11 +285,11 @@
         }
 
         // 澶栧舰妫�娴�
-        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.430", (short) (staNosErrList.size() *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*4, 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]);
@@ -245,17 +298,17 @@
                 staProtocol.setGroupSupportErr(status[5]);
                 staProtocol.setBarcodeErr(status[6]);
                 staProtocol.setWeightErr(status[7]);
-                short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 4 + 2);
+                short goodsHeight = siemensS7Net.getByteTransform().TransInt16(resultErr.Content, i * 6 + 4);
                 staProtocol.setGoodsHeight(goodsHeight);
             }
         }
 
         // 鏁呴殰淇℃伅鍙嶉
-        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.442", (short) (staNos.size() * 4));
+        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB101.400", (short) (getStaNo().size() * 4));
         if (resultErr2.IsSuccess) {
-            for (int i = 0; i < staNos.size(); i++) {
+            for (int i = 0; i < getStaNo().size(); i++) {
                 boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4 + 2, 1);
-                StaProtocol staProtocol = station.get(staNos.get(i)); // 绔欑偣缂栧彿
+                StaProtocol staProtocol = station.get(getStaNo().get(i)); // 绔欑偣缂栧彿
                 staProtocol.setBreakerErr(status[0]);
                 staProtocol.setInfraredErr(status[1]);
                 staProtocol.setOutTimeErr(status[2]);
@@ -275,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());
                 }
@@ -297,6 +350,12 @@
         }
     }
 
+    public void updatePathStatus(int status) {
+        if (this.pathStatus == status) return;
+        this.pathStatus = status;
+        siemensS7Net.Write("DB100.1", (short) status);
+    }
+
     /**
      * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
      */
@@ -305,15 +364,15 @@
             return;
         }
 
-        int address = staNos.indexOf(staProtocol.getSiteId()) * 4;
+        int address = getStaNo().indexOf(staProtocol.getSiteId()) * 6;
 
         OperateResult write;
         OperateResult write1;
         //浠诲姟涓嬪彂娆℃暟
         int writeCount = 0;
         do {
-            write = siemensS7Net.Write("DB100." + address, staProtocol.getWorkNo().shortValue());    // 宸ヤ綔鍙�
-            write1 = siemensS7Net.Write("DB100." + (address + 2), staProtocol.getStaNo());    // 鐩爣绔�
+            write = siemensS7Net.Write("DB100." + (address), staProtocol.getWorkNo());    // 宸ヤ綔鍙�
+            write1 = siemensS7Net.Write("DB100." + (address + 4), staProtocol.getStaNo());    // 鐩爣绔�
             Thread.sleep(200);
             if(write.IsSuccess && write1.IsSuccess){
                 break;

--
Gitblit v1.9.1