From aeaf3e43e425ef0de84c1819f318f20e90471f90 Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期四, 02 十月 2025 11:49:37 +0800
Subject: [PATCH] #和得服务器

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |  180 ++++++++----------------------------------------------------
 1 files changed, 24 insertions(+), 156 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 0a4a413..7926c47 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -27,6 +27,7 @@
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
+import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
@@ -110,6 +111,11 @@
         // 鍏朵粬绔欑偣鍚岀悊缁х画鍔�
     }};
 
+    public static final Map<Integer, Integer> siteErrOffsetMap = new HashMap<Integer, Integer>() {{
+        put(1036, 512);put(1103, 476);put(1047, 452);
+
+    }};
+
     // 鐗规畩绔欑偣闆嗗悎
     private static final Set<Integer> specialSites = new HashSet<>(
             Arrays.asList(1001,1005,1008,1011,1015,1019,1022,1025,1029, 1032,1039));
@@ -129,7 +135,7 @@
         add(3); add(4);
     }};
     public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
-        add(1036);
+        add(1103);add(1036);add(1047);
     }};
 
     private Integer count=0;
@@ -286,6 +292,7 @@
         OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB104.0", (short) (1268));//1042-1053
         OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB103.0", (short) (2824));//1054-1079
         OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB102.0", (short) (3428));//1080-1110
+        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB3.0", (short) (536));//1080-1110
 
 
 
@@ -327,10 +334,24 @@
                 if(specialSites2.contains(siteId)){
                     staProtocol.setStaNo((short)siemensS7Net.getByteTransform().TransInt32(result.Content, offset + offset2 + 48));   // 鐩爣绔�
                     staProtocol.setBarcode(String.valueOf(siemensS7Net.getByteTransform().TransInt32(result.Content, offset + offset2 + 52)));  //鏉$爜
-
+                }
+                if(staNosErrList.contains(siteId)){
+                    Integer offsetErr = siteErrOffsetMap.get(siteId);
+                    boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(resultErr.Content, offsetErr, 2);
+                    staProtocol.setFrontErr(statusErr[2]);
+                    staProtocol.setBackErr(statusErr[3]);
+                    staProtocol.setHighErr(statusErr[5]);
+                    staProtocol.setLeftErr(statusErr[11]);
+                    staProtocol.setRightErr(statusErr[12]);
+// 鍙栧嚭454~458浣嶇疆鐨�5涓瓧鑺�
+                    byte[] bytes = Arrays.copyOfRange(resultErr.Content, (offsetErr + 14), (offsetErr + 19));
+// 杞崲鎴愬瓧绗︿覆锛圫7閲孋HAR鏄崟瀛楄妭缂栫爜锛岀洿鎺SCII鍗冲彲锛�
+                    String plcStr = new String(bytes, StandardCharsets.US_ASCII).trim();
+// 鍒ゆ柇鏄惁绛変簬 "error"
+                    staProtocol.setBarcodeErr("error".equalsIgnoreCase(plcStr));
                 }
 
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3, 2);
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3, 1);
                 staProtocol.setAutoing(!status[0]);  // 鑷姩
                 boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 4, 3);
 
@@ -387,159 +408,6 @@
 //            News.error(JSON.toJSONString(barcode+"绾跨▼"+barcodeId));
 
         }
-
-
-//        BasRgvMapService basRgvMapService = SpringUtils.getBean(BasRgvMapService.class);
-//        RGV灏忚溅1
-//        Thread.sleep(100);
-//        OperateResultExOne<byte[]> resultCar1 = siemensS7Net.Read("DB101.0",(short)36);
-//        if (resultCar1.IsSuccess) {
-//            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(resultCar1.Content, 0) + 1);
-//            if (!Cools.isEmpty(basRgvMap)){
-//                Integer siteId1 = 1;
-//                Integer siteId2 = 2;
-//                StaProtocol staProtocol1 = station.get(siteId1);
-//                StaProtocol staProtocol2 = station.get(siteId2);
-//
-//                if (null == staProtocol1) {
-//                    staProtocol1 = new StaProtocol();
-//                    staProtocol1.setSiteId(siteId1);
-//                    station.put(siteId1, staProtocol1);
-//                }
-//                if (null == staProtocol2) {
-//                    staProtocol2 = new StaProtocol();
-//                    staProtocol2.setSiteId(siteId2);
-//                    station.put(siteId2, staProtocol2);
-//
-//                }
-//                String pos = String.valueOf(getRgvPosI(siemensS7Net.getByteTransform().TransInt32(resultCar1.Content, 4)));
-//                staProtocol1.setAutoing(siemensS7Net.getByteTransform().TransInt16(result.Content, 2) == 0);
-//                staProtocol2.setAutoing(siemensS7Net.getByteTransform().TransInt16(result.Content, 2) == 0);
-//                staProtocol1.setNearbySta(pos);
-//                staProtocol1.setStaNo((short) siemensS7Net.getByteTransform().TransInt32(resultCar1.Content, 28));
-//                staProtocol2.setStaNo((short) siemensS7Net.getByteTransform().TransInt32(resultCar1.Content, 32));
-//                staProtocol1.setWorkNo(siemensS7Net.getByteTransform().TransInt32(resultCar1.Content, 16));
-//                staProtocol2.setWorkNo(siemensS7Net.getByteTransform().TransInt32(resultCar1.Content, 20));
-//                boolean[] status1 = siemensS7Net.getByteTransform().TransBool(resultCar1.Content, 24, 1);
-//                staProtocol1.setLoading(status1[0]);
-//                staProtocol2.setLoading(status1[1]);
-//                //                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 8)));
-//            }
-//        }
-        //RGV灏忚溅2
-//        Thread.sleep(100);
-//        OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB50.212",(short)10);
-//        if (result4.IsSuccess) {
-//            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result4.Content, 0));
-//            if (!Cools.isEmpty(basRgvMap)){
-//                Integer siteId = 2;
-//                StaProtocol staProtocol = station.get(siteId);
-//                if (null == staProtocol) {
-//                    staProtocol = new StaProtocol();
-//                    staProtocol.setSiteId(siteId);
-//                    station.put(siteId, staProtocol);
-//                }
-//                staProtocol.setAutoing(true);
-//                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result4.Content, 8)));
-//            }
-//        }
-
-//        //RGV灏忚溅3
-////        Thread.sleep(100);
-//        OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB50.224",(short)10);
-//        if (result5.IsSuccess) {
-//            BasRgvMap basRgvMap = basRgvMapService.selectByRgvNo((int) siemensS7Net.getByteTransform().TransInt16(result5.Content, 0));
-//            if (!Cools.isEmpty(basRgvMap)){
-//                Integer siteId = 3;
-//                StaProtocol staProtocol = station.get(siteId);
-//                if (null == staProtocol) {
-//                    staProtocol = new StaProtocol();
-//                    staProtocol.setSiteId(siteId);
-//                    station.put(siteId, staProtocol);
-//                }
-//                staProtocol.setAutoing(true);
-//                staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result5.Content, 8)));
-//            }
-//        }
-
-
-
-        //鏉$爜鎵弿鍣�
-//        ArrayList<Integer> barcodeListMat = BarcodeListMat;
-//        OperateResultExOne<byte[]> result2Mat = siemensS7Net.Read("DB103.0", (short) (barcodeListMat.size() * 30));
-//        if (result2Mat.IsSuccess) {
-//            for (int i = 0; i < barcodeListMat.size(); i++) {
-//                Integer barcodeId = barcodeListMat.get(i);
-//                String barcode = siemensS7Net.getByteTransform().TransString(result2Mat.Content,i*30,30, "UTF-8");
-//                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
-//                if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
-//                    barcodeThread.setBarcode(barcode);
-//                }
-//            }
-//        }
-        //澶栧舰妫�娴�
-//        ArrayList<Integer> staNoErrs = staNosErrList;
-//        int staNoErrsSize = staNoErrs.size();
-//        OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB101.800", (short) (staNoErrsSize*8));
-//        if (resultErr.IsSuccess){
-//            for (int i = 0;i<3;i++){
-//                Integer siteId = staNoErrs.get(i); // 绔欑偣缂栧彿
-//                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr.Content, i*4+2, 1);
-//                StaProtocol staProtocol = station.get(siteId);
-//                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]);
-//            }
-//        }
-
-//        OperateResultExOne<byte[]> resultErr2 = siemensS7Net.Read("DB13.2", (short) (staNoSize*4));
-//        if (resultErr2.IsSuccess) {
-//            for (int i = 0; i < staNoSize; i++) {
-//                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-//                boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr2.Content, i*4, 1);
-//                StaProtocol staProtocol = station.get(siteId);
-//                staProtocol.setBreakerErr(status[0]);
-//                staProtocol.setInfraredErr(status[1]);
-//                staProtocol.setOutTimeErr(status[2]);
-//                staProtocol.setSeizeSeatErr(status[3]);
-//                staProtocol.setWrkYgoodsN(status[4]);
-//                staProtocol.setInverterErr(status[5]);
-//                staProtocol.setContactErr(status[6]);
-//                staProtocol.setUpcontactErr(status[7]);
-//
-//            }
-//        }
-//        OperateResultExOne<byte[]> resultErr3 = siemensS7Net.Read("DB13.400", (short) 3);
-//        if (resultErr3.IsSuccess) {
-//            if (staError1 == null){
-//                staError1 = new StaError1();
-//            }
-//            boolean[] status = siemensS7Net.getByteTransform().TransBool(resultErr3.Content, 0, 3);
-//            staError1.setEMERGENCY_Stop_Core(status[0]);
-//            staError1.setEMERGENCY_STOP1(status[1]);
-//            staError1.setEMERGENCY_STOP2(status[2]);
-//            staError1.setEMERGENCY_STOP3(status[3]);
-//            staError1.setEMERGENCY_STOP4(status[4]);
-//
-//            staError1.setDoor_EMERGENCY_STOP1(status[5]);
-//            staError1.setDoor_EMERGENCY_STOP2(status[6]);
-//            staError1.setDoor_EMERGENCY_STOP3(status[7]);
-//            staError1.setDoor_EMERGENCY_STOP4(status[8]);
-//            staError1.setDoor_EMERGENCY_STOP5(status[9]);
-//            staError1.setDoor_EMERGENCY_STOP6(status[10]);
-//
-//            staError1.setDoor_Open_Err1(status[11]);
-//            staError1.setDoor_Open_Err1(status[12]);
-//            staError1.setDoor_Open_Err1(status[13]);
-//            staError1.setDoor_Open_Err1(status[14]);
-//            staError1.setDoor_Open_Err1(status[15]);
-//            staError1.setDoor_Open_Err1(status[16]);
-//
-//        }
 
 
         if (result1.IsSuccess && result2.IsSuccess) {

--
Gitblit v1.9.1