From afdfc60107245516aba35a74f7f49eee64f483ad Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期五, 13 六月 2025 09:49:38 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SiemensCrnThread.java |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index ac81663..d55ff16 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -40,6 +40,11 @@
     private CrnProtocol crnProtocol;
     private boolean resetFlag = false;
 
+    public Long sign = System.currentTimeMillis();
+
+    public boolean isRunning = true;
+
+
     /**
      * 鍫嗗灈鏈烘槸鍚﹀湪鍥炲師鐐硅繍鍔ㄤ腑鏍囪
      */
@@ -53,7 +58,7 @@
     @SuppressWarnings("InfiniteLoopStatement")
     public void run() {
         this.connect();
-        while (true) {
+        while (isRunning) {
             try {
                 int step = 1;
                 Task task = MessageQueue.poll(SlaveType.Crn, slave.getId());
@@ -94,7 +99,7 @@
             } catch (Exception e) {
 //                e.printStackTrace();
             }
-
+            sign = System.currentTimeMillis();
         }
     }
 
@@ -149,7 +154,11 @@
      */
     private void readStatus(){
         try {
-            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
+            short len = 56;
+            if (slave.getId() == 1) {
+                len = 58;
+            }
+            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", len);
             if (result.IsSuccess) {
                 if (null == crnProtocol) {
                     crnProtocol = new CrnProtocol();
@@ -176,6 +185,9 @@
                 crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
                 crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
                 crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
+                if (slave.getId() == 1) {
+                    crnProtocol.setCrnLane((int) siemensNet.getByteTransform().TransInt16(result.Content, 56));
+                }
 
                 OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
@@ -234,6 +246,23 @@
             News.error("SiemensCrn"+" - 6"+" - 鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
             return false;
         }
+
+        int writeAck = 0;
+        do {
+            OperateResult resultAck = siemensNet.Write("DB100.0", (short) 0);
+            if (resultAck.IsSuccess){
+                Thread.sleep(200);
+                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 2);
+                short ack = siemensNet.getByteTransform().TransInt16(resultRead.Content, 0);
+                if (ack != 0) {
+                    writeAck++;
+                }else {
+                    News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), "ack澶嶄綅瀹屾垚");
+                    break;
+                }
+            }
+        }while (writeAck <5);
+
 //        convertRow(command);
         command.setCrnNo(slave.getId());
         short[] array = new short[10];
@@ -414,4 +443,9 @@
 
     }
 
+    // 鎻愪緵涓�涓柟娉曟潵鍋滄绾跨▼
+    public void requestStop() {
+        isRunning = false;
+    }
+
 }

--
Gitblit v1.9.1