From 72ce003daa99f4e36466e7fc146e6c14bfc6438f Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期一, 27 十月 2025 08:32:42 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index e51db88..83db7d4 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -9,14 +9,8 @@
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.entity.BasDevpOpt;
-import com.zy.asrs.entity.BasRgvMap;
-import com.zy.asrs.entity.BasRgvOpt;
-import com.zy.asrs.service.BasDevpOptService;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.asrs.service.BasRgvMapService;
-import com.zy.asrs.service.BasRgvOptService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
 import com.zy.common.utils.News;
 import com.zy.core.DevpThread;
 import com.zy.core.cache.MessageQueue;
@@ -62,7 +56,7 @@
         add(1022);add(1024);
         add(1025);add(1026);add(1028);
         add(1029);add(1031);
-        add(1032);add(1033);add(1035);
+        add(1032);add(1033);add(1034);add(1035);
         add(1036);add(1037);add(1038);
         add(1039);add(1040);add(1041);
         add(1042);add(1043);add(1044);add(1045);add(1046);add(1047);add(1048);add(1050);add(1051);add(1052);add(1053);add(1054);add(1055);add(1056);add(1057);
@@ -219,11 +213,61 @@
                 throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
         }
     }
+    private boolean connectDev = false;
 
     @Override
     @SuppressWarnings("InfiniteLoopStatement")
     public void run() {
-        connect();
+        connectDev = connect();
+        while(!connectDev){
+            try {
+                connectDev = this.connect();
+                Thread.sleep(100);
+            } catch (Exception e){
+
+            }
+        }
+
+        // 鍚姩绾跨▼鑷姩閲嶈繛
+        new Thread(this::devConnect).start();
+        new Thread(this::readStatusDev).start();
+        new Thread(this::writeStatusDev).start();
+    }
+    private void readStatusDev() {
+        while (true) {
+            try {
+                Thread.sleep(50);
+                read();
+
+            } catch (Exception e) {
+                log.error("Dev鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                initSite();
+            }
+
+        }
+
+    }
+    private void devConnect() {
+        while (true) {
+            try {
+                Thread.sleep(1000);
+
+                if(!connectDev){
+                    try {
+                        connectDev = this.connect();
+                        Thread.sleep(100);
+                    } catch (Exception e){
+
+                    }
+                }
+            } catch (Exception e) {
+                log.info("dev杩炴帴澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                initSite();
+//                e.printStackTrace();
+            }
+        }
+    }
+    private void writeStatusDev() {
         while (true) {
             try {
                 int step = 1;
@@ -234,7 +278,7 @@
                 switch (step) {
                     // 璇绘暟鎹�
                     case 1:
-                        read();
+//                        read();
                         break;
                     // 鍐欐暟鎹� ID+鐩爣绔�
                     case 2:
@@ -246,13 +290,55 @@
                 }
                 // 蹇冭烦
 //                heartbeat();
-                Thread.sleep(100);
+                Thread.sleep(400);
             } catch (Exception e) {
-                e.printStackTrace();
+//                e.printStackTrace();
+                try{
+                    log.error("dev鍐欑嚎绋嬪紓甯�"+e.getMessage());
+
+                } catch (Exception e1){
+
+                }
+                log.error("DEV鏁版嵁鍐欏叆绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+
             }
 
         }
+
     }
+//    @Override
+//    @SuppressWarnings("InfiniteLoopStatement")
+//    public void run() {
+//        connect();
+//        while (true) {
+//            try {
+//                int step = 1;
+//                Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
+//                if (task != null) {
+//                    step = task.getStep();
+//                }
+//                switch (step) {
+//                    // 璇绘暟鎹�
+//                    case 1:
+//                        read();
+//                        break;
+//                    // 鍐欐暟鎹� ID+鐩爣绔�
+//                    case 2:
+//                        write((StaProtocol)task.getData());
+//                        log.error("杈撻�佺嚎涓嬪彂鍛戒护锛�"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo());
+//                        break;
+//                    default:
+//                        break;
+//                }
+//                // 蹇冭烦
+////                heartbeat();
+//                Thread.sleep(100);
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//
+//        }
+//    }
     /**
      * 鍒濆鍖栫珯鐐圭姸鎬�
      */
@@ -319,7 +405,7 @@
         OperateResultExOne<byte[]> result4 = null;//1054-1079
         OperateResultExOne<byte[]> result5 = null;//1080-1110
         OperateResultExOne<byte[]> resultErr = null;
-        if(staNoSize == 99){
+        if(staNoSize == 100){
             result1 = siemensS7Net.Read("DB100.0", (short) (2768));//1001-1028
             result2 = siemensS7Net.Read("DB101.0", (short) (1268));//1029-1037
             result3 = siemensS7Net.Read("DB104.0", (short) (1268));//1042-1053
@@ -347,7 +433,7 @@
                     station.put(siteId, staProtocol);
                 }
                 staProtocol.setSiteId(siteId);
-                if (staNoSize == 99) {
+                if (staNoSize == 100) {
                     if (siteId < 1029) {
                         result = result1;
                     } else if (siteId < 1042) {
@@ -406,10 +492,9 @@
                 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);
-                boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + 54, 1);
+                boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 8, 3);
                 boolean loading = false;
                 if(!status1[0])
-//                        && statusErr[2])
                 {
                     loading = true;
                 }
@@ -418,12 +503,71 @@
                 staProtocol.setInEnable(status1[2]); // 鍙叆
                 staProtocol.setOutEnable(status1[2]);// 鍙嚭
                 staProtocol.setErr(status1[6]);
-//                staProtocol.setInEnable(status1[1]); // 鍙叆
-//                staProtocol.setOutEnable(status1[3]);// 鍙嚭
-//                staProtocol.setEmptyMk(status[4]);  // 绌烘澘淇″彿
-//                staProtocol.setFullPlt(status[5]);  // 婊℃墭鐩�
-//                staProtocol.setHigh(status[6]);     // 楂樺簱浣�
-//                staProtocol.setLow(status[7]);      // 浣庡簱浣�
+
+                staProtocol.setPassTimeOut(statusErr[0]);
+                staProtocol.setObjectNoIdError(statusErr[1]);
+                staProtocol.setIdNoObjectError(statusErr[2]);
+                staProtocol.setLmfrError(statusErr[3]);
+                staProtocol.setLiftError(statusErr[4]);
+                staProtocol.setDlfrError(statusErr[5]);
+                staProtocol.setDmfrError(statusErr[6]);
+                staProtocol.setVfdError(statusErr[7]);
+                staProtocol.setSrvError(statusErr[8]);
+                staProtocol.setRes1(statusErr[9]);
+                staProtocol.setRes2(statusErr[10]);
+                staProtocol.setRes3(statusErr[11]);
+                staProtocol.setCommunicationTimeOut(statusErr[12]);
+                staProtocol.setParameterIncompleteError(statusErr[13]);
+                staProtocol.setDataNotClear(statusErr[14]);
+                staProtocol.setSetParameterError(statusErr[15]);
+                staProtocol.setRes4(statusErr[16]);
+                staProtocol.setRes5(statusErr[17]);
+                staProtocol.setDataError(statusErr[18]);
+
+                if( (staProtocol.getPassTimeOut() ||
+                    staProtocol.getObjectNoIdError() ||
+                        staProtocol.getIdNoObjectError() ||
+                        staProtocol.getLmfrError() ||
+                        staProtocol.getLiftError() ||
+                        staProtocol.getDlfrError() ||
+                        staProtocol.getDmfrError() ||
+                        staProtocol.getVfdError() ||
+                        staProtocol.getSrvError() ||
+                        staProtocol.getRes1() ||
+                        staProtocol.getRes2() ||
+                        staProtocol.getRes3() ||
+                        staProtocol.getCommunicationTimeOut() ||
+                        staProtocol.getParameterIncompleteError() ||
+                        staProtocol.getDataNotClear() ||
+                        staProtocol.getSetParameterError() ||
+                        staProtocol.getDataError()) && staProtocol.isWriteMk()
+                ){
+                    staProtocol.setErrorMk(true);//鑻ュ瓨鍦ㄥ紓甯歌Е鍙戝啓鍏�
+                }
+
+                if(     !staProtocol.getPassTimeOut() &&
+                        !staProtocol.getObjectNoIdError() &&
+                        !staProtocol.getIdNoObjectError() &&
+                        !staProtocol.getLmfrError() &&
+                        !staProtocol.getLiftError() &&
+                        !staProtocol.getDlfrError() &&
+                        !staProtocol.getDmfrError() &&
+                        !staProtocol.getVfdError() &&
+                        !staProtocol.getSrvError() &&
+                        !staProtocol.getRes1() &&
+                        !staProtocol.getRes2() &&
+                        !staProtocol.getRes3() &&
+                        !staProtocol.getCommunicationTimeOut() &&
+                        !staProtocol.getParameterIncompleteError() &&
+                        !staProtocol.getDataNotClear() &&
+                        !staProtocol.getSetParameterError() &&
+                        !staProtocol.getDataError()
+                ){
+                    staProtocol.setWriteMk(true);//鏃犲紓甯稿悗鎵嶈兘缁х画鍐欏叆
+                    staProtocol.setErrorMk(false);//鑻ュ瓨鍦ㄥ紓甯歌Е鍙戝啓鍏�
+
+                }
+
 
                 if (!staProtocol.isPakMk() && (!staProtocol.isLoading() || staProtocol.getWorkNo()==0)) {
                     staProtocol.setPakMk(true);
@@ -497,12 +641,27 @@
                 for (Integer siteId : staNos) {
                     StaProtocol staProtocol = station.get(siteId);
                     basDevps.add(staProtocol.toSqlModel());
-                }
+                    if(staProtocol.isWriteMk() && staProtocol.isErrorMk()){
+                        try {
+                            // 鏃ュ織璁板綍寮傚父鎯呭喌
+                            BasDevpErrorLog basDevpErrorLogs = new BasDevpErrorLog();
+                            basDevpErrorLogs = staProtocol.toSqlModelError();
+                            BasDevpErrorLogService basDevpErrorLogService = SpringUtils.getBean(BasDevpErrorLogService.class);
+                            basDevpErrorLogService.insert(basDevpErrorLogs);
+                            staProtocol.setWriteMk(false);
+                        } catch (Exception ignore) {
+                            log.error(ignore.getMessage());
+                        }
+                    }
 
+                }
                 BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+
                 if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
                     throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
                 }
+
+
             } catch (Exception e) {
                 initSite();
                 e.printStackTrace();

--
Gitblit v1.9.1