From 93f9f03112dd065e605417dab4c996a1161722d1 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 13 八月 2020 14:47:44 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/CrnThread.java |   49 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/CrnThread.java b/src/main/java/com/zy/core/thread/CrnThread.java
index 4146e8f..4ac451e 100644
--- a/src/main/java/com/zy/core/thread/CrnThread.java
+++ b/src/main/java/com/zy/core/thread/CrnThread.java
@@ -6,6 +6,7 @@
 import HslCommunication.Profinet.Siemens.SiemensS7Net;
 import com.zy.core.ThreadHandler;
 import com.zy.core.cache.MessageQueue;
+import com.zy.core.enums.CrnTaskModeType;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.CrnSlave;
 import com.zy.core.model.Task;
@@ -28,6 +29,7 @@
 
     public CrnThread(CrnSlave slave) {
         this.slave = slave;
+        this.connect();
     }
 
     @Override
@@ -43,15 +45,26 @@
                 switch (step) {
                     // 璇绘暟鎹�
                     case 1:
-                        readStatus();   // 璇诲彇鐘舵��
+                        readStatus();
                         break;
+                    // 鍐欏叆鏁版嵁
                     case 2:
-                        CrnCommand command = (CrnCommand) task.getData();
-                        break;
-                    case 3:
+                        write((CrnCommand) task.getData());
                         break;
                     // 澶嶄綅
-                    case 4:
+                    case 3:
+                        CrnCommand command = (CrnCommand) task.getData();
+                        command.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
+                        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
+                        command.setAckFinish((short) 1);  // 浠诲姟瀹屾垚纭浣�
+                        command.setTaskMode(CrnTaskModeType.NONE); // 浠诲姟妯″紡:  搴撲綅绉昏浆
+                        command.setSourcePosX((short)0);     // 婧愬簱浣嶆帓
+                        command.setSourcePosY((short)0);     // 婧愬簱浣嶅垪
+                        command.setSourcePosZ((short)0);     // 婧愬簱浣嶅眰
+                        command.setDestinationPosX((short)0);     // 鐩爣搴撲綅鎺�
+                        command.setDestinationPosY((short)0);     // 鐩爣搴撲綅鍒�
+                        command.setDestinationPosZ((short)0);     // 鐩爣搴撲綅灞�
+                        write(command);
                         break;
                     default:
                         break;
@@ -85,7 +98,7 @@
      * 璇诲彇鐘舵��
      */
     private void readStatus(){
-        OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 10);
+        OperateResultExOne<byte[]> result = siemensNet.Read("DB8.18", (short) 46);
         if (result.IsSuccess) {
             if (null == crnProtocol) {
                 crnProtocol = new CrnProtocol();
@@ -118,8 +131,28 @@
     /**
      * 鍐欏叆鏁版嵁
      */
-    private void write(){
-
+    private void write(CrnCommand command){
+        if (null == command) {
+            log.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+            return;
+        }
+        command.setCrnNo(slave.getId());
+        short[] array = new short[9];
+        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();
+        OperateResult result = siemensNet.Write("DB8.0", array);
+        if (result.IsSuccess) {
+            readStatus();
+        } else {
+            log.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
+        }
     }
 
     @Override

--
Gitblit v1.9.1