From 818fdd469e2ed47c9e02e06fcb4c7dc791977a0b Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期一, 13 四月 2026 10:07:32 +0800
Subject: [PATCH] 1

---
 zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java |   99 +++++++++++++++++++++++++++++--------------------
 1 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
index 370550e..9ef89c7 100644
--- a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
+++ b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -109,7 +109,7 @@
 
         byte[] content = result.Content;
         for (int i = 0; i < staNoSize; i++) {
-            StaProtocol staProtocol = station.get(staNos.get(staNoSize));
+            StaProtocol staProtocol = station.get(staNos.get(i));
             parseStationStatus(content, i, staProtocol);
         }
 
@@ -134,7 +134,7 @@
      */
     private void parseStationStatus(byte[] content, int index, StaProtocol staProtocol) {
         int offset = index * StationStatusField.ALL.getByteLength();
-        staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(content, offset));
+        staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(content, offset + StationStatusField.TASK_NUMBER.getOffset()));
         staProtocol.setStaNo((int) siemensS7Net.getByteTransform().TransInt16(
                 content, offset + StationStatusField.FINAL_TARGET.getOffset()));
 
@@ -158,14 +158,13 @@
      * 璇诲彇鏉$爜淇℃伅
      */
     private void readBarcodes() {
-        List<Integer> barcodeArr = slave.getBarcodeArr();
-        if (barcodeArr == null || barcodeArr.isEmpty()) {
+        if (slave.getBarcode() == null || !slave.getBarcode()) {
             return;
         }
 
         OperateResultExOne<byte[]> result = siemensS7Net.Read(
                 DeviceField.BARCODE.buildAddress(),
-                (short) (barcodeArr.size() * DeviceField.BARCODE.getByteLength()));
+                (short) (DeviceField.BARCODE.getByteLength() * DeviceField.BARCODE.getArrLength()));
 
         if (!result.IsSuccess) {
             log.warn("璇诲彇鏉$爜澶辫触 [id:{}]", slave.getId());
@@ -173,15 +172,18 @@
         }
 
         byte[] content = result.Content;
-        for (int i = 0; i < barcodeArr.size(); i++) {
+        for (int i = 0; i < DeviceField.BARCODE.getArrLength(); i++) {
+            int[] seg = DeviceField.BARCODE.getSeg();
+            Short staNo = siemensS7Net.getByteTransform().TransInt16(
+                    content, seg[0] + i * DeviceField.BARCODE.getByteLength());
             String barcode = siemensS7Net.getByteTransform().TransString(
-                    content, i * DeviceField.BARCODE.getByteLength(),
-                    DeviceField.BARCODE.getByteLength(), "UTF-8");
+                    content, seg[1] + i * DeviceField.BARCODE.getByteLength(),
+                    DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8");
 
-            if (!Cools.isEmpty(barcode)) {
-                StaProtocol staProtocol = station.get(barcodeArr.get(i));
+            if (!Cools.isEmpty(barcode) && staNo != null) {
+                StaProtocol staProtocol = station.get(staNo);
                 if (staProtocol == null) {
-                    log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), barcodeArr.get(i));
+                    log.warn("鎵爜绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
                     continue;
                 }
                 staProtocol.setBarcode(barcode);
@@ -191,30 +193,36 @@
     }
 
     /**
-     * 璇诲彇鏉$爜淇℃伅
+     * 璇诲彇閲嶉噺淇℃伅
      */
     private void readWeight() {
-        List<Integer> weightArr = slave.getWeightArr();
-        if (weightArr == null || weightArr.isEmpty()) {
+        if (slave.getWeight() == null || !slave.getWeight()) {
             return;
         }
 
         OperateResultExOne<byte[]> result = siemensS7Net.Read(
                 DeviceField.WEIGHT.buildAddress(),
-                (short) (weightArr.size() * DeviceField.WEIGHT.getByteLength()));
+                (short) (DeviceField.WEIGHT.getArrLength() * DeviceField.WEIGHT.getByteLength()));
 
         if (!result.IsSuccess) {
             log.warn("璇诲彇閲嶉噺澶辫触 [id:{}]", slave.getId());
             return;
         }
-        for (int i = 0; i < weightArr.size(); i++) {
-            StaProtocol staProtocol = station.get(weightArr.get(i));
-            if (staProtocol == null) {
-                log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), weightArr.get(i));
-                continue;
+        byte[] content = result.Content;
+        for (int i = 0; i < DeviceField.WEIGHT.getArrLength(); i++) {
+            int[] seg = DeviceField.WEIGHT.getSeg();
+            Short staNo = siemensS7Net.getByteTransform().TransInt16(
+                    content, seg[0] + i * DeviceField.WEIGHT.getByteLength());
+            Double weight = (double) siemensS7Net.getByteTransform().TransSingle(
+                    content, seg[1] + i * DeviceField.WEIGHT.getByteLength());
+            if (!Cools.isEmpty(weight) && staNo != null) {
+                StaProtocol staProtocol = station.get(staNo);
+                if (staProtocol == null) {
+                    log.warn("绉伴噸绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
+                    continue;
+                }
+                staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
             }
-            double weight = siemensS7Net.getByteTransform().TransSingle(result.Content, i * DeviceField.WEIGHT.getByteLength());
-            staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
         }
     }
 
@@ -222,14 +230,13 @@
      * 璇诲彇澶栧舰妫�娴嬮敊璇�
      */
     private void readDimensionErrors() {
-        List<Integer> staNosError = slave.getStaNosError();
-        if (staNosError == null || staNosError.isEmpty()) {
+        if (slave.getStaNosError() == null || !slave.getStaNosError()) {
             return;
         }
 
         OperateResultExOne<byte[]> result = siemensS7Net.Read(
                 DeviceField.DIMENSION_WORD.buildAddress(),
-                (short) (staNosError.size() * DeviceField.DIMENSION_WORD.getByteLength()));
+                (short) (DeviceField.DIMENSION_WORD.getArrLength() * DeviceField.DIMENSION_WORD.getByteLength()));
 
         if (!result.IsSuccess) {
             log.warn("璇诲彇澶栧舰妫�娴嬮敊璇け璐� [id:{}]", slave.getId());
@@ -237,25 +244,35 @@
         }
 
         byte[] content = result.Content;
-        for (int i = 0; i < staNosError.size(); i++) {
-            Integer siteId = staNosError.get(i);
-            StaProtocol staProtocol = station.get(siteId);
-            if (staProtocol == null){
-                log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNosError.get(i));
-                continue;
+        for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) {
+            int[] seg = DeviceField.DIMENSION_WORD.getSeg();
+            Short staNo = siemensS7Net.getByteTransform().TransInt16(
+                    content, seg[0]);
+            if (staNo != null) {
+                StaProtocol staProtocol = station.get(staNo);
+                if (staProtocol == null) {
+                    log.warn("寮傚父绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
+                    continue;
+                }
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(
+                        content, seg[1] + i * DeviceField.DIMENSION_WORD.getByteLength(),
+                        1);
+//鏈娇鐢紝棰勭暀
+//                boolean[] status1 = siemensS7Net.getByteTransform().TransBool(
+//                        content, seg[1]+i * DeviceField.DIMENSION_WORD.getByteLength()+1,
+//                        1);
+
+                staProtocol.setLeftErr(status[0]);
+                staProtocol.setRightErr(status[1]);
+                staProtocol.setFrontErr(status[2]);
+                staProtocol.setBackErr(status[3]);
+                staProtocol.setHighErr(status[4]);
+                staProtocol.setLoadErr(status[5]);
+                staProtocol.setWeightErr(status[6]);
+                staProtocol.setBarcodeErr(status[7]);
             }
 
-            boolean[] status = siemensS7Net.getByteTransform().TransBool(
-                    content, i * DeviceField.DIMENSION_WORD.getByteLength(),
-                    DeviceField.DIMENSION_WORD.getByteLength());
 
-            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.setBarcodeErr(status[6]);
         }
     }
 

--
Gitblit v1.9.1