From 20e30bcc31223e67c2ef83af69d9a3bb322aba6f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期一, 22 八月 2022 14:29:02 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SteThread.java |   53 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index 787be85..db370d0 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -17,7 +17,6 @@
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.enums.SteStatusType;
-import com.zy.core.enums.SteTaskModeType;
 import com.zy.core.model.SteSlave;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.SteCommand;
@@ -27,7 +26,6 @@
 
 import java.text.MessageFormat;
 import java.util.Date;
-import java.util.Random;
 
 /**
  * shuttle 绌挎杞︾嚎绋�
@@ -142,9 +140,9 @@
                 if (waitingRes.IsSuccess) {
                     steProtocol.setWaiting(waitingRes.Content);
                 }
-                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt32(result.Content, 6));
-                steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt32(result.Content, 8));
-                steProtocol.setCharge(siemensS7Net.getByteTransform().TransInt16(result.Content, 10));
+                steProtocol.setAlarm(siemensS7Net.getByteTransform().TransInt16(result.Content, 6));
+                steProtocol.setAlarm0(siemensS7Net.getByteTransform().TransInt16(result.Content, 8));
+                steProtocol.setCharge(siemensS7Net.getByteTransform().TransSingle(result.Content, 10));
 //                steProtocol.setFullCharge();
 //                steProtocol.setLowCharge();
                 steProtocol.setFeed(siemensS7Net.getByteTransform().TransInt16(result.Content, 14));
@@ -224,9 +222,14 @@
             // 浣滀笟
             if (command.getTaskMode() != 0) {
                 // 1.浠诲姟鍙�
-                OperateResult result0 = siemensS7Net.Write("V1000", command.getTaskNo());
+                OperateResult result0 = siemensS7Net.Write("V998", command.getTaskNo().shortValue());
+                try {
+                    Thread.sleep(200);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
                 // 2.浣滀笟
-                OperateResult result1 = siemensS7Net.Write("V1000", command.getTaskMode());     // todo
+                OperateResult result1 = siemensS7Net.Write("V1000", command.getTaskMode());
                 // 3.纭寮�濮嬩换鍔�
                 if (result0.IsSuccess && result1.IsSuccess) {
                     result = siemensS7Net.Write("V2000.0", true);
@@ -244,14 +247,17 @@
                 } else if (command.getDelete() != null) {
                     result =  siemensS7Net.Write("V2000.3", command.getDelete());
                 // 鏃犳晥鎸囦护
-                } else {
+                } else if (command.getRun() != null) {
+                    result =  siemensS7Net.Write("V1016", command.getRun());
+                    // 鏃犳晥鎸囦护
+                }else {
                     return false;
                 }
             }
 
         // 浠诲姟瀹屾垚
         } else {
-            result = siemensS7Net.Write("D0", true);
+            result = siemensS7Net.Write("V2000.1", true);
         }
 
         try {
@@ -286,9 +292,7 @@
         if (result != null && result.IsSuccess) {
             // 缁存姢鏁版嵁搴撴帓鍒楀眰
             if (!steProtocol.getWaiting()) {
-                this.lastRow = command.getRow().intValue();
-                this.lastBay = command.getBay().intValue();
-                this.lastLev = command.getLev().intValue();
+                this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue());
             }
 
             log.info("绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
@@ -363,19 +367,21 @@
     public static void main(String[] args) throws InterruptedException {
         SteSlave slave = new SteSlave();
         slave.setId(1);
-        slave.setIp("192.168.3.39");
-        slave.setPort(5015);
+        slave.setIp("192.168.2.1");
+        slave.setPort(502);
         SteThread thread = new SteThread(slave);
         thread.connect();
         thread.readStatus();
         System.out.println(JSON.toJSONString(thread.steProtocol));
 
         // 浠诲姟浣滀笟
-        SteCommand command = new SteCommand();
-        command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-        command.setTaskNo(new Random().nextInt(9000)); // 宸ヤ綔鍙�
-        command.setTaskMode(SteTaskModeType.IN_LEFT); // 浠诲姟妯″紡
-        thread.write(command);
+//        SteCommand command = new SteCommand();
+//        command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
+//        Random random = new Random();
+//        int taskNo = random.nextInt(9090);
+//        command.setTaskNo(taskNo); // 宸ヤ綔鍙�
+//        command.setTaskMode(SteTaskModeType.MOVE_LEFT); // 浠诲姟妯″紡
+//        thread.write(command);
 
         // 浠诲姟瀹屾垚
 //        SteCommand command = new SteCommand();
@@ -390,14 +396,19 @@
 
         // 澶嶄綅淇″彿
 //        SteCommand command = new SteCommand();
-//        command.setReset((short) 1);
+//        command.setReset(Boolean.TRUE);
 //        thread.write(command);
 
         // 鍒犻櫎鎸囦护
 //        SteCommand command = new SteCommand();
-//        command.setDelete((short) 1);
+//        command.setDelete(Boolean.TRUE);
 //        thread.write(command);
 
+        // 绌挎杞﹁繍琛岀姝�
+        SteCommand command = new SteCommand();
+        command.setRun((short)0);
+        thread.write(command);
+
     }
 
 }

--
Gitblit v1.9.1