From d014ca67872527703ef949b6874984df0208f17b Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 17 四月 2023 09:42:36 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/SiemensDevpThread.java |   53 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 497ca67..d22872a 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -15,6 +15,7 @@
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.IoModeType;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.DevpSlave;
 import com.zy.core.model.Task;
@@ -58,6 +59,17 @@
         this.slave = slave;
     }
 
+    /**
+     * 鍏ュ嚭搴撴ā寮�
+     * 0锛氭湭鐭�
+     * 1锛氬叆搴撳惎鍔ㄤ腑
+     * 2.鍏ュ簱妯″紡
+     * 3.鍑哄簱鍚姩涓� 锛堜笉鑳界敓鎴愬叆搴撳伐浣滄。锛�
+     * 4.鍑哄簱妯″紡
+     */
+    public IoModeType ioModeOf1F = IoModeType.NONE;
+    public IoModeType ioModeOf2F = IoModeType.NONE;
+
     @Override
     @SuppressWarnings("InfiniteLoopStatement")
     public void run() {
@@ -76,7 +88,9 @@
                         break;
                     // 鍐欐暟鎹� ID+鐩爣绔�
                     case 2:
-                        write((StaProtocol)task.getData());
+                        write((StaProtocol)task.getData(), 0);
+                        Thread.sleep(300);
+                        read();
                         break;
                     default:
                         break;
@@ -114,6 +128,8 @@
      * 璇诲彇鐘舵�� ====> 鏁村潡plc
      */
     private void read() throws InterruptedException {
+        // 鏇存柊鍏ュ嚭搴撴ā寮�
+        updateIoMode();
         OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 50);
         if (result.IsSuccess) {
             for (int i = 0; i < 25; i++) {
@@ -216,28 +232,47 @@
     /**
      * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
      */
-    private void write(StaProtocol staProtocol) throws InterruptedException {
-        if (null == staProtocol) {
+    private void write(StaProtocol staProtocol, int times) throws InterruptedException {
+        if (null == staProtocol || times > 2) {
             return;
         }
         int index = staNos.indexOf(staProtocol.getSiteId());
         OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo());    // 宸ヤ綔鍙�
-        Thread.sleep(500);
+        Thread.sleep(200);
         OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo());    // 鐩爣绔�
 
         if (!write.IsSuccess || !write1.IsSuccess) {
-            staProtocol = station.get(staProtocol.getSiteId());
-            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
-                staProtocol.setPakMk(true);
-            }
+            MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(2, staProtocol));
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol)));
-            News.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
+            News.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触锛岄噸鏂版坊鍔犱换鍔″埌闃熷垪銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
+            times++;
+            write(staProtocol, times);
+//            staProtocol = station.get(staProtocol.getSiteId());
+//            if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
+//                staProtocol.setPakMk(true);
+//            }
         } else {
             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
             News.info("杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
         }
     }
 
+    // 鏇存柊鍏ュ嚭搴撴ā寮�
+    private void updateIoMode() throws InterruptedException {
+        if (this.ioModeOf1F != IoModeType.NONE) {
+            if (!siemensS7Net.Write("DB100.180", this.ioModeOf1F.id).IsSuccess) {
+                OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎103鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId()));
+                News.error("鍐欏叆杈撻�佺嚎103鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId());
+            }
+        }
+        if (this.ioModeOf2F != IoModeType.NONE) {
+            if (!siemensS7Net.Write("DB100.182", this.ioModeOf2F.id).IsSuccess) {
+                OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎203鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId()));
+                News.error("鍐欏叆杈撻�佺嚎203鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId());
+            }
+        }
+    }
+
     /**
      * 蹇冭烦
      */

--
Gitblit v1.9.1