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/DevpThread.java |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java
index 3b57b24..362c164 100644
--- a/src/main/java/com/zy/core/thread/DevpThread.java
+++ b/src/main/java/com/zy/core/thread/DevpThread.java
@@ -104,7 +104,7 @@
     /**
      * 璇诲彇鐘舵�� ====> 鏁村潡plc
      */
-    private void read(){
+    private void read() throws InterruptedException {
         OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30);
         if (result.IsSuccess) {
             for (int i = 1; i <= 8; i++) {
@@ -118,6 +118,7 @@
                 staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40));   // 鐩爣绔�
             }
         }
+        Thread.sleep(100);
         OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64);
         if (result1.IsSuccess) {
             for (int i = 1; i <= 8; i++) {
@@ -127,6 +128,10 @@
                 staProtocol.setInEnable(result1.Content[(i-1)*8+2]); // 鍙叆
                 staProtocol.setOutEnable(result1.Content[(i-1)*8+3]);// 鍙嚭
                 staProtocol.setEmptyMk(result1.Content[(i-1)*8+4]);  // 绌烘澘淇″彿
+
+                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
+                    staProtocol.setPakMk(true);
+                }
             }
         }
         if (result.IsSuccess && result1.IsSuccess) {
@@ -157,11 +162,12 @@
     /**
      * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
      */
-    private void write(StaProtocol staProtocol){
+    private void write(StaProtocol staProtocol) throws InterruptedException {
         if (null == staProtocol) {
             return;
         }
         OperateResult write = melsecMcNet.Write("D10" + staProtocol.getSiteId(), staProtocol.getWorkNo());    // 宸ヤ綔鍙�
+        Thread.sleep(100);
         OperateResult write1 = melsecMcNet.Write("D12" + staProtocol.getSiteId(), staProtocol.getStaNo());    // 鐩爣绔�
 //        boolean[] status = new boolean[8];
 //        status[0] = staProtocol.isAutoing();
@@ -171,6 +177,9 @@
 //        status[4] = staProtocol.isEmptyMk();
 //        OperateResult write2 = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) + 40), status);     //  鐘舵��
         if (!write.IsSuccess || !write1.IsSuccess) {
+            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
+                staProtocol.setPakMk(true);
+            }
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol)));
             log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
         } else {
@@ -230,24 +239,27 @@
         melsecMcNet.ConnectClose();
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
         DevpSlave slave = new DevpSlave();
         slave.setIp("192.168.3.65");
         slave.setPort(6000);
         DevpThread devpThread = new DevpThread(slave);
         devpThread.connect();
         devpThread.read();
+        System.out.println("绗竴娆¤");
         // 鍐�
-        StaProtocol staProtocol = devpThread.getStation().get(1);
-        staProtocol.setWorkNo((short) 232);
-        staProtocol.setStaNo((short) 6);
-        staProtocol.setAutoing(true);
-        staProtocol.setEmptyMk(true);
-        staProtocol.setInEnable(true);
-        devpThread.write(staProtocol);
-        System.out.println("----------------------------------------");
+//        StaProtocol staProtocol = devpThread.getStation().get(1);
+//        staProtocol.setWorkNo((short) 232);
+//        staProtocol.setStaNo((short) 6);
+//        staProtocol.setAutoing(true);
+//        staProtocol.setEmptyMk(true);
+//        staProtocol.setInEnable(true);
+//        devpThread.write(staProtocol);
+//        System.out.println("----------------------------------------");
+        Thread.sleep(400);
         // 璇�
         devpThread.read();
+        System.out.println("绗簩娆¤");
         System.out.println(JSON.toJSONString(devpThread.station));
 
     }

--
Gitblit v1.9.1