From b4ff04d7dd22f0e48bf386cd422e885aef08fed7 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期四, 22 五月 2025 15:03:10 +0800
Subject: [PATCH] OPC通讯修改为S7通讯

---
 hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OPCPlcSlicecage.java |   74 +++++++++++++++++++++++++++---------
 1 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OPCPlcSlicecage.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OPCPlcSlicecage.java
index 54bf769..0277d2d 100644
--- a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OPCPlcSlicecage.java
+++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/OPCPlcSlicecage.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
 import com.kangaroohy.milo.model.ReadWriteEntity;
 import com.kangaroohy.milo.service.MiloService;
 import com.mes.bigstorage.entity.BigStorageCageDetails;
@@ -17,12 +18,15 @@
 import com.mes.glassinfo.service.GlassInfoService;
 import com.mes.largenscreen.entity.PieChartVO;
 import com.mes.largenscreen.entity.RunTime;
+import com.mes.s7.entity.S7DataDLPOne;
+import com.mes.s7.entity.S7DataDLPTwo;
 import com.mes.temperingglass.entity.TemperingGlassInfo;
 import com.mes.temperingglass.service.TemperingGlassInfoService;
 import com.mes.tools.WebSocketServer;
 import com.mes.utils.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -56,9 +60,19 @@
     @Autowired(required = false)
     MiloService miloService;
 
+    @Autowired
+    @Qualifier("s7SerializerDLPOne")
+    private S7Serializer s7SerializerDLPOne;
+
+    @Autowired
+    @Qualifier("s7SerializerDLPTwo")
+    private S7Serializer s7SerializerDLPTwo;
+
     private JSONObject jsonObject = new JSONObject();
 
     public void queryDataSource1() throws Exception {
+        S7DataDLPOne s7DataDLPOne = s7SerializerDLPOne.read(S7DataDLPOne.class);
+        S7DataDLPTwo s7DataWLTwo = s7SerializerDLPTwo.read(S7DataDLPTwo.class);
         List<Double> carPostion = new ArrayList<>();
         carPostion.add(0.25);
         carPostion.add(0.5);
@@ -69,14 +83,23 @@
         try {
             //杩涚墖浠诲姟鏁版嵁
             List<BigStorageTaskVO> inTaskList = new ArrayList();
-            ReadWriteEntity fromOpcUa = miloService.readFromOpcUa("DLP1A.DLP1A.FROM1");
+//            ReadWriteEntity fromOpcUa = miloService.readFromOpcUa("DLP1A.DLP1A.FROM1");
+            String fromOpcUa = s7DataDLPOne.getFrom1().toString();
+            List<Short> states = s7DataDLPOne.getStates();
+            List<Short> tos = s7DataDLPOne.getTos();
+            List<String> ids = s7DataDLPOne.getIds();
             for (int i = 1; i <= 6; i++) {
-                ReadWriteEntity requestWord = miloService.readFromOpcUa("DLP1A.DLP1A.DI" + i);
-                ReadWriteEntity targetSlotWord = miloService.readFromOpcUa("DLP1A.DLP1A.TO" + i);
-                ReadWriteEntity stateWord = miloService.readFromOpcUa("DLP1A.DLP1A.STATE" + i);
-                if (null != requestWord.getValue()) {
+//                ReadWriteEntity requestWord = miloService.readFromOpcUa("DLP1A.DLP1A.DI" + i);
+//                ReadWriteEntity targetSlotWord = miloService.readFromOpcUa("DLP1A.DLP1A.TO" + i);
+//                ReadWriteEntity stateWord = miloService.readFromOpcUa("DLP1A.DLP1A.STATE" + i);
+                String requestWord = ids.get(i - 1);
+                String targetSlotWord = tos.get(i - 1).toString();
+                String stateWord = states.get(i - 1).toString();
+//                if (null != requestWord.getValue()) {
+                if (null != requestWord) {
                     BigStorageTaskVO task = new BigStorageTaskVO();
-                    task.setGlassId(requestWord.getValue() + "");
+//                    task.setGlassId(requestWord.getValue() + "");
+                    task.setGlassId(requestWord);
                     int isExistCount = bigStorageCageDetailsService.count(new LambdaQueryWrapper<BigStorageCageDetails>().in(BigStorageCageDetails::getGlassId, task.getGlassId())
                             .in(BigStorageCageDetails::getState, Const.GLASS_STATE_IN_ALL));
                     if (isExistCount > 0) {
@@ -84,9 +107,12 @@
                     } else {
                         task.setIsSame(0);
                     }
-                    task.setStartSlot(Integer.parseInt(fromOpcUa.getValue() + ""));
-                    task.setTargetSlot(Integer.parseInt(targetSlotWord.getValue() + ""));
-                    task.setTaskState(Integer.parseInt(stateWord.getValue() + ""));
+//                    task.setStartSlot(Integer.parseInt(fromOpcUa.getValue() + ""));
+//                    task.setTargetSlot(Integer.parseInt(targetSlotWord.getValue() + ""));
+//                    task.setTaskState(Integer.parseInt(stateWord.getValue() + ""));
+                    task.setStartSlot(Integer.parseInt(fromOpcUa));
+                    task.setTargetSlot(Integer.parseInt(targetSlotWord));
+                    task.setTaskState(Integer.parseInt(stateWord));
                     inTaskList.add(task);
                     continue;
                 }
@@ -97,20 +123,30 @@
         }
         try {
             //杩涚墖鑱旀満
-            ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl");
-            jsonObject.append("inkageEntity", inkageEntity.getValue());
+//            ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl");
+//            jsonObject.append("inkageEntity", inkageEntity.getValue());
+            Boolean inkageEntity = s7DataDLPOne.getMesControl();
+            jsonObject.append("inkageEntity", inkageEntity);
             //杩涚墖璇锋眰
-            ReadWriteEntity requestEntity = miloService.readFromOpcUa("DLP1A.DLP1A.RequestMes");
-            jsonObject.append("requestEntity", requestEntity.getValue());
+//            ReadWriteEntity requestEntity = miloService.readFromOpcUa("DLP1A.DLP1A.RequestMes");
+//            jsonObject.append("requestEntity", requestEntity.getValue());
+            String requestEntity = s7DataDLPOne.getRequestMes().toString();
+            jsonObject.append("requestEntity", requestEntity);
             //鍚姩鍛戒护
-            ReadWriteEntity mesReplyEntity = miloService.readFromOpcUa("DLP1A.DLP1A.MesReply");
-            jsonObject.append("mesReplyEntity", mesReplyEntity.getValue());
+//            ReadWriteEntity mesReplyEntity = miloService.readFromOpcUa("DLP1A.DLP1A.MesReply");
+//            jsonObject.append("mesReplyEntity", mesReplyEntity.getValue());
+            String mesReplyEntity = s7DataDLPOne.getMesReply().toString();
+            jsonObject.append("mesReplyEntity", mesReplyEntity);
             //鍑虹墖鑱旀満
-            ReadWriteEntity outInkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl");
-            jsonObject.append("outInkageEntity", outInkageEntity.getValue());
+//            ReadWriteEntity outInkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl");
+//            jsonObject.append("outInkageEntity", outInkageEntity.getValue());
+            Boolean outInkageEntity = s7DataWLTwo.getMesControl();
+            jsonObject.append("outInkageEntity", outInkageEntity);
             //鍑虹墖璇锋眰
-            ReadWriteEntity outRequestEntity = miloService.readFromOpcUa("DLP1B.DLP1B.RequestMes");
-            jsonObject.append("outRequestEntity", outRequestEntity.getValue());
+//            ReadWriteEntity outRequestEntity = miloService.readFromOpcUa("DLP1B.DLP1B.RequestMes");
+//            jsonObject.append("outRequestEntity", outRequestEntity.getValue());
+            String outRequestEntity = s7DataWLTwo.getRequestMes().toString();
+            jsonObject.append("outRequestEntity", outRequestEntity);
 
 
             //鍑虹墖浠诲姟鏁版嵁

--
Gitblit v1.8.0