From 6d99081f3f6e0363b0bd28053e545a8e4589b979 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 09 一月 2026 08:50:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java |  153 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 136 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
index 4bc50fc..543a2bd 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
@@ -17,6 +17,7 @@
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.enums.StationCommandType;
 import com.zy.core.model.CommandResponse;
+import com.zy.core.model.StationObjModel;
 import com.zy.core.model.command.StationCommand;
 import com.zy.core.network.api.ZyStationConnectApi;
 import com.zy.core.network.entity.ZyStationStatusEntity;
@@ -35,7 +36,7 @@
 public class ZyStationV3RealConnect implements ZyStationConnectApi {
 
     private List<ZyStationStatusEntity> statusList;
-    private List<ZyStationStatusEntity> barcodeStatusList;
+    private List<StationObjModel> barcodeOriginList;
     private SiemensS7Net siemensNet;
     private DeviceConfig deviceConfig;
     private RedisUtil redisUtil;
@@ -94,10 +95,7 @@
             if (statusList != null) {
                 statusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId));
             }
-            barcodeStatusList = JSONObject.parseArray(basDevp.getBarcodeStationList(), ZyStationStatusEntity.class);
-            if (barcodeStatusList != null) {
-                barcodeStatusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId));
-            }
+            barcodeOriginList = basDevp.getBarcodeStationList$();
         }
 
         if (siemensNet == null) {
@@ -122,21 +120,94 @@
                 boolean[] status2 = siemensNet.getByteTransform().TransBool(result.Content, i * 8 + 7, 1);
                 statusEntity.setRunBlock(status2[1]);//閲嶆柊瑙勫垝璺嚎
                 statusEntity.setEnableIn(status2[3]);//鍚姩鍏ュ簱
+
+                Integer palletHeight = null;
+                if (status[7]) {
+                    palletHeight = 1;//浣�
+                }
+                if (status2[0]) {
+                    palletHeight = 2;//涓�
+                }
+                if (status[6]) {
+                    palletHeight = 3;//楂�
+                }
+                statusEntity.setPalletHeight(palletHeight);//楂樹綆淇″彿
+
+                statusEntity.setError(0);//榛樿鏃犳姤璀�
             }
         }
 
         // 鏉$爜鎵弿鍣�
-        OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.0", (short) (statusList.size() * 10));
+        OperateResultExOne<byte[]> result2 = siemensNet.Read("DB101.0", (short) (barcodeOriginList.size() * 16));
         if (result2.IsSuccess) {
-            for (int i = 0; i < barcodeStatusList.size(); i++) {
-                ZyStationStatusEntity barcodeEntity = barcodeStatusList.get(i);
-                ZyStationStatusEntity statusEntity = findStatusEntity(barcodeEntity.getStationId());
-                if (statusEntity == null) {
+            for (int i = 0; i < barcodeOriginList.size(); i++) {
+                ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+                if (barcodeEntity == null) {
                     continue;
                 }
-                String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 10 + 2, 8, "UTF-8");
+                String barcode = siemensNet.getByteTransform().TransString(result2.Content, i * 16 + 2, 14, "UTF-8");
                 barcode = barcode.trim();
                 barcodeEntity.setBarcode(barcode);
+            }
+        }
+
+        // 绉伴噸
+        OperateResultExOne<byte[]> result3 = siemensNet.Read("DB102.0", (short) (barcodeOriginList.size() * 4));
+        if (result3.IsSuccess) {
+            for (int i = 0; i < barcodeOriginList.size(); i++) {
+                ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+                if (barcodeEntity == null) {
+                    continue;
+                }
+                double weight = (double) siemensNet.getByteTransform().TransSingle(result3.Content, i * 4);
+                barcodeEntity.setWeight(weight);
+            }
+        }
+
+        // 鎶ヨ淇℃伅
+        OperateResultExOne<byte[]> result4 = siemensNet.Read("DB103.0", (short) (barcodeOriginList.size() * 2));
+        if (result4.IsSuccess) {
+            for (int i = 0; i < barcodeOriginList.size(); i++) {
+                ZyStationStatusEntity barcodeEntity = findStatusEntityByBarcodeIdx(i + 1);
+                if (barcodeEntity == null) {
+                    continue;
+                }
+
+                StringBuilder sb = new StringBuilder();
+                boolean[] status1 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2, 1);
+                boolean[] status2 = siemensNet.getByteTransform().TransBool(result4.Content, i * 2 + 1, 1);
+
+                if(status1[0]){
+                    sb.append("宸﹁秴瀹芥姤璀�;");
+                }
+                if(status1[1]) {
+                    sb.append("鍙宠秴瀹芥姤璀�;");
+                }
+                if(status1[2]) {
+                    sb.append("鍓嶈秴闀挎姤璀�;");
+                }
+                if(status1[3]) {
+                    sb.append("鍚庤秴闀挎姤璀�;");
+                }
+                if(status1[4]) {
+                    sb.append("瓒呴珮鎶ヨ;");
+                }
+                if(status1[5]) {
+                    sb.append("鏈夎揣鎶ヨ锛岀┖鎵樺叆搴撴椂妫�娴嬫墭鐩樹笂鏈夋棤璐х墿;");
+                }
+                if(status1[6]) {
+                    sb.append("閲嶉噺寮傚父鎶ヨ;");
+                }
+                if(status1[7]) {
+                    sb.append("鎵爜寮傚父;");
+                }
+
+                if(sb.length() > 0) {
+                    barcodeEntity.setError(1);
+                }else {
+                    barcodeEntity.setError(0);
+                }
+                barcodeEntity.setErrorMsg(sb.toString());
             }
         }
 
@@ -199,6 +270,46 @@
                 log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
                 commandResponse.setResult(false);
             }
+        } else if (command.getCommandType().equals(StationCommandType.WRITE_INFO)) {
+            int enableCommandIdx = -1;
+            while (true) {
+                enableCommandIdx = getEnableCommandIdx(command.getTaskNo());
+                if(enableCommandIdx == -1) {
+                    try {
+                        Thread.sleep(300);
+                    }catch (Exception e) {}
+                }else {
+                    break;
+                }
+                tryCount++;
+                if (tryCount > maxTryCount) {
+                    commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
+                    return commandResponse;
+                }
+            }
+
+            short[] data = new short[21];
+            data[0] = command.getTargetStaNo().shortValue();
+            data[1] = command.getTargetStaNo().shortValue();
+
+            OperateResult writeTask = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength), command.getTaskNo());
+            try {
+                Thread.sleep(50);
+            }catch (Exception e) {}
+
+            OperateResult writeData = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 4), data);
+            try {
+                Thread.sleep(200);
+            }catch (Exception e) {}
+            OperateResult writeConfirm = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 46), (short) 1);
+
+            if(writeTask.IsSuccess &&  writeData.IsSuccess &&  writeConfirm.IsSuccess) {
+                log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆備换鍔″彿={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+                commandResponse.setResult(true);
+            }else {
+                log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傜珯鐐圭紪鍙�={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
+                commandResponse.setResult(false);
+            }
         }
         return commandResponse;
     }
@@ -231,10 +342,18 @@
         return new byte[0];
     }
 
-    private ZyStationStatusEntity findStatusEntity(Integer stationId) {
-        for (ZyStationStatusEntity statusEntity : statusList) {
-            if (statusEntity.getStationId().equals(stationId)) {
-                return statusEntity;
+    private ZyStationStatusEntity findStatusEntityByBarcodeIdx(Integer barcodeIdx) {
+        Integer stationId = null;
+        for (StationObjModel stationObjModel : barcodeOriginList) {
+            if (stationObjModel.getBarcodeIdx().equals(barcodeIdx)) {
+                stationId = stationObjModel.getStationId();
+                break;
+            }
+        }
+
+        for (ZyStationStatusEntity zyStationStatusEntity : statusList) {
+            if(zyStationStatusEntity.getStationId().equals(stationId)) {
+                return zyStationStatusEntity;
             }
         }
         return null;
@@ -243,9 +362,9 @@
     private int getEnableCommandIdx(int taskNo) {
         int useIdx = -1;
         for (int i = 0; i < taskAddressLimit; i++) {
-            OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 2);
+            OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 4);
             OperateResultExOne<byte[]> resultStatus = siemensNet.Read("DB23." + (i * taskAddressLength + 46), (short) 2);
-            if(resultTask.IsSuccess && resultStatus.IsSuccess) {
+            if(!resultTask.IsSuccess || !resultStatus.IsSuccess) {
                 continue;
             }
 

--
Gitblit v1.9.1