From d251a0234fae2d58ff8a9d92069064617dc0a94b Mon Sep 17 00:00:00 2001
From: 18516761980 <4761516tqsxp>
Date: 星期四, 09 六月 2022 13:36:43 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/MelsecCrnThread.java |  137 ++++++++++++++++++++++++---------------------
 1 files changed, 73 insertions(+), 64 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/MelsecCrnThread.java b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
index 73e1d1b..cb42c1f 100644
--- a/src/main/java/com/zy/core/thread/MelsecCrnThread.java
+++ b/src/main/java/com/zy/core/thread/MelsecCrnThread.java
@@ -43,6 +43,11 @@
     private short heartBeatVal = 1;
     private boolean resetFlag = false;
 
+    /**
+     * 鍫嗗灈鏈烘槸鍚﹀湪鍥炲師鐐硅繍鍔ㄤ腑鏍囪
+     */
+    private boolean backHpFlag = false;
+
     public MelsecCrnThread(CrnSlave slave) {
         this.slave = slave;
     }
@@ -161,6 +166,7 @@
             if (result.IsSuccess) {
                 if (null == crnProtocol) {
                     crnProtocol = new CrnProtocol();
+                    crnProtocol.setCrnNo(slave.getId());
                 }
                 crnProtocol.setMode(melsecMcNet.getByteTransform().TransInt16(result.Content, 0));
                 crnProtocol.setTaskNo(melsecMcNet.getByteTransform().TransInt16(result.Content, 2));
@@ -190,6 +196,9 @@
                 if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
                     log.error("-------------------------------------------绗竴姝ャ�乕鍫嗗灈鏈哄彿锛歿}][宸ヤ綔鍙凤細{}]==>> 鐘舵�佷负90锛岀瓑寰呯‘璁わ紒锛�",slave.getId(),crnProtocol.getTaskNo());
                     if (resetFlag) {
+                        if(crnProtocol.getTaskNo()==9999){
+                            backHpFlag = false;
+                        }
                         CrnCommand crnCommand = new CrnCommand();
                         crnCommand.setAckFinish((short)1);
                         if (write(crnCommand)) {
@@ -230,73 +239,73 @@
             return false;
         }
 
-        OperateResult result = null;
-        try{
-            Integer exeCount=0;
-            do{
-                command.setCrnNo(slave.getId());
-                short[] array = new short[10];
-                array[0] = command.getAckFinish();
-                array[1] = command.getTaskNo();
-                array[2] = command.getTaskMode();
-                array[3] = command.getSourcePosX();
-                array[4] = command.getSourcePosY();
-                array[5] = command.getSourcePosZ();
-                array[6] = command.getDestinationPosX();
-                array[7] = command.getDestinationPosY();
-                array[8] = command.getDestinationPosZ();
-                array[9] = command.getCommand();
-                result = melsecMcNet.Write("D0", array);
-                if(result.IsSuccess) {
-                    if (command.getAckFinish() == 0) {
-                        short commandFinish = 1;
-                        result = melsecMcNet.Write("D9", commandFinish);
-                        if(result.IsSuccess){
-                            //鍐欎换鍔$‘璁よ繑鍥炴垚鍔熷悗锛屾煡璇㈢‘璁や竴娆�
-                            Thread.sleep(200);
-                            OperateResultExOne<byte[]> result1 = melsecMcNet.Read("D9", (short)2);
-                            if(result1.IsSuccess){
-                                short commandVal = melsecMcNet.getByteTransform().TransInt16(result1.Content,2);
-                                if(commandVal==1){
-                                    break;
-                                } else {
-                                    exeCount++;
-                                }
-                            } else{
-                                exeCount++;
-                            }
-                        }else{
-                            exeCount++;
-                        }
-                    }
-                }else{
-                    exeCount++;
-                }
-                Thread.sleep(200);
-            }while(exeCount>3);
-        }catch (Exception e){
-
-        }
-
-//        command.setCrnNo(slave.getId());
-//        short[] array = new short[10];
-//        array[0] = command.getAckFinish();
-//        array[1] = command.getTaskNo();
-//        array[2] = command.getTaskMode();
-//        array[3] = command.getSourcePosX();
-//        array[4] = command.getSourcePosY();
-//        array[5] = command.getSourcePosZ();
-//        array[6] = command.getDestinationPosX();
-//        array[7] = command.getDestinationPosY();
-//        array[8] = command.getDestinationPosZ();
-//        array[9] = command.getCommand();
-//        OperateResult result = melsecMcNet.Write("D0", array);
+//        OperateResult result = null;
+//        try{
+//            Integer exeCount=0;
+//            do{
+//                command.setCrnNo(slave.getId());
+//                short[] array = new short[10];
+//                array[0] = command.getAckFinish();
+//                array[1] = command.getTaskNo();
+//                array[2] = command.getTaskMode();
+//                array[3] = command.getSourcePosX();
+//                array[4] = command.getSourcePosY();
+//                array[5] = command.getSourcePosZ();
+//                array[6] = command.getDestinationPosX();
+//                array[7] = command.getDestinationPosY();
+//                array[8] = command.getDestinationPosZ();
+//                array[9] = command.getCommand();
+//                result = melsecMcNet.Write("D0", array);
+//                if(result.IsSuccess) {
+//                    if (command.getAckFinish() == 0) {
+//                        short commandFinish = 1;
+//                        result = melsecMcNet.Write("D9", commandFinish);
+//                        if(result.IsSuccess){
+//                            //鍐欎换鍔$‘璁よ繑鍥炴垚鍔熷悗锛屾煡璇㈢‘璁や竴娆�
+//                            Thread.sleep(200);
+//                            OperateResultExOne<byte[]> result1 = melsecMcNet.Read("D9", (short)2);
+//                            if(result1.IsSuccess){
+//                                short commandVal = melsecMcNet.getByteTransform().TransInt16(result1.Content,2);
+//                                if(commandVal==1){
+//                                    break;
+//                                } else {
+//                                    exeCount++;
+//                                }
+//                            } else{
+//                                exeCount++;
+//                            }
+//                        }else{
+//                            exeCount++;
+//                        }
+//                    }
+//                }else{
+//                    exeCount++;
+//                }
+//                Thread.sleep(200);
+//            }while(exeCount>3);
+//        }catch (Exception e){
 //
-//        if (command.getAckFinish() == 0) {
-//            short commandFinish = 1;
-//            result = melsecMcNet.Write("D9", commandFinish);
 //        }
 
+        command.setCrnNo(slave.getId());
+        short[] array = new short[10];
+        array[0] = command.getAckFinish();
+        array[1] = command.getTaskNo();
+        array[2] = command.getTaskMode();
+        array[3] = command.getSourcePosX();
+        array[4] = command.getSourcePosY();
+        array[5] = command.getSourcePosZ();
+        array[6] = command.getDestinationPosX();
+        array[7] = command.getDestinationPosY();
+        array[8] = command.getDestinationPosZ();
+        array[9] = command.getCommand();
+        OperateResult result = melsecMcNet.Write("D0", array);
+
+        if (command.getAckFinish() == 0) {
+            short commandFinish = 1;
+            result = melsecMcNet.Write("D9", commandFinish);
+        }
+
         try {
             // 鏃ュ織璁板綍
             BasCrnOptService bean = SpringUtils.getBean(BasCrnOptService.class);

--
Gitblit v1.9.1