From c64b495fa07b7d381df66590894109fb672c20f0 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期四, 08 五月 2025 14:57:50 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/RgvThread.java |   73 +++++++++++++++++++++++++++++-------
 1 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index f8cc43d..d354a5b 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -108,6 +108,21 @@
      * 瀹屾垚
      */
     private void taskComplete() {
+        while (true) {
+            try {
+                Thread.sleep(100);
+                OperateResultExOne<byte[]> result = siemensNet.Read("DB100.12", (short) 1);
+                boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 0, 1);
+                if (status[0]){
+                    OperateResult result4 = siemensNet.Write("DB100.12.0", true);
+                }
+            } catch (Exception e) {
+                log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛�" + e.getMessage());
+                initRgv();
+//                e.printStackTrace();
+            }
+
+        }
 
     }
 
@@ -168,6 +183,9 @@
                 if (rgvTaskProtocol.getAvoid() != 0) {
                     continue;
                 }
+                if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){
+                    continue;
+                }
 
                 List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getTakeOrPutTaskProtocol(rgvProtocol.getLoaded());
                 for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
@@ -180,12 +198,22 @@
                                 continue;
                             }
                         }
-                        Thread.sleep(100);
-                        TaskProtocol issued = new TaskProtocol(taskProtocol);
-                        write(issued);
-                        taskProtocol.setIsRunning(taskProtocol.getIsRunning() + 1);
-                        taskProtocolCache.updateTaskProtocol(taskProtocol);
-                        break;
+                        if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
+                                && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
+                            Thread.sleep(100);
+                            TaskProtocol issued = new TaskProtocol(taskProtocol);
+                            write(issued);
+                            taskProtocol.setIsRunning(4);
+                            taskProtocolCache.updateTaskProtocol(taskProtocol);
+                            break;
+                        } else {
+                            Thread.sleep(100);
+                            TaskProtocol issued = new TaskProtocol(taskProtocol,true);
+                            write(issued);
+//                            taskProtocol.setIsRunning(4);
+//                            taskProtocolCache.updateTaskProtocol(taskProtocol);
+                            break;
+                        }
                     }
                 }
             } catch (Exception e) {
@@ -390,7 +418,7 @@
             rgvTaskProtocol = new RgvTaskProtocol();
             rgvTaskProtocol.setRgvNo(slave.getId());
         }
-        rgvTaskProtocol.setAvoid(-1);
+        rgvTaskProtocol.setAvoid(0);
         rgvTaskProtocol.setAvoidingTheDestination(0L);
 
         RgvStatusCache.updateRgvStatus(rgvProtocol);
@@ -425,7 +453,7 @@
      */
     private void readStatus() {
         try {
-            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 34);
+            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 19);
             if (result.IsSuccess) {
                 // 鏋勫缓璁惧鐘舵�佸璞�
                 RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
@@ -433,13 +461,25 @@
                     rgvProtocol = new RgvProtocol();
                     rgvProtocol.setRgvNo(slave.getId());
                 }
-                rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 0));
-                rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 2));
-                rgvProtocol.setRgvPos(siemensNet.getByteTransform().TransUInt32(result.Content, 10));
-                rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 20));
+
+                rgvProtocol.setRgvPos((long)siemensNet.getByteTransform().TransInt32(result.Content, 0));
+                rgvProtocol.setRgvPosDestination((long)siemensNet.getByteTransform().TransInt32(result.Content, 4));
+                if (rgvProtocol.getRgvPosDestination()==0L){
+                    rgvProtocol.setRgvPosDestination(rgvProtocol.getRgvPos());
+                }
+                rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 8));
+                rgvProtocol.setTaskNo((long)siemensNet.getByteTransform().TransInt32(result.Content, 10));
+
+                rgvProtocol.setRgvNo((int)siemensNet.getByteTransform().TransInt16(result.Content, 14));
+                rgvProtocol.setMode(siemensNet.getByteTransform().TransInt16(result.Content, 16));
+//                rgvProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 20));
 //                rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
 //                rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
 //                rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
+
+//                OperateResultExOne<byte[]> result11 = siemensNet.Read("DB100.12", (short) 1);
+                boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 18, 1);
+                rgvProtocol.setLoaded(status[0]? (short)1:(short)0);
 
                 OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), slave.getId()));
 //                // 宸ヤ綅1澶嶄綅淇″彿
@@ -506,9 +546,14 @@
 //        array[2] = taskProtocol.getTaskMode();
 //        array[4] = command.getDestinationStaNo();
 //        array[10] = taskProtocol.getCommand();
-        OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTaskNo());
-        OperateResult result1 = siemensNet.Write("DB100.1", taskProtocol.isDirection()); // 鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級    true:宸�   false:鍙�
+        int taskStatus = taskProtocol.getTaskStatus();
 
+        OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTargetPosition().intValue());
+        OperateResult result1 = siemensNet.Write("DB100.4", (short) taskStatus);
+        OperateResult result2 = siemensNet.Write("DB100.6", taskProtocol.getTaskNo().intValue());
+        OperateResult result3 = siemensNet.Write("DB100.10", taskProtocol.isDirection()? (short) 1 :  (short) 2); // 鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級    true:宸�   false:鍙�
+
+        OperateResult result4 = siemensNet.Write("DB100.12.0", true);
 //        if (taskProtocol.getAckFinish1() == 0) {
 //            short commandFinish = 3;  //宸ヤ綅1銆�2浠诲姟鍚屾椂鍐欏叆
 //            Thread.sleep(100L);

--
Gitblit v1.9.1