From 123a6f57a1e52980b323de65e5642148e4348ff3 Mon Sep 17 00:00:00 2001
From: yxFwq <1>
Date: 星期二, 10 六月 2025 15:04:53 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SteThread.java |   87 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index 223aa17..0682039 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -44,6 +44,7 @@
     private SteProtocol steProtocol;
     private short heartBeatVal = 1;
     private boolean resetFlag = false;
+    private boolean connectSte = false;
 
     public SteThread(SteSlave slave) {
         this.slave = slave;
@@ -52,7 +53,31 @@
     @Override
     @SuppressWarnings("InfiniteLoopStatement")
     public void run() {
-        this.connect();
+        connectSte = this.connect();
+        while(!connectSte){
+            try {
+                connectSte = this.connect();
+                Thread.sleep(100);
+            } catch (Exception e){
+
+            }
+        }
+
+        // 鍚姩绾跨▼鑷姩閲嶈繛
+        new Thread(this::steConnect).start();
+
+        // 鍚姩璇绘暟鎹嚎绋�
+        new Thread(this::readStatusSte).start();
+
+        // 鍚姩浠诲姟涓嬪彂绾跨▼
+        new Thread(this::taskIssued).start();
+
+    }
+
+    /**
+     * 浠诲姟涓嬪彂
+     */
+    private void taskIssued() {
         while (true) {
             try {
                 int step = 1;
@@ -63,7 +88,7 @@
                 switch (step) {
                     // 璇绘暟鎹�
                     case 1:
-                        readStatus();
+//                        readStatus();
                         break;
                     // 鍐欏叆鏁版嵁
                     case 2:
@@ -74,12 +99,53 @@
                 }
                 // 蹇冭烦
 //                heartbeat();
-                Thread.sleep(500);
+                Thread.sleep(50);
             } catch (Exception e) {
-                e.printStackTrace();
+                log.error("STE鍐欑嚎绋嬪紓甯�"+e.getMessage());
+
+//                e.printStackTrace();
             }
 
         }
+    }
+
+    private void steConnect() {
+        while (true) {
+            try {
+                Thread.sleep(1000);
+                if(!connectSte){
+                    try {
+                        connectSte = this.connect();
+                        Thread.sleep(100);
+                    } catch (Exception e){
+
+                    }
+                }
+            } catch (Exception e) {
+                log.error("ste杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                initSte();
+//                e.printStackTrace();
+            }
+        }
+    }
+
+    private void readStatusSte() {
+        while (true) {
+            try {
+                Thread.sleep(50);
+//                System.out.println("璇荤嚎绋�"+ slave.getId());
+
+                readStatus();
+
+            } catch (Exception e) {
+                log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+
+                initSte();
+//                e.printStackTrace();
+            }
+
+        }
+
     }
 
     /**
@@ -123,7 +189,7 @@
      */
     private void readStatus(){
         try {
-            OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) 27);
+            OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) 28);
             if (result.IsSuccess) {
                 if (null == steProtocol) {
                     steProtocol = new SteProtocol();
@@ -155,8 +221,8 @@
 
                 boolean[] status2 = siemensS7Net.getByteTransform().TransBool(result.Content, 27, 1);
 
-                steProtocol.setChargeStatus(status[0]?(short)1:(short)0);
-                steProtocol.setTrack(status[1]?(short)1:(short)0);
+                steProtocol.setChargeStatus(status2[0]?(short)1:(short)0);
+                steProtocol.setTrack(status2[1]?(short)1:(short)0);
 
 //                steProtocol.setLoad(status2[6]?(short)1:(short)0);
                 steProtocol.setLoad(status2[7]?(short)1:(short)0);
@@ -218,6 +284,8 @@
         }
         command.setSteNo(slave.getId());
         OperateResult result = null;
+        News.error("绌挎杞﹀啓鍏ュ懡浠�"+JSON.toJSONString(command));
+
         // 寮�濮嬩换鍔�
         if (!command.getComplete()) {
             //缁勭粐浠诲姟鍓嶏紝鍏堟竻绌哄啓浠诲姟纭浣嶏紝浠ュ強浠诲姟瀹屾垚纭浣�
@@ -226,11 +294,12 @@
             siemensS7Net.Write("DB100.12", (short) 0);//璧峰鐐逛綅
             siemensS7Net.Write("DB100.14", (short) 0);//鐩殑鐐逛綅
             siemensS7Net.Write("DB100.16.0", false);//浠诲姟寮�濮嬬‘璁や綅
+            siemensS7Net.Write("DB100.16.1", false);//浠诲姟瀹屾垚纭浣�
 //            siemensS7Net.Write("DB100.18", (short) 0);//纭寲缃愬彿
             // 1.浠诲姟鍙�
             OperateResult result0 = siemensS7Net.Write("DB100.2", command.getTaskNo().shortValue());
             try {
-                Thread.sleep(200);
+                Thread.sleep(50);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
@@ -246,7 +315,7 @@
                     result = siemensS7Net.Write("DB100.16.0", true);
 
                     try {
-                        Thread.sleep(300);
+                        Thread.sleep(50);
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }

--
Gitblit v1.9.1