From 64b19ec9fe5eab3e7be031844c4ee228175d7e54 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 17 三月 2022 10:40:04 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/model/command/SteCommand.java   |    4 ++++
 src/main/java/com/zy/core/thread/SteThread.java           |   47 +++++++++++++++++++++++++++++++----------------
 src/main/java/com/zy/core/model/protocol/SteProtocol.java |    6 +++---
 src/main/resources/application.yml                        |    2 +-
 4 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/zy/core/model/command/SteCommand.java b/src/main/java/com/zy/core/model/command/SteCommand.java
index 6d979bd..1b91911 100644
--- a/src/main/java/com/zy/core/model/command/SteCommand.java
+++ b/src/main/java/com/zy/core/model/command/SteCommand.java
@@ -77,6 +77,10 @@
     // 淇敼纭
     private Short modifyYes;
 
+    /**
+     * 杈撳叆绌挎杞﹁繍琛岀姝� 1杩愯锛�0绂佹
+     */
+    private Short run;
 
     public void setTaskMode(Short taskMode){
         this.taskMode = taskMode;
diff --git a/src/main/java/com/zy/core/model/protocol/SteProtocol.java b/src/main/java/com/zy/core/model/protocol/SteProtocol.java
index 82e95dd..8b0c9d6 100644
--- a/src/main/java/com/zy/core/model/protocol/SteProtocol.java
+++ b/src/main/java/com/zy/core/model/protocol/SteProtocol.java
@@ -47,18 +47,18 @@
     /**
      * 寮傚父鐮�1
      */
-    public Integer alarm;
+    public Short alarm;
 
 
     /**
      * 寮傚父鐮�2
      */
-    public Integer alarm0;
+    public Short alarm0;
 
     /**
      * 鐢垫睜鐢甸噺
      */
-    public Short charge;
+    public Float charge;
 
     /**
      * 婊$數
diff --git a/src/main/java/com/zy/core/thread/SteThread.java b/src/main/java/com/zy/core/thread/SteThread.java
index 787be85..dd6640a 100644
--- a/src/main/java/com/zy/core/thread/SteThread.java
+++ b/src/main/java/com/zy/core/thread/SteThread.java
@@ -142,9 +142,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 +224,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 +249,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 {
@@ -363,19 +371,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 +400,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);
+
     }
 
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index e9d33bf..f38b4ea 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -71,7 +71,7 @@
   ste[0]:
     id: 1
     ip: 10.10.10.10
-    port: 8888
+    port: 502
     rack: 0
     slot: 0
     # 鍋忕Щ閲忥紝褰撳爢鍨涙満绔欑偣鍒楀彿=1鏃讹紝鍋忕Щ閲�=2

--
Gitblit v1.9.1