From 876db5fee890311a1d7eaea983af20826b817e01 Mon Sep 17 00:00:00 2001
From: TQS <56479841@qq.com>
Date: 星期二, 13 八月 2024 19:33:23 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 1a2bfc5..1236dc9 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -8,6 +8,7 @@
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
+import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasDevp;
 import com.zy.asrs.mapper.BasDevpMapper;
 import com.zy.asrs.service.BasDevpService;
@@ -44,12 +45,18 @@
     private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
     private short heartBeatVal = 1;
     private int barcodeSize = 2;
-    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
+    public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
         add(100);add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);add(109);
         add(110);add(111);
         add(200);add(201);add(202);add(203);add(204);add(205);add(206);add(207);add(208);add(209);
         add(210);add(211);
         add(300);
+    }};
+    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
+        add(112);add(113);add(114);
+    }};
+    public static final ArrayList<Integer> staNos3 = new ArrayList<Integer>() {{
+        add(212);add(214);add(213);
     }};
 
     public boolean charge0;
@@ -70,6 +77,20 @@
      */
     public IoModeType ioModeOf1F = IoModeType.NONE;
     public IoModeType ioModeOf2F = IoModeType.NONE;
+
+    private ArrayList<Integer> getStaNo() {
+        switch (slave.getId()) {
+            case 1:
+                return staNos1;
+            case 2:
+                return staNos2;
+            case 3:
+                return staNos3;
+            default:
+                throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
+        }
+    }
+
 
     @Override
     @SuppressWarnings("InfiniteLoopStatement")
@@ -132,9 +153,10 @@
     private void read() throws InterruptedException {
         // 鏇存柊鍏ュ嚭搴撴ā寮�
         updateIoMode();
-        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 50);
+        ArrayList<Integer> staNos = getStaNo();
+        OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNos.size()*2));
         if (result.IsSuccess) {
-            for (int i = 0; i < 25; i++) {
+            for (int i = 0; i < staNos.size(); i++) {
                 Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
                 StaProtocol staProtocol = station.get(siteId);
                 if (null == staProtocol) {
@@ -146,9 +168,9 @@
             }
         }
         Thread.sleep(200);
-        OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 50);
+        OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) (staNos.size()*2));
         if (result0.IsSuccess) {
-            for (int i = 0; i < 25; i++) {
+            for (int i = 0; i < staNos.size(); i++) {
                 Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
                 StaProtocol staProtocol = station.get(siteId);
                 if (null == staProtocol) {
@@ -160,11 +182,11 @@
             }
         }
         Thread.sleep(200);
-        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.0", (short) 50);
+        OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.0", (short) (staNos.size()*2));
         if (result1.IsSuccess) {
-            for (int i = 0; i < 25; i++) {
+            for (int i = 0; i < staNos.size(); i++) {
                 Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
+                boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i * 2, 1);
                 StaProtocol staProtocol = station.get(siteId);
                 staProtocol.setAutoing(status[0]);  // 鑷姩
                 staProtocol.setLoading(status[1]);  // 鏈夌墿
@@ -177,10 +199,10 @@
 
                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
                     staProtocol.setPakMk(true);
-                }else if (staProtocol.getSiteId().equals(300)){
+                } else if (staProtocol.getSiteId().equals(300)) {
                     BasDevpMapper basDevpMapper = SpringUtils.getBean(BasDevpMapper.class);
                     BasDevp basDevp = basDevpMapper.selectByDevNo(300);
-                    if (!basDevp.getWrkNo().equals(basDevp.getWrkNo1())){
+                    if (!basDevp.getWrkNo().equals(basDevp.getWrkNo1())) {
                         staProtocol.setPakMk(true);
                     }
                 }
@@ -244,6 +266,7 @@
         if (null == staProtocol) {
             return;
         }
+        ArrayList<Integer> staNos = getStaNo();
         int index = staNos.indexOf(staProtocol.getSiteId());
 
         OperateResult writeId,writeDest;
@@ -358,6 +381,7 @@
         if (null == staProtocol || times > 3) {
             return;
         }
+        ArrayList<Integer> staNos = getStaNo();
         int index = staNos.indexOf(staProtocol.getSiteId());
         OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo());    // 宸ヤ綔鍙�
         Thread.sleep(200);

--
Gitblit v1.9.1