From ae07cd92f46b88bf034c7d9d0b96b3a5e83fdc98 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期二, 20 五月 2025 16:29:00 +0800
Subject: [PATCH] 仓储,上片,卧理修改OPC为S7通讯

---
 hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java |  112 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 90 insertions(+), 22 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java
index 0f83952..1a09f85 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassNewTask.java
@@ -5,6 +5,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
 import com.kangaroohy.milo.model.ReadWriteEntity;
 import com.kangaroohy.milo.service.MiloService;
 import com.mes.common.config.Const;
@@ -22,11 +23,15 @@
 import com.mes.opctask.entity.EdgStorageDeviceTaskHistory;
 import com.mes.opctask.service.EdgStorageDeviceTaskHistoryService;
 import com.mes.opctask.service.EdgStorageDeviceTaskService;
+import com.mes.s7.entity.S7DataMBOne;
+import com.mes.s7.entity.S7DataWLOne;
+import com.mes.s7.entity.S7DataWLTwo;
 import com.mes.sysconfig.service.SysConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 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;
 
@@ -68,6 +73,18 @@
     @Resource
     SysConfigService sysConfigService;
 
+    @Autowired
+    @Qualifier("s7SerializerWLOne")
+    private S7Serializer s7SerializerWLOne;
+
+    @Autowired
+    @Qualifier("s7SerializerWLTwo")
+    private S7Serializer s7SerializerWLTwo;
+
+    @Autowired
+    @Qualifier("s7SerializerMBOne")
+    private S7Serializer s7SerializerMBOne;
+
     //    @Value("${mes.threshold}")
     private int threshold;
     //    @Value("${mes.cellLength}")
@@ -103,12 +120,15 @@
 
     @Scheduled(fixedDelay = 1000)
     public void startOneOpcTask() throws Exception {
+        S7DataWLTwo s7DataWLTwo = s7SerializerWLTwo.read(S7DataWLTwo.class);
         //鑾峰彇绗簩鏉$嚎璺殑鍗у紡鐞嗙墖绗肩姸鎬�
-        ReadWriteEntity twoInkageEntity = miloService.readFromOpcUa("WL2.WL2.deviceState");
+//        ReadWriteEntity twoInkageEntity = miloService.readFromOpcUa("WL2.WL2.deviceState");
+        Boolean twoInkageEntity = s7DataWLTwo.getDeviceState();
         //榛樿鍙窇涓�鍙板崸寮忕悊鐗�,涓ゆ潯绾胯矾閮藉彲浠ヨ蛋
         int cellFlag = 1;
         //濡傛灉涓ゆ潯绾块兘鍚姩鍒欏彧鑳借窇涓�鏉$嚎
-        if (twoInkageEntity != null && !Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
+//        if (twoInkageEntity != null && !Boolean.parseBoolean(twoInkageEntity.getValue() + "")) {
+        if (twoInkageEntity != null && !twoInkageEntity) {
             cellFlag = 2;
         }
         startOneOpcTaskChild(EDG_STORAGE_DEVICE_ONE_TASK, 1, cellFlag);
@@ -116,9 +136,12 @@
 
     @Scheduled(fixedDelay = 1000)
     public void startTwoOpcTask() throws Exception {
-        ReadWriteEntity oneInkageEntity = miloService.readFromOpcUa("WL1.WL1.deviceState");
+        S7DataWLOne s7DataWLOne = s7SerializerWLOne.read(S7DataWLOne.class);
+//        ReadWriteEntity oneInkageEntity = miloService.readFromOpcUa("WL1.WL1.deviceState");
+        Boolean oneInkageEntity = s7DataWLOne.getDeviceState();
         int cellFlag = 1;
-        if (oneInkageEntity != null && !Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
+//        if (oneInkageEntity != null && !Boolean.parseBoolean(oneInkageEntity.getValue() + "")) {
+        if (oneInkageEntity != null && !oneInkageEntity) {
             cellFlag = 2;
         }
         startOneOpcTaskChild(EDG_STORAGE_DEVICE_TWO_TASK, 2, cellFlag);
@@ -219,15 +242,25 @@
             return;
         }
         String toEndingId = glassInfo.getTemperingLayoutId() + "" + glassInfo.getTemperingFeedSequence();
-        List<ReadWriteEntity> list = new ArrayList<>();
-//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".mesControl", true));
-        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".glassId", Integer.parseInt(toEndingId)));
-        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".toEdingId", Integer.parseInt(toEndingId)));
-        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".width", (int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
-        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
+//        List<ReadWriteEntity> list = new ArrayList<>();
+////        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".mesControl", true));
+//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".glassId", Integer.parseInt(toEndingId)));
+//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".toEdingId", Integer.parseInt(toEndingId)));
+//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".width", (int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
+//        list.add(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".height", (int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio)));
+//
+//        miloService.writeToOpcUa(list);
+//        miloService.writeToOpcWord(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".thickness", (int) glassInfo.getThickness() * ratio));
+        S7DataMBOne s7DataMBOne =new S7DataMBOne();
+        s7DataMBOne.setToEdingId(Integer.parseInt(toEndingId));
+        s7DataMBOne.setGlassId(Integer.parseInt(toEndingId));
+        s7DataMBOne.setWidth((int) Math.max(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio));
+        s7DataMBOne.setHeight((int) Math.min(glassInfo.getWidth() * ratio, glassInfo.getHeight() * ratio));
+        s7SerializerMBOne.write(s7DataMBOne);
 
-        miloService.writeToOpcUa(list);
-        miloService.writeToOpcWord(generateReadWriteEntity("MB" + cell + ".MB" + cell + ".thickness", (int) glassInfo.getThickness() * ratio));
+        s7DataMBOne =new S7DataMBOne();
+        s7DataMBOne.setThickness((short) (glassInfo.getThickness() * ratio));
+        s7SerializerMBOne.write(s7DataMBOne);
         //淇敼纾ㄨ竟瀵瑰垪涓殑纾ㄨ竟绾胯矾鍙婄姸鎬�
         edgGlassTaskInfoService.update(new LambdaUpdateWrapper<EdgGlassTaskInfo>()
                 .set(EdgGlassTaskInfo::getLine, cell)
@@ -300,22 +333,57 @@
     private boolean outTask(EdgStorageDeviceTask task, String tableName, int deviceId, int cellFlag) throws Exception {
         Date startDate = new Date();
         //鑾峰彇瀵瑰簲鐨勮澶囩姸鎬佷俊鎭�
-        ReadWriteEntity oneOutStateEntity = miloService.readFromOpcUa("WL1.WL1.slotState");
-        ReadWriteEntity twoOutStateEntity = miloService.readFromOpcUa("WL2.WL2.slotState");
+//        ReadWriteEntity oneOutStateEntity = miloService.readFromOpcUa("WL1.WL1.slotState");
+//        ReadWriteEntity twoOutStateEntity = miloService.readFromOpcUa("WL2.WL2.slotState");
+//        ReadWriteEntity d06OutStateEntity = miloService.readFromOpcUa("WL2.WL2.d06SlotState");
+        S7DataWLOne s7DataWLOne = s7SerializerWLOne.read(S7DataWLOne.class);
+        S7DataWLTwo s7DataWLTwo = s7SerializerWLTwo.read(S7DataWLTwo.class);
+        Short oneOutStateEntity = s7DataWLOne.getSlotState();
+        Short twoOutStateEntity = s7DataWLTwo.getSlotState();
+        Short d06OutStateEntity = s7DataWLTwo.getD06SlotState();
         //鐘舵�佹湁3涓儏鍐碉細0绌洪棽 1蹇欑 2绂佺敤
-        String oneOutState = "2";
-        String twoOutState = "2";
-        if (null != oneOutStateEntity && null != oneOutStateEntity.getValue()) {
-            oneOutState = oneOutStateEntity.getValue().toString();
+        String oneOutState = Const.OUT_DISABLE;
+        String twoOutState = Const.OUT_DISABLE;
+        String d06OutState = Const.OUT_DISABLE;
+//        if (null != oneOutStateEntity && null != oneOutStateEntity.getValue()) {
+//            oneOutState = oneOutStateEntity.getValue().toString();
+//        }
+        if (null != oneOutStateEntity ) {
+            oneOutState = oneOutStateEntity.toString();
         }
-        if (null != twoOutStateEntity && null != twoOutStateEntity.getValue()) {
-            twoOutState = twoOutStateEntity.getValue().toString();
+//        if (null != twoOutStateEntity && null != twoOutStateEntity.getValue()) {
+//            twoOutState = twoOutStateEntity.getValue().toString();
+//        }
+        if (null != twoOutStateEntity ) {
+            twoOutState = twoOutStateEntity.toString();
         }
-
-        if ((cellFlag == 2 && Const.OUT_BUSY.equals(oneOutState) && Const.OUT_BUSY.equals(twoOutState)) || (Const.OUT_DISABLE.equals(oneOutState) && Const.OUT_DISABLE.equals(twoOutState))) {
+        //涓ゆ潯绾块兘涓虹鐢ㄥ垯涓嶅嚭鐜荤拑
+        if (Const.OUT_DISABLE.equals(oneOutState) && Const.OUT_DISABLE.equals(twoOutState)) {
             log.info("A09銆丄10涓簕},{}闈炶嚜鍔ㄧ姸鎬侊紝鏃犳硶鍑虹墖", oneOutState, oneOutState);
             return Boolean.FALSE;
         }
+//        if (null != d06OutStateEntity && null != d06OutStateEntity.getValue()) {
+//            d06OutState = d06OutStateEntity.getValue().toString();
+//        }
+        if (null != d06OutStateEntity ) {
+            d06OutState = d06OutStateEntity.toString();
+        }
+        //鑾峰彇d06鐗囧彴鐘舵��
+        // 1:涓�瀵逛竴鐨勬儏鍐典笅涓嶉渶瑕佸垽鏂璬06鐘舵��
+        // 2:涓�鍙风嚎涓�瀵瑰鐨勬儏鍐典笅锛岃幏鍙栦簩鍙风嚎纾ㄨ竟鍓嶇墖鍙癉07鐨勭姸鎬侊紝D07闈炵鐢ㄦ椂锛屼簩鍙风嚎灏嗘寜鐓06鐗囧彴鐘舵�佽寰楀嚭鐗�
+        // 3:浜屽彿绾夸竴瀵瑰鐨勬儏鍐典笅锛岃幏鍙栦竴鍙风嚎纾ㄨ竟鍓嶇墖鍙癈08鐨勭姸鎬侊紝C08闈炵鐢ㄦ椂锛屼竴鍙风嚎灏嗘寜鐓06鐗囧彴鐘舵�佽寰楀嚭鐗�
+        if (cellFlag == 2) {
+            if (deviceId == 1) {
+                twoOutState = Const.OUT_DISABLE.equals(twoOutState) ? Const.OUT_DISABLE : d06OutState;
+            } else {
+                oneOutState = Const.OUT_DISABLE.equals(oneOutState) ? Const.OUT_DISABLE : d06OutState;
+            }
+            if (Const.OUT_BUSY.equals(oneOutState) && Const.OUT_BUSY.equals(twoOutState)) {
+                log.info("A09銆丄10涓簕},{}闈炶嚜鍔ㄧ姸鎬侊紝鏃犳硶鍑虹墖", oneOutState, oneOutState);
+                return Boolean.FALSE;
+            }
+        }
+
         log.info("寮�濮嬫墽琛屽嚭鐗�/鐩撮�氫换鍔★紝浠诲姟淇℃伅涓猴細{},琛ㄥ悕涓猴細{},璁惧id:{},寮�濮嬫椂闂达細{},涓�鍙风嚎鐘舵�侊細{}锛屼簩鍙风嚎鐘舵�侊細{}",
                 task, tableName, deviceId, startDate, oneOutState, twoOutState);
         //鑾峰彇褰撳墠闇�瑕佽蛋閭f潯绾�

--
Gitblit v1.8.0