From 06fad1864fbe3aa23edd4fd03e27904219588cfb Mon Sep 17 00:00:00 2001
From: 野心家 <1051256694@qq.com>
Date: 星期五, 13 六月 2025 10:33:10 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |  149 ++++++++++++++++++++++---------------------------
 1 files changed, 66 insertions(+), 83 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index a8bde3c..be7d3ac 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -44,19 +44,16 @@
     private short heartBeatVal = 1;
 
     public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
-        add(101);add(102);add(103);add(104);
-        add(201);add(202);add(203);add(204);
-        add(301);add(302);add(303);add(304);add(305);add(306);
+        add(100);add(101);add(102);add(103);
     }};
 
-    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
-        add(401);add(402);
-    }};
+
+    private Integer count=0;
 
     /**
      * 鏉$爜鏁伴噺
      */
-    private int barcodeSize = 3;
+    private int barcodeSize = 1;
 
     /**
      * 鍏ュ嚭搴撴ā寮�
@@ -66,8 +63,10 @@
      * 3.鍑哄簱鍚姩涓� 锛堜笉鑳界敓鎴愬叆搴撳伐浣滄。锛�
      * 4.鍑哄簱妯″紡
      */
+    public IoModeType ioModeOf1F = IoModeType.NONE;
     public IoModeType ioModeOf2F = IoModeType.NONE;
 //    public IoModeType ioMode = IoModeType.NONE;
+    public IoModeType ioModeOf3F = IoModeType.NONE;
     public IoModeType ioModeOf4F = IoModeType.NONE;
 //    public IoModeType ioMode = IoModeType.NONE;
 
@@ -79,8 +78,6 @@
         switch (slave.getId()) {
             case 1:
                 return staNos1;
-            case 2:
-                return staNos2;
             default:
                 throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
         }
@@ -123,26 +120,30 @@
      * 鍒濆鍖栫珯鐐圭姸鎬�
      */
     private void initSite() {
+        count ++;
         ArrayList<Integer> staNos = getStaNo();
-        // 绔欑偣缂栧彿
-        for (Integer siteId : staNos) {
-            StaProtocol staProtocol = station.get(siteId);
-            if (null == staProtocol) {
-                staProtocol = new StaProtocol();
-                staProtocol.setSiteId(siteId);
-                station.put(siteId, staProtocol);
-            }
-            staProtocol.setWorkNo((short) 0);    // ID
-            staProtocol.setAutoing(false);      // 鑷姩
-            staProtocol.setLoading(false);      // 鏈夌墿
-            staProtocol.setInEnable(false);     // 鍙叆
-            staProtocol.setOutEnable(false);    // 鍙嚭
-            staProtocol.setEmptyMk(false);      // 绌烘澘淇″彿
-            staProtocol.setStaNo((short) 0);     // 鐩爣绔�
+        if(count > 10) {
+            // 绔欑偣缂栧彿
+            for (Integer siteId : staNos) {
+                StaProtocol staProtocol = station.get(siteId);
+                if (null == staProtocol) {
+                    staProtocol = new StaProtocol();
+                    staProtocol.setSiteId(siteId);
+                    station.put(siteId, staProtocol);
+                }
+                staProtocol.setWorkNo((short) 0);    // ID
+                staProtocol.setAutoing(false);      // 鑷姩
+                staProtocol.setLoading(false);      // 鏈夌墿
+                staProtocol.setInEnable(false);     // 鍙叆
+                staProtocol.setOutEnable(false);    // 鍙嚭
+                staProtocol.setEmptyMk(false);      // 绌烘澘淇″彿
+                staProtocol.setStaNo((short) 0);     // 鐩爣绔�
 
-            if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
-                staProtocol.setPakMk(true);
+                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
+                    staProtocol.setPakMk(true);
+                }
             }
+            count = 0;
         }
     }
 
@@ -171,10 +172,10 @@
      */
     private void read() throws InterruptedException {
 //        // 鏇存柊鍏ュ嚭搴撴ā寮�
-        updateIoMode();
+//        updateIoMode();
         ArrayList<Integer> staNos = getStaNo();
         int staNoSize = staNos.size();
-        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4));
+        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8));
         if (result.IsSuccess) {
             for (int i = 0; i < staNoSize; i++) {
                 Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
@@ -184,32 +185,11 @@
                     staProtocol.setSiteId(siteId);
                     station.put(siteId, staProtocol);
                 }
-                staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4));     // 宸ヤ綔鍙�
+                staProtocol.setWorkNo((short)siemensS7Net.getByteTransform().TransInt32(result.Content, i*8));     // 宸ヤ綔鍙�
 
-                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4 + 2));   // 鐩爣绔�
-            }
-        }
-//        Thread.sleep(200);
-//        OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 186);
-//        if (result0.IsSuccess) {
-//            for (int i = 0; i < 93; i++) {
-//                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-//                StaProtocol staProtocol = station.get(siteId);
-//                if (null == staProtocol) {
-//                    staProtocol = new StaProtocol();
-//                    staProtocol.setSiteId(siteId);
-//                    station.put(siteId, staProtocol);
-//                }
-//                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2));   // 鐩爣绔�
-//            }
-//        }
-        Thread.sleep(200);
-        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize));
-        if (result1.IsSuccess) {
-            for (int i = 0; i < staNoSize; i++) {
-                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 1);
-                StaProtocol staProtocol = station.get(siteId);
+                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4));   // 鐩爣绔�
+
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2);
                 staProtocol.setAutoing(status[0]);  // 鑷姩
                 staProtocol.setLoading(status[1]);  // 鏈夌墿
                 staProtocol.setInEnable(status[2]); // 鍙叆
@@ -225,25 +205,37 @@
             }
         }
 
-        Thread.sleep(200);
-        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150",(short)(barcodeSize*8));
-        if (result2.IsSuccess) {
-            for (int i = 0; i < barcodeSize; i++) {
-                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
-                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
-                if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
-                    barcodeThread.setBarcode(barcode);
-                }
-            }
+        //澶栧舰妫�娴�
+        OperateResultExOne<byte[]> resultErr1 = siemensS7Net.Read("DB101.702.0", (short) (barcodeSize*1));
+        if(resultErr1.IsSuccess){
+            StaProtocol staProtocol1 = station.get(101);
+            boolean[] status1 = siemensS7Net.getByteTransform().TransBool(resultErr1.Content, 0, 1);
+            staProtocol1.setFrontErr(status1[0]);
+            staProtocol1.setBackErr(status1[1]);
+            staProtocol1.setHighErr(status1[2]);
+            staProtocol1.setLeftErr(status1[3]);
+            staProtocol1.setRightErr(status1[4]);
+            staProtocol1.setWeightErr(status1[5]);
+            staProtocol1.setBarcodeErr(status1[6]);
 
         }
 
-//        OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0");
-//        if (result2.IsSuccess) {
-//            this.ioMode = IoModeType.get(result2.Content);
-//        }
+        Thread.sleep(200);
+        if(slave.getId()==1) {
+            OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.602.0", (short) (barcodeSize * 8));
+            if (result2.IsSuccess) {
+                for (int i = 0; i < barcodeSize; i++) {
+                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
+                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
+                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+                        barcodeThread.setBarcode(barcode);
+                    }
+                }
 
-        if (result.IsSuccess && result1.IsSuccess) {
+            }
+        }
+
+        if (result.IsSuccess) {
 
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
@@ -282,15 +274,14 @@
         ArrayList<Integer> staNos = getStaNo();
         int index = staNos.indexOf(staProtocol.getSiteId());
         short[] array = new short[2];
-        array[0] = staProtocol.getWorkNo();
-        array[1] = staProtocol.getStaNo();
-        OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
+        OperateResult writeResult1 = siemensS7Net.Write("DB100." + index*6,  staProtocol.getWorkNo().intValue());    // 宸ヤ綔鍙�
+        OperateResult writeResult2 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo());    // 鐩爣绔�
 
-//        OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo());    // 宸ヤ綔鍙�
+//        OperateResult write = siemensS7Net.Write("DB100.0" + index*4, staProtocol.getWorkNo());    // 宸ヤ綔鍙�
 //        Thread.sleep(500);
-//        OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo());    // 鐩爣绔�
+//        OperateResult write1 = siemensS7Net.Write("DB100.2" + index*4+2, staProtocol.getStaNo());    // 鐩爣绔�
 
-        if (!write.IsSuccess) {
+        if (!writeResult1.IsSuccess&&!writeResult2.IsSuccess) {
             staProtocol = station.get(staProtocol.getSiteId());
             if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
                 staProtocol.setPakMk(true);
@@ -303,15 +294,7 @@
         }
     }
 
-    // 鏇存柊鍏ュ嚭搴撴ā寮�
-    private void updateIoMode() throws InterruptedException {
-        if (this.ioModeOf2F != IoModeType.NONE) {
-            if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) {
-                OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId()));
-                log.error("鍐欏叆杈撻�佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId());
-            }
-        }
-    }
+
 
     /**
      * 蹇冭烦

--
Gitblit v1.9.1