From 6e7005a9c8f0e9c21f2d3a4d77a779381e859ac3 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期六, 11 四月 2026 10:35:09 +0800
Subject: [PATCH] 1

---
 zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 57 insertions(+), 1 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 c425337..370550e 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
@@ -8,6 +8,8 @@
 import com.zy.acs.conveyor.core.constant.StationStatusField;
 import com.zy.acs.conveyor.core.model.StaProtocol;
 import com.zy.acs.conveyor.core.properties.DevpSlave;
+import com.zy.acs.conveyor.core.service.DevpS7Service;
+import com.zy.acs.conveyor.core.service.StationService;
 import com.zy.acs.conveyor.entity.Devp;
 import com.zy.acs.conveyor.service.DevpService;
 import com.zy.acs.conveyor.utils.SpringContextUtil;
@@ -15,6 +17,8 @@
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -74,7 +78,19 @@
      */
     private void read() throws InterruptedException {
         if (siemensS7Net == null) {
+            DevpS7Service devpS7Service = SpringContextUtil.getBean(DevpS7Service.class);
+            if (devpS7Service != null) {
+                siemensS7Net = devpS7Service.get(slave.getId());
+            }
             log.warn("PLC鏈繛鎺ワ紝璺宠繃璇诲彇 [id:{}]", slave.getId());
+            return;
+        }
+        if (station == null) {
+            StationService stationService = SpringContextUtil.getBean(StationService.class);
+            if (stationService != null) {
+                station = stationService.getStationMap(slave.getId());
+            }
+            log.warn("绔欑偣鏈繛鎺ワ紝璺宠繃璇诲彇 [id:{}]", slave.getId());
             return;
         }
 
@@ -99,6 +115,9 @@
 
         // 璇诲彇鏉$爜
         readBarcodes();
+
+        // 绉伴噸
+        readWeight();
 
         // 璇诲彇澶栧舰妫�娴嬮敊璇�
         readDimensionErrors();
@@ -161,9 +180,41 @@
 
             if (!Cools.isEmpty(barcode)) {
                 StaProtocol staProtocol = station.get(barcodeArr.get(i));
+                if (staProtocol == null) {
+                    log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), barcodeArr.get(i));
+                    continue;
+                }
                 staProtocol.setBarcode(barcode);
-                log.info("鏂欑鐮侊細{}", barcode);
+                News.info("鏂欑鐮侊細{}", barcode);
             }
+        }
+    }
+
+    /**
+     * 璇诲彇鏉$爜淇℃伅
+     */
+    private void readWeight() {
+        List<Integer> weightArr = slave.getWeightArr();
+        if (weightArr == null || weightArr.isEmpty()) {
+            return;
+        }
+
+        OperateResultExOne<byte[]> result = siemensS7Net.Read(
+                DeviceField.WEIGHT.buildAddress(),
+                (short) (weightArr.size() * 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;
+            }
+            double weight = siemensS7Net.getByteTransform().TransSingle(result.Content, i * DeviceField.WEIGHT.getByteLength());
+            staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
         }
     }
 
@@ -189,6 +240,10 @@
         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;
+            }
 
             boolean[] status = siemensS7Net.getByteTransform().TransBool(
                     content, i * DeviceField.DIMENSION_WORD.getByteLength(),
@@ -222,6 +277,7 @@
             Integer siteId = staNos.get(i);
             StaProtocol staProtocol = station.get(siteId);
             if (staProtocol == null) {
+                log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), siteId);
                 continue;
             }
 

--
Gitblit v1.9.1