From e08b0e5516fb552c99362e474bb6959dab92d90a Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 02 九月 2020 09:53:26 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/DevpThread.java |   50 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/DevpThread.java b/src/main/java/com/zy/core/thread/DevpThread.java
index 0352ad7..07f212a 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,10 +177,14 @@
 //        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 {
-            OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
+            OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
+            log.info("杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
         }
     }
 
@@ -230,23 +240,33 @@
         melsecMcNet.ConnectClose();
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
         DevpSlave slave = new DevpSlave();
-        slave.setIp("192.168.2.125");
+        slave.setIp("192.168.3.65");
+        slave.setPort(6000);
         DevpThread devpThread = new DevpThread(slave);
         devpThread.connect();
-        devpThread.read();
+        OperateResult d1021 = devpThread.melsecMcNet.Write("D102", (short) 234);
+        if (d1021.IsSuccess) {
+            System.out.println("success");
+        }
+        OperateResultExOne<Short> d102 = devpThread.melsecMcNet.ReadInt16("D102");
+        System.out.println(d102.Content);
+//        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();
+//        devpThread.read();
+        System.out.println("绗簩娆¤");
         System.out.println(JSON.toJSONString(devpThread.station));
 
     }

--
Gitblit v1.9.1