From 5292a401bc26ad177ff5005787429ce036e6457f Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期五, 31 十月 2025 13:35:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java |  142 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 111 insertions(+), 31 deletions(-)

diff --git a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java
index 3002c7e..78e634c 100644
--- a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java
+++ b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java
@@ -1,5 +1,9 @@
 package com.mes.job;
 
+import com.github.xingshuangs.iot.common.buff.ByteReadBuff;
+import com.github.xingshuangs.iot.common.buff.EByteBuffFormat;
+import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
+import com.github.xingshuangs.iot.utils.ByteUtil;
 import com.kangaroohy.milo.model.ReadWriteEntity;
 import com.kangaroohy.milo.service.MiloService;
 import com.mes.hollow.entity.vo.HollowGlassFormulaVO;
@@ -7,10 +11,12 @@
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 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;
 
 import javax.annotation.Resource;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -28,6 +34,43 @@
     @Autowired(required = false)
     MiloService miloService;
 
+    @Autowired
+    @Qualifier("CMJ1ModbusTcp")
+    ModbusTcp CMJ1ModbusTcp;
+
+    @Autowired
+    @Qualifier("CMJ2ModbusTcp")
+    ModbusTcp CMJ2ModbusTcp;
+
+    private Integer offset = 40001;
+
+    /**
+     * 闄よ啘鏈鸿仈鏈虹姸鎬�
+     *
+     * @throws Exception
+     */
+    @Scheduled(fixedDelay = 3000)
+    public void filmRemoveStateOne() throws Exception {
+        ModbusTcp modbusTcp = CMJ1ModbusTcp;
+        try {
+            modbusTcp.readUInt16(42001 - offset);
+            log.info("闄よ啘鏈�1鑱旀満鐘舵�佹甯�");
+        } catch (Exception e) {
+            log.error("闄よ啘鏈�1鑱旀満鐘舵�佸紓甯�", e);
+        }
+    }
+
+    @Scheduled(fixedDelay = 3000)
+    public void filmRemoveStateTwo() throws Exception {
+        ModbusTcp modbusTcp = CMJ2ModbusTcp;
+        try {
+            modbusTcp.readUInt16(42001 - offset);
+            log.info("闄よ啘鏈�2鑱旀満鐘舵�佹甯�");
+        } catch (Exception e) {
+            log.error("闄よ啘鏈�2鑱旀満鐘舵�佸紓甯�", e);
+        }
+    }
+
     /**
      * 鏀跺埌闄よ啘鏈鸿姹傚強鐜荤拑id
      *
@@ -43,58 +86,86 @@
         hollowRemoveChildTask("CMJ2.CMJ2.");
     }
 
+    public String readString(ModbusTcp modbusTcp, int address) {
+        //
+        byte[] bytes = new byte[20];
+        for (int i = 0; i < 10; i++) {
+            int res = modbusTcp.readUInt16(address + i);
+
+            bytes[i * 2 + 1] = (byte) ((res >> 8) & 0xFF);
+            bytes[i * 2] = (byte) (res & 0xFF);
+        }
+        int endIndex = 0;
+        while (endIndex < bytes.length) {
+            if (bytes[endIndex] == 0) {
+                break;
+            }
+            endIndex++;
+        }
+        // 鎴彇鏈夋晥閮ㄥ垎
+        return new String(bytes, 0, endIndex);
+    }
+
     private void hollowRemoveChildTask(String cell) throws Exception {
-        ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
-        if ("0".equals(requestEntity.getValue() + "")) {
+        ModbusTcp modbusTcp = null;
+        if ("CMJ1.CMJ1.".equals(cell)) {
+            modbusTcp = CMJ1ModbusTcp;
+        } else {
+            modbusTcp = CMJ2ModbusTcp;
+        }
+        if (!modbusTcp.checkConnected()) {
+            log.info("闄よ啘鏈簕}鏈繛鎺�", cell);
+            return;
+        }
+        String glassIdEntitys = readString(modbusTcp, 42003 - offset);
+        log.info("闄よ啘{}鑾峰彇褰撳墠鐨勭幓鐠僫d锛歿}", cell, glassIdEntitys);
+        Integer requestEntity = modbusTcp.readUInt16(42001 - offset);
+        if (0 == requestEntity) {
             log.info("褰撳墠闄よ啘鏈轰负鍗曟満鐘舵��");
             return;
         }
-        int request = Integer.parseInt(requestEntity.getValue() + "");
+        int request = requestEntity;
         int flagRequest = request & 3;
-        ReadWriteEntity glassIdEntity = miloService.readFromOpcUa(cell + "glassId");
-        log.info("闄よ啘{}鑾峰彇褰撳墠鐨勪俊鍙蜂负锛歿},鐜荤拑id:{}", cell, flagRequest, glassIdEntity);
         if (flagRequest != 3) {
             log.info("褰撳墠鏈敹鍒拌姹傜幓鐠僫d鏁版嵁锛岀粨鏉熶换鍔�");
             return;
         }
 
-        log.info("闄よ啘{}鑾峰彇褰撳墠鐨勭幓鐠僫d锛歿}", cell, glassIdEntity);
-        if (null == glassIdEntity.getValue() || StringUtils.isBlank(glassIdEntity.getValue() + "")) {
+        String glassIdEntity = readString(modbusTcp, 42003 - offset);
+        log.info("闄よ啘{}鑾峰彇褰撳墠鐨勪俊鍙蜂负锛歿},鐜荤拑id:{}", cell, flagRequest, glassIdEntity);
+        if (null == glassIdEntity || StringUtils.isBlank(glassIdEntity)) {
             log.info("褰撳墠鏈敹鍒扮幓鐠僫d鏁版嵁锛岀粨鏉熶换鍔�");
             return;
         }
-        log.info("褰撳墠闇�瑕侀櫎鑶滅殑鐜荤拑id涓猴細{}", glassIdEntity.getValue() + "");
+        log.info("褰撳墠闇�瑕侀櫎鑶滅殑鐜荤拑id涓猴細{}", glassIdEntity);
         //鎸夌収鐜荤拑id鑾峰彇瀵瑰簲鐨勪换鍔d
-        HollowGlassFormulaVO detailsVO = hollowFormulaDetailsService.queryFormulaDetailsByGlassId(glassIdEntity.getValue() + "", null, null);
+        HollowGlassFormulaVO detailsVO = hollowFormulaDetailsService.queryFormulaDetailsByGlassId(glassIdEntity, null, null);
         if (null == detailsVO) {
             log.info("鐜荤拑id涓嶅瓨鍦紝璇锋鏌ユ暟鎹�");
             return;
         }
         //鎸夌収浠诲姟id鑾峰彇瀵瑰簲鐨勯厤鏂逛俊鎭�
-
-        List<ReadWriteEntity> ualist = new ArrayList<>();
-        List<ReadWriteEntity> wordlist = new ArrayList<>();
-        log.info("闄よ啘{}鑾峰彇鐜荤拑{},鏄惁闄よ啘锛歿}", cell, glassIdEntity.getValue(), detailsVO.getFilmRemove());
+        int Id = 0;
+        log.info("闄よ啘{}鑾峰彇鐜荤拑{},鏄惁闄よ啘锛歿}", cell, requestEntity, detailsVO.getFilmRemove());
         if (detailsVO.getFilmRemove() == 0) {
             // 10111011
             int sendId = request & 63;
-            sendId = sendId + 4;
-            wordlist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
+            Id = sendId + 4;
+            modbusTcp.writeUInt16(42001 - offset, sendId);
         } else {
             // 鍏堝皢瀵瑰簲鐨勪綅缃负0锛岃幏寰楄姹傜殑鐜荤拑鏁版嵁锛� 鐒跺悗灏嗗搴斾綅鍊�     110111011
             int sendId = request & 63;
-            sendId = sendId + 4 + 64;
-            wordlist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
-            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassTop", detailsVO.getTopRemove()));
-            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassBottom", detailsVO.getBottomRemove()));
-            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassLeft", detailsVO.getLeftRemove()));
-            ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "glassRight", detailsVO.getRightRemove()));
+            Id = sendId + 4 + 64;
+
+            modbusTcp.writeUInt32(42019 - offset, detailsVO.getTopRemove());
+            modbusTcp.writeUInt32(42021 - offset, detailsVO.getTopRemove());
+            modbusTcp.writeUInt32(42023 - offset, detailsVO.getTopRemove());
+            modbusTcp.writeUInt32(42025 - offset, detailsVO.getTopRemove());
         }
-        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "thickness", (int) (detailsVO.getThickness() * 10)));
-        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "firstLength", (int) (Math.max(detailsVO.getWidth(), detailsVO.getHeight())) * 10));
-        ualist.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "secondLength", (int) (Math.min(detailsVO.getWidth(), detailsVO.getHeight())) * 10));
-        miloService.writeToOpcWord(wordlist);
-        miloService.writeToOpcUa(ualist);
+        modbusTcp.writeUInt32(42013 - offset, (int) (detailsVO.getThickness() * 10));
+        modbusTcp.writeUInt32(42015 - offset, (int) (Math.max(detailsVO.getWidth(), detailsVO.getHeight())) * 10);
+        modbusTcp.writeUInt32(42017 - offset, (int) (Math.min(detailsVO.getWidth(), detailsVO.getHeight())) * 10);
+        modbusTcp.writeUInt16(42001 - offset, Id);
         return;
     }
 
@@ -114,8 +185,19 @@
     }
 
     public void finishHollowRemoveChildTask(String cell) throws Exception {
-        ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
-        int request = Integer.parseInt(requestEntity.getValue() + "");
+//        ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
+        ModbusTcp modbusTcp = null;
+        if ("CMJ1.CMJ1.".equals(cell)) {
+            modbusTcp = CMJ1ModbusTcp;
+        } else {
+            modbusTcp = CMJ2ModbusTcp;
+        }
+        if (!modbusTcp.checkConnected()) {
+            log.info("闄よ啘鏈簕}鏈繛鎺�", cell);
+            return;
+        }
+        int requestEntity = modbusTcp.readUInt16(42001 - offset);
+        int request = requestEntity;
         int flagRequest = request & 9;
         if (flagRequest != 9) {
             log.info("褰撳墠鏈敹鍒伴櫎鑶滄満ID鎺ユ敹瀹屾垚淇″彿锛岀粨鏉熶换鍔�");
@@ -124,9 +206,7 @@
         //鍚戠數姘斿彂閫佹竻妤氫俊鍙�
         int sendId = request & 251;
         log.info("{}鏀跺埌闄よ啘鏈篒D鎺ユ敹瀹屾垚淇″彿锛屽皢鍐欏叆鏁版嵁瀹屾垚缃�0,鍙戦�佹暟鎹负锛歿}", cell, sendId);
-        List<ReadWriteEntity> list = new ArrayList<>();
-        list.add(opcPlcStorageCageHollowTask.generateReadWriteEntity(cell + "mesControl", sendId));
-        miloService.writeToOpcWord(list);
+        modbusTcp.writeUInt16(42001 - offset, sendId);
     }
 
 }
\ No newline at end of file

--
Gitblit v1.8.0