From f30358a20ae9a74ee7f6c604a8d102c1b9b24659 Mon Sep 17 00:00:00 2001
From: lsh <lsh123456>
Date: 星期二, 25 六月 2024 16:24:26 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index f3acc49..cd891bc 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -197,6 +197,9 @@
                         Thread.sleep(400);
                         write((StaProtocol)task.getData());
                         break;
+                    case 9:
+                        write9((StaProtocol)task.getData());
+                        break;
                     default:
                         break;
                 }
@@ -316,27 +319,6 @@
                 }
             }
         }
-//        Thread.sleep(200);
-//        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize * 2));
-//        if (result1.IsSuccess) {
-//            for (int i = 0; i < staNoSize; i++) {
-//                Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-//                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
-//                StaProtocol staProtocol = station.get(siteId);
-//                staProtocol.setAutoing(status[0]);  // 鑷姩
-//                staProtocol.setLoading(status[1]);  // 鏈夌墿
-//                staProtocol.setInEnable(status[2]); // 鍙叆
-//                staProtocol.setOutEnable(status[3]);// 鍙嚭
-//                staProtocol.setEmptyMk(status[4]);  // 绌烘澘淇″彿
-//                staProtocol.setFullPlt(status[5]);  // 婊℃墭鐩�
-//                staProtocol.setHigh(status[6]);     // 楂樺簱浣�
-//                staProtocol.setLow(status[7]);      // 浣庡簱浣�
-//
-//                if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
-//                    staProtocol.setPakMk(true);
-//                }
-//            }
-//        }
 
         //鏉$爜鎵弿鍣�
         Thread.sleep(200);
@@ -555,6 +537,86 @@
             log.info("杈撻�佺嚎鍛戒护涓嬪彂鐮佸灈瀹屾垚  缁欒緭閫佸浣� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));
         }
     }
+
+    /**
+     * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
+     */
+    private void write9(StaProtocol staProtocol) throws InterruptedException {
+        if (null == staProtocol) {
+            return;
+        }
+        short resultS1 = staProtocol.getEndRow();
+        OperateResult result1 = null;
+        String resultV1 = "";
+        switch (staProtocol.getSiteId()){
+            case 623:
+                resultV1 = "1800";
+                break;
+            case 624:
+                resultV1 = "1806";
+                break;
+            case 625:
+                resultV1 = "1812";
+                break;
+            case 626:
+                resultV1 = "1818";
+                break;
+            default:
+                return;
+        }
+        result1 = siemensS7Net.Write(resultV1, resultS1);
+        //纭寲缃愪换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
+        try {
+            Thread.sleep(200);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+        int writeCount = 1;
+        do {
+            try{
+                if(!result1.IsSuccess){
+                    log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔�  鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+                    result1 = siemensS7Net.Write(resultV1, resultS1);
+                    Thread.sleep(100);
+                    writeCount++;
+                    continue;
+                }
+                OperateResultExOne<byte[]> resultRead1 = siemensS7Net.Read(resultV1, (short) 2);
+                if (resultRead1.IsSuccess) {
+                    short transInt16 = siemensS7Net.getByteTransform().TransInt16(resultRead1.Content, 0);
+                    if (transInt16 == resultS1 || transInt16 == (short) 2 || transInt16 == (short) 3){
+                        break;
+                    } else {
+                        log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔�  鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+                        result1 = siemensS7Net.Write(resultV1, resultS1);
+                        Thread.sleep(100);
+                        writeCount++;
+                        continue;
+                    }
+                } else {
+                    log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔�  鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+                    result1 = siemensS7Net.Write(resultV1, resultS1);
+                    Thread.sleep(100);
+                    writeCount++;
+                    continue;
+                }
+            }catch (Exception e){
+                log.error("鍐欏叆RGV鏁版嵁鍚庡洖璇诲嚭閿�,寮傚父锛�"+e);
+            }
+            writeCount++;
+        } while (writeCount<6);
+
+        if (!result1.IsSuccess) {
+            staProtocol = station.get(staProtocol.getSiteId());
+            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 updateIoMode() throws InterruptedException {
         if (this.ioModeOf2F != IoModeType.NONE) {

--
Gitblit v1.9.1