From c422d0d7da0d26f39cd40f9070311ffbb2f9c009 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <xltys1995>
Date: 星期四, 27 八月 2020 18:32:03 +0800
Subject: [PATCH] #v2.0

---
 src/main/java/com/zy/core/thread/CrnThread.java |   85 ++++++++++++++++++++++++++++--------------
 1 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java
index 73e2b60..d9ef282 100644
--- a/src/main/java/com/zy/core/thread/CrnThread.java
+++ b/src/main/java/com/zy/core/thread/CrnThread.java
@@ -12,6 +12,7 @@
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
+import com.zy.core.enums.CrnStatusType;
 import com.zy.core.enums.CrnTaskModeType;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.CrnSlave;
@@ -35,6 +36,7 @@
     private MelsecMcNet melsecMcNet;
     private CrnSlave slave;
     private CrnProtocol crnProtocol;
+    private boolean resetFlag = false;
 
     public CrnThread(CrnSlave slave) {
         this.slave = slave;
@@ -178,13 +180,21 @@
 
         OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
+//        if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+//            if (resetFlag) {
+//                if (melsecMcNet.Write("D2218", 1).IsSuccess) {
+//                    resetFlag = false;
+//                }
+//            }
+//        }
+
         // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
-        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
-        BasCrnp basCrnp = new BasCrnp();
-        basCrnp.setCrnNo(slave.getId());
-        if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
-            log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
-        }
+//        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
+//        BasCrnp basCrnp = new BasCrnp();
+//        basCrnp.setCrnNo(slave.getId());
+//        if (!basCrnpService.updateById(crnProtocol.toSqlModel(basCrnp))){
+//            log.error("鍫嗗灈鏈簆lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+//        }
 
     }
 
@@ -199,15 +209,33 @@
         command.setCrnNo(slave.getId());
         /* 鏂规硶 1 */
         do {
-            if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2216", command.getTaskMode()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2214", command.getSourcePosX()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2212", command.getSourcePosY()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2210", command.getSourcePosZ()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2208", command.getDestinationPosX()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2204", command.getDestinationPosY()).IsSuccess) { break; }
-            if (!melsecMcNet.Write("D2202", command.getDestinationPosZ()).IsSuccess) { break; }
+            if (command.getDestinationPosZ() != null) {
+                if (!melsecMcNet.Write("D2202", command.getDestinationPosZ()).IsSuccess) { break; }
+            }
+            if (command.getDestinationPosY() != null) {
+                if (!melsecMcNet.Write("D2204", command.getDestinationPosY()).IsSuccess) { break; }
+            }
+            if (command.getDestinationPosX() != null) {
+                if (!melsecMcNet.Write("D2208", command.getDestinationPosX()).IsSuccess) { break; }
+            }
+            if (command.getSourcePosZ() != null) {
+                if (!melsecMcNet.Write("D2210", command.getSourcePosZ()).IsSuccess) { break; }
+            }
+            if (command.getSourcePosY() != null) {
+                if (!melsecMcNet.Write("D2212", command.getSourcePosY()).IsSuccess) { break; }
+            }
+            if (command.getDestinationPosX() != null) {
+                if (!melsecMcNet.Write("D2214", command.getSourcePosX()).IsSuccess) { break; }
+            }
+            if (command.getTaskMode() != null) {
+                if (!melsecMcNet.Write("D2216", command.getTaskMode()).IsSuccess) { break; }
+            }
+            if (command.getTaskNo() != null) {
+                if (!melsecMcNet.Write("D2217", command.getTaskNo()).IsSuccess) { break; }
+            }
+            if (command.getAckFinish() != null) {
+                if (!melsecMcNet.Write("D2218", command.getAckFinish()).IsSuccess) { break; }
+            }
 
             System.out.println(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
@@ -262,7 +290,6 @@
         crnThread.connect();
         crnThread.readStatus();
         System.out.println(JSON.toJSONString(crnThread.crnProtocol));
-        Thread.sleep(3000L);
 
         // 1.鍏ュ簱 婧愬拰鐩爣閮藉彂
 //        CrnCommand command = new CrnCommand();
@@ -335,19 +362,19 @@
 //        command.setDestinationPosZ((short) 0);     // 鐩爣搴撲綅灞�
 //        crnThread.write(command);
 
-//        // 7.鍧愭爣绉昏   鐩爣鍙�   pass
-//        CrnCommand command = new CrnCommand();
-//        command.setCrnNo(1); // 鍫嗗灈鏈虹紪鍙�
-//        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
-//        command.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
-//        command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 浠诲姟妯″紡
-//        command.setSourcePosX((short) 0);     // 婧愬簱浣嶆帓
-//        command.setSourcePosY((short) 0);     // 婧愬簱浣嶅垪
-//        command.setSourcePosZ((short) 0);     // 婧愬簱浣嶅眰
-//        command.setDestinationPosX((short) 2);     // 鐩爣搴撲綅鎺�
-//        command.setDestinationPosY((short) 1);     // 鐩爣搴撲綅鍒�
-//        command.setDestinationPosZ((short) 1);     // 鐩爣搴撲綅灞�
-//        crnThread.write(command);
+        // 7.鍧愭爣绉昏   鐩爣鍙�   pass
+        CrnCommand command = new CrnCommand();
+        command.setCrnNo(1); // 鍫嗗灈鏈虹紪鍙�
+        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
+        command.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
+        command.setTaskMode(CrnTaskModeType.OFFSET_MOVE); // 浠诲姟妯″紡
+        command.setSourcePosX((short) 0);     // 婧愬簱浣嶆帓
+        command.setSourcePosY((short) 0);     // 婧愬簱浣嶅垪
+        command.setSourcePosZ((short) 0);     // 婧愬簱浣嶅眰
+        command.setDestinationPosX((short) 1);     // 鐩爣搴撲綅鎺�
+        command.setDestinationPosY((short) 3);     // 鐩爣搴撲綅鍒�
+        command.setDestinationPosZ((short) 3);     // 鐩爣搴撲綅灞�
+        crnThread.write(command);
 
         // 鍙湁鍑虹幇鎸囧畾寮傚父鎵嶈繘琛屽浣�
 //        if (crnThread.crnProtocol.getCrnError2().leftTakeNoneErr

--
Gitblit v1.9.1