From 389ed5b1fb5585e66c95e3891ff8b40e02fe1995 Mon Sep 17 00:00:00 2001
From: lsh <1>
Date: 星期四, 07 三月 2024 14:08:53 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 5e9dc63..52c745a 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -125,6 +125,11 @@
                         write((StaProtocol)task.getData());
                         read();
                         break;
+                    // 鍐欐暟鎹� ID+鐩爣绔�
+                    case 4:
+                        writeAgvOk((StaProtocol)task.getData());
+                        read();
+                        break;
                    /* case 3:
                         write2((StaProtocol)task.getData());
                         read();
@@ -229,6 +234,34 @@
             }
         }
 
+        OperateResultExOne<byte[]> resultAgvAndPlc = siemensS7Net.Read("DB102.0", (short) 30);
+        if (resultAgvAndPlc.IsSuccess) {
+            for (int i = 0; i < staNoSize; i++) {
+                int sign =(i+2)/2-1;
+                if ((i+2)%2!=0){
+                    Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
+                    StaProtocol staProtocol = station.get(siteId);
+                    if (null == staProtocol) {
+                        staProtocol = new StaProtocol();
+                        staProtocol.setSiteId(siteId);
+                        station.put(siteId, staProtocol);
+                    }
+                    staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4));     // 鍏佽鍙栬揣
+                    staProtocol.setAgvStartPlace((short)0);   // 鍏佽鏀捐揣
+                    continue;
+                }
+                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
+                StaProtocol staProtocol = station.get(siteId);
+                if (null == staProtocol) {
+                    staProtocol = new StaProtocol();
+                    staProtocol.setSiteId(siteId);
+                    station.put(siteId, staProtocol);
+                }
+                staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6));     // 鍏佽鍙栬揣
+                staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2));   // 鍏佽鏀捐揣
+            }
+        }
+
 
         if (slave.getId() == 1) {
             //鏉$爜
@@ -324,6 +357,83 @@
     /**
      * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
      */
+    private void writeAgvOk(StaProtocol staProtocol) throws InterruptedException {
+        if (null == staProtocol) {
+            return;
+        }
+        ArrayList<Integer> staNos = getStaNo();
+        int index = staNos.indexOf(staProtocol.getSiteId());
+        if (staProtocol.getAgvTypeSign()==0){  //0鍙栬揣
+            switch (staProtocol.getSiteId()){
+                case 100:
+                    index=32;
+                    break;
+                case 101:
+                    index=34;
+                    break;
+                case 102:
+                    index=38;
+                    break;
+                case 103:
+                    index=40;
+                    break;
+                case 104:
+                    index=44;
+                    break;
+                case 105:
+                    index=46;
+                    break;
+                case 106:
+                    index=50;
+                    break;
+                case 107:
+                    index=52;
+                    break;
+                default:
+                    return;
+            }
+        }else {
+            switch (staProtocol.getSiteId()){
+                case 100:
+                    index=30;
+                    break;
+                case 102:
+                    index=36;
+                    break;
+                case 104:
+                    index=42;
+                    break;
+                case 106:
+                    index=48;
+                    break;
+                default:
+                    return;
+            }
+        }
+
+        OperateResult write = null;
+        //浠诲姟涓嬪彂娆℃暟
+        int writeCount = 0;
+        do {
+            write = siemensS7Net.Write("DB102." + index, true);    // 浠诲姟瀹屾垚
+            if(write.IsSuccess){
+                writeCount=6;
+            }else {
+                writeCount++;
+                log.error("鍐欏叆杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠ゅ悗璇诲彇澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
+            }
+        }while (writeCount<5);
+
+        if (!write.IsSuccess) {
+            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)));
+            log.info("杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠や笅鍙戠爜鍨涘畬鎴�  缁欒緭閫佺嚎鍐欎换鍔″畬鎴� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
+        }
+
+
+    }
     private void write(StaProtocol staProtocol) throws InterruptedException {
         if (null == staProtocol) {
             return;

--
Gitblit v1.9.1