From 62af9acaccedaea4c4c7efd4e68c8b702cf5a27d Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期六, 22 六月 2024 13:35:02 +0800
Subject: [PATCH] # 捷众二期开发

---
 src/main/java/com/zy/core/thread/SiemensCrnThread.java |  110 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 66 insertions(+), 44 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
index ab70f5b..a410ab6 100644
--- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -5,7 +5,6 @@
 import HslCommunication.Profinet.Siemens.SiemensPLCS;
 import HslCommunication.Profinet.Siemens.SiemensS7Net;
 import com.alibaba.fastjson.JSON;
-import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.BasCrnOpt;
@@ -16,7 +15,9 @@
 import com.zy.core.CrnThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
-import com.zy.core.enums.*;
+import com.zy.core.enums.CrnStatusType;
+import com.zy.core.enums.CrnTaskModeType;
+import com.zy.core.enums.SlaveType;
 import com.zy.core.model.CrnSlave;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.CrnCommand;
@@ -158,7 +159,7 @@
      */
     private void readStatus(){
         try {
-            OperateResultExOne<byte[]> result = siemensNet.Read("DB91.0", (short) 52);
+            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 54);
             if (result.IsSuccess) {
                 if (null == crnProtocol) {
                     crnProtocol = new CrnProtocol();
@@ -175,20 +176,20 @@
                 crnProtocol.setLoaded(siemensNet.getByteTransform().TransInt16(result.Content, 16));
                 crnProtocol.setAlarm(siemensNet.getByteTransform().TransInt16(result.Content, 18));
 
-//                crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
-//                crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
-//                crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
-                crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 34));
-                crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
-                crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 38));
+                crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
+                crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 32));
+                crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
+//                crnProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 34));
+//                crnProtocol.setySpeed(siemensNet.getByteTransform().TransInt16(result.Content, 36));
+//                crnProtocol.setzSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 38));
 
-//                crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
-//                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
-//                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
                 crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
-                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 42));
-                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 44));
-                crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 46));
+                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 44));
+                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
+//                crnProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
+//                crnProtocol.setyDistance(siemensNet.getByteTransform().TransInt16(result.Content, 42));
+//                crnProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 44));
+                crnProtocol.setyDuration(siemensNet.getByteTransform().TransInt16(result.Content, 52));
 
 
 //                crnProtocol.setTemp1(siemensNet.getByteTransform().TransInt16(result.Content, 20));
@@ -201,15 +202,28 @@
                 OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
 
                 // 澶嶄綅淇″彿
-                if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+//                if (!Cools.isEmpty(crnProtocol.getStatusType()) && crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+//                    if (resetFlag) {
+//                        if(crnProtocol.getTaskNo()==9999){
+//                            backHpFlag = false;
+//                        }
+//                        CrnCommand crnCommand = new CrnCommand();
+//                        crnCommand.setAckFinish((short)1);
+//                        if (write(crnCommand)) {
+//                            resetFlag = false;
+//                        }
+//                    }
+//                }
+
+                if (crnProtocol.getStatusType().equals(CrnStatusType.WAITING)) {
+//                    News.error("-------------------------------------------绗竴姝ャ�乕鍫嗗灈鏈哄彿锛歿}, 宸ヤ綔鍙凤細{}, 杞借揣鍙颁俊鍙�:{}]==>> 鐘舵�佷负10锛岀瓑寰呯‘璁わ紒锛�",
+//                            slave.getId(),crnProtocol.getTaskNo(), crnProtocol.getLoaded()==1 ? "鏈夌墿" : "鏃犵墿");
                     if (resetFlag) {
-                        if(crnProtocol.getTaskNo()==9999){
-                            backHpFlag = false;
-                        }
                         CrnCommand crnCommand = new CrnCommand();
                         crnCommand.setAckFinish((short)1);
                         if (write(crnCommand)) {
                             resetFlag = false;
+//                            cmdFlag = true;
                         }
                     }
                 }
@@ -255,27 +269,33 @@
             News.error("SiemensCrn"+" - 6"+" - 鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
             return false;
         }
+        OperateResult result;
 //        convertRow(command);
-        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();
+        if (command.getAckFinish() == 1) {
+            result = siemensNet.Write("DB100.0", (short) 1);
+//            result = siemensNet.Write("DB100.18", 0);
+        } else {
+            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.getSourceStaNo();
 //        array[10] = command.getDestinationStaNo();
-        array[9] = command.getCommand();
-        OperateResult result = siemensNet.Write("DB90.0", array);
+            array[9] = command.getCommand();
+            result = siemensNet.Write("DB100.0", array);
 
-        if (command.getAckFinish() == 0) {
-            short commandFinish = 1;
-            Thread.sleep(100L);
-            result = siemensNet.Write("DB90.18", commandFinish);
+//            if (command.getAckFinish() == 0) {
+//                short commandFinish = 1;
+//                Thread.sleep(100L);
+//                result = siemensNet.Write("DB100.18", commandFinish);
+//            }
         }
 
         try {
@@ -326,7 +346,8 @@
     public static void main(String[] args) throws InterruptedException {
         CrnSlave slave = new CrnSlave();
         slave.setId(1);
-        slave.setIp("192.168.6.9");
+        slave.setIp("10.10.10.10");
+        slave.setPort(0);
         slave.setRack(0);
         slave.setSlot(0);
         SiemensCrnThread crnThread = new SiemensCrnThread(slave);
@@ -337,16 +358,17 @@
 
         // 1.鍏ュ簱 婧愬拰鐩爣閮藉彂
 //        CrnCommand command = new CrnCommand();
-//        command.setCrnNo(1); // 鍫嗗灈鏈虹紪鍙�
-//        command.setTaskNo((short) 0); // 宸ヤ綔鍙�
+////        command.setCrnNo(3); // 鍫嗗灈鏈虹紪鍙�
+//        command.setTaskNo((short) 2); // 宸ヤ綔鍙�
 //        command.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
 //        command.setTaskMode(CrnTaskModeType.PAKIN); // 浠诲姟妯″紡
-//        command.setSourcePosX((short) 1);     // 婧愬簱浣嶆帓
-//        command.setSourcePosY((short) 0);     // 婧愬簱浣嶅垪
-//        command.setSourcePosZ((short) 1);     // 婧愬簱浣嶅眰
-//        command.setDestinationPosX((short) 2);     // 鐩爣搴撲綅鎺�
-//        command.setDestinationPosY((short) 3);     // 鐩爣搴撲綅鍒�
+//        command.setSourcePosX((short) 6);     // 婧愬簱浣嶆帓
+//        command.setSourcePosY((short) 2);     // 婧愬簱浣嶅垪
+//        command.setSourcePosZ((short) 2);     // 婧愬簱浣嶅眰
+//        command.setDestinationPosX((short) 6);     // 鐩爣搴撲綅鎺�
+//        command.setDestinationPosY((short) 0);     // 鐩爣搴撲綅鍒�
 //        command.setDestinationPosZ((short) 1);     // 鐩爣搴撲綅灞�
+//        command.setCommand((short)1);
 //        crnThread.write(command);
 
         // 2.鍑哄簱 婧愬拰鐩爣閮藉彂

--
Gitblit v1.9.1