From 056cf9d0311e1345017ab4c52c5946144fb4ccb8 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期一, 14 十月 2024 15:03:10 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index f107d92..9edf634 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -45,11 +45,19 @@
     private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
     private short heartBeatVal = 1;
     private StaError1 staError1;
+    public static boolean is = true;
 //    public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
 //
 //    }};
     public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
-        add(140);add(141);
+    add(1000);	add(1001);	add(1002);	add(1003);	add(1004);	add(1005);	add(1006);	add(1007);	add(1008);	add(1009);	add(1010);
+    add(1011);	add(1012);	add(1013);	add(1014);	add(1015);	add(1016);	add(1017);	add(1018);	add(1019);	add(1020);	add(1021);
+    add(1022);	add(1023);	add(1024);	add(1025);	add(1026);	add(1027);	add(1028);	add(1029);	add(1030);
+//        add(200);add(201);add(202);
+    }};
+    public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
+       add(1400);
+
 //        add(200);add(201);add(202);
     }};
 
@@ -91,6 +99,8 @@
         switch (slave.getId()) {
             case 1:
                 return staNos1;
+            case 2:
+                return staNos2;
             default:
                 throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
         }
@@ -135,31 +145,43 @@
     private void initSite() {
         count ++;
         ArrayList<Integer> staNos = getStaNo();
+        if(count > 50) {
+            // 绔欑偣缂栧彿
+            for (Integer siteId : staNos) {
+                StaProtocol staProtocol = station.get(siteId);
+                if (null == staProtocol) {
+                    staProtocol = new StaProtocol();
+                    staProtocol.setSiteId(siteId);
+                    station.put(siteId, staProtocol);
+                }
+                staProtocol.setWorkNo(0);     // 宸ヤ綔鍙�
+                staProtocol.setStaNo((short) 0);   // 鐩爣绔�
+                staProtocol.setState((short) 0);  // 妯″紡鐘舵�� 0鍋滄満锛�=1鎵嬪姩锛�=2鑷姩锛�=3鏁呴殰
+                staProtocol.setWorkIo((short) 0);
+                staProtocol.setRequestIo((short) 0);
+                staProtocol.setTrayIo((short) 0);
+                staProtocol.setLocIo((short) 0);
+                staProtocol.setBarcode("-");
+                staProtocol.setWeightIo(0.0);
+                staProtocol.setMode((short) 0);
 
-        // 绔欑偣缂栧彿
-        for (Integer siteId : staNos) {
-            StaProtocol staProtocol = station.get(siteId);
-            if (null == staProtocol) {
-                staProtocol = new StaProtocol();
-                staProtocol.setSiteId(siteId);
-                station.put(siteId, staProtocol);
+                if (!staProtocol.isPakMk() && staProtocol.workType == DevpWorkType.IDLE) {
+                    staProtocol.setPakMk(true);
+                }
             }
-            staProtocol.setWorkNo(0);     // 宸ヤ綔鍙�
-            staProtocol.setStaNo((short) 0);   // 鐩爣绔�
-            staProtocol.setState((short) 0);  // 妯″紡鐘舵�� 0鍋滄満锛�=1鎵嬪姩锛�=2鑷姩锛�=3鏁呴殰
-            staProtocol.setWorkIo((short) 0);
-            staProtocol.setRequestIo((short) 0);
-            staProtocol.setTrayIo((short) 0);
-            staProtocol.setLocIo((short) 0);
-            staProtocol.setBarcode("-");
-            staProtocol.setWeightIo(0.0);
-            staProtocol.setMode((short) 0);
-
-            if (!staProtocol.isPakMk() && staProtocol.workType == DevpWorkType.IDLE) {
-                staProtocol.setPakMk(true);
-            }
+            count = 0;
         }
-        count = 0;
+
+
+    }
+
+    public void initSta(){
+        if (is){
+            for (int i = 1000; i <= 1300; i++) {
+                staNos1.add(i);
+            }
+            is = false;
+        }
 
     }
 
@@ -295,7 +317,7 @@
         int index = staNos.indexOf(staProtocol.getSiteId());
 
         OperateResult write1 = siemensS7Net.Write("DB100." + index*66, staProtocol.getWorkNo());    // 宸ヤ綔鍙�
-        Thread.sleep(200);
+        Thread.sleep(100);
         OperateResult write2 = siemensS7Net.Write("DB100." + (index*66+4), staProtocol.getStaNo());    // 鐩爣绔�
         if(write1.IsSuccess && write2.IsSuccess){
             OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100."+(index*66), (short) 6);
@@ -317,7 +339,9 @@
                     OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100."+(index*66 +6), (short) 2);
                     short mk = siemensS7Net.getByteTransform().TransInt16(result2.Content, 0);
                     if (mk == 2){
-                        OperateResult write4 = siemensS7Net.Write("DB100." + (index*66+6), 0);
+                        OperateResult write5 = siemensS7Net.Write("DB100." + index*66, 0);    // 宸ヤ綔鍙�
+                        OperateResult write6 = siemensS7Net.Write("DB100." + (index*66+4), (short) 0);    // 鐩爣绔�
+                        OperateResult write4 = siemensS7Net.Write("DB100." + (index*66+6), (short) 0);
                         if (write4.IsSuccess){
                             OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
                             News.info("SiemensDevp"+" - 5"+" - 杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}",  slave.getId(), JSON.toJSON(staProtocol));

--
Gitblit v1.9.1