From 0cd7adb27af908b7d0ce0db697f9567d77bcbeb2 Mon Sep 17 00:00:00 2001
From: zhangchao <zc857179121@qq.com>
Date: 星期五, 30 八月 2024 13:44:56 +0800
Subject: [PATCH] 对照协议调整

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |   93 +++++++++++++++++++++++++---------------------
 1 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 6cb08b5..84c4673 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -50,7 +50,7 @@
         add(101);
         add(102);
         add(103);
-        add(104);
+        //add(104);
     }};
 
     public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
@@ -194,7 +194,7 @@
 //        updateIoMode();
         ArrayList<Integer> staNos = getStaNo();
         int staNoSize = staNos.size();
-        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize * 4));
+        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize * 8));
 //        OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB100.2", (short) (staNoSize*2));
         if (result.IsSuccess) {
             for (int i = 0; i < staNoSize; i++) {
@@ -205,19 +205,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));   // 鐩爣绔�
-            }
-        }
+                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i * 8 + 4));   // 鐩爣绔�
 
-        Thread.sleep(200);
-        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB101.6", (short) (staNoSize * 4));
-        if (result1.IsSuccess) {
-            for (int i = 0; i < staNoSize; i++) {
-                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i * 4, 1);
-                StaProtocol staProtocol = station.get(siteId);
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i * 8 + 6, 1);
                 staProtocol.setAutoing(status[0]);  // 鑷姩
                 staProtocol.setLoading(status[1]);  // 鏈夌墿
                 staProtocol.setInEnable(status[2]); // 鍙叆
@@ -226,7 +218,6 @@
                 staProtocol.setFullPlt(status[5]);  // 婊℃墭鐩�
                 staProtocol.setHigh(status[6]);     // 楂樺簱浣�
                 staProtocol.setLow(status[7]);      // 浣庡簱浣�
-
                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                     staProtocol.setPakMk(true);
                 }
@@ -237,8 +228,10 @@
                     //lfd鍏ュ簱鍗拌  褰搒tamp>=2鏃舵墠鍏ュ簱
                     staProtocol.setStamp(staProtocol.getStamp() + 1);
                 }
+
             }
         }
+
 
 //        Thread.sleep(200);
 //        OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 186);
@@ -254,43 +247,57 @@
 //                staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2));   // 鐩爣绔�
 //            }
 //        }
+
         //鏉$爜鎵弿鍣�
         Thread.sleep(200);
-        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.2", (short) (barcodeSize * 8));
+        //ArrayList<Integer> barcodeList = BarcodeList;
+        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.200", (short) (3 * 8));
         if (result2.IsSuccess) {
-            if (slave.getId() == 1) {
-                for (int i = 0; i < barcodeSize / 3; 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)) {
-//                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
-                        barcodeThread.setBarcode(barcode);
-                    }
-                }
-            } else if (slave.getId() == 2) {
-                for (int i = barcodeSize / 3; i < barcodeSize; i++) {
-                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, (i - barcodeSize / 3) * 8, 8, "UTF-8");
-                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
-                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
-//                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
-                        barcodeThread.setBarcode(barcode);
-                    }
-                }
-            } else if (slave.getId() == 3) {
-                for (int i = barcodeSize / 3 + 1; i < barcodeSize; i++) {
-                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, (i - (barcodeSize / 3) * 2) * 8, 8, "UTF-8");
-                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
-                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
-//                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
-                        barcodeThread.setBarcode(barcode);
-                    }
+            for (int i = 0; i < 3; i++) {
+                String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i);
+                if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+                    barcodeThread.setBarcode(barcode);
                 }
             }
         }
+        //鏉$爜鎵弿鍣�
+//        Thread.sleep(200);
+//        OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.2", (short) (barcodeSize * 8));
+//        if (result2.IsSuccess) {
+//            if (slave.getId() == 1) {
+//                for (int i = 0; i < barcodeSize / 3; 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)) {
+////                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
+//                        barcodeThread.setBarcode(barcode);
+//                    }
+//                }
+//            } else if (slave.getId() == 2) {
+//                for (int i = barcodeSize / 3; i < barcodeSize; i++) {
+//                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, (i - barcodeSize / 3) * 8, 8, "UTF-8");
+//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
+//                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+////                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
+//                        barcodeThread.setBarcode(barcode);
+//                    }
+//                }
+//            } else if (slave.getId() == 3) {
+//                for (int i = barcodeSize / 3 + 1; i < barcodeSize; i++) {
+//                    String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, (i - (barcodeSize / 3) * 2) * 8, 8, "UTF-8");
+//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
+//                    if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+////                            && !Cools.isEmpty(barcode) && Cools.isEmpty(barcodeThread.getBarcode())) {
+//                        barcodeThread.setBarcode(barcode);
+//                    }
+//                }
+//            }
+//        }
 
 
         Thread.sleep(200);
-        OperateResultExOne<byte[]> resultError = siemensS7Net.Read("DB101.1", (short) (32));
+        OperateResultExOne<byte[]> resultError = siemensS7Net.Read("DB101.100", (short) (32));
         if (resultError.IsSuccess) {
             ArrayList<Integer> staNoError = new ArrayList<Integer>() {{
                 add(102);
@@ -317,7 +324,7 @@
         }
 
 
-        if (result.IsSuccess && result1.IsSuccess) {
+        if (result.IsSuccess) {
 
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), slave.getId()));
 

--
Gitblit v1.9.1