From f07fd673fb0977a370178f27655bf39cc574de6e Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期五, 20 六月 2025 14:06:52 +0800
Subject: [PATCH] 修改modbus读取String方法
---
hangzhoumesParent/common/servicebase/src/main/resources/mapper/OrderMapper.xml | 6 ++++--
hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/config/ModbusConfig.java | 2 +-
hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/job/OpcHollowRemoveTask.java | 42 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/hangzhoumesParent/common/servicebase/src/main/resources/mapper/OrderMapper.xml b/hangzhoumesParent/common/servicebase/src/main/resources/mapper/OrderMapper.xml
index 521aeff..7eafcca 100644
--- a/hangzhoumesParent/common/servicebase/src/main/resources/mapper/OrderMapper.xml
+++ b/hangzhoumesParent/common/servicebase/src/main/resources/mapper/OrderMapper.xml
@@ -17,7 +17,8 @@
a.area,
a.quantity,
a.create_time,
- round(ifnull(d.finishNum, 0) / a.quantity * 100) as 'percent'
+ round(ifnull(d.finishNum, 0) / a.quantity * 100) as 'percent',
+ ifnull(d.finishNum, 0)
from sd.`order` as a
LEFT JOIN (
SELECT sum(c.reporting_work_num) as 'finishNum',order_id
@@ -28,6 +29,7 @@
GROUP BY c.order_id
) as d
on a.order_id = d.order_id
- where a.warehousing != 2 and a.warehousing > 0
+ where a.warehousing != 2 and a.warehousing >= 0
+ ORDER BY a.order_id desc
</select>
</mapper>
diff --git a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/config/ModbusConfig.java b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/config/ModbusConfig.java
index 447ef6e..47e1a4b 100644
--- a/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/config/ModbusConfig.java
+++ b/hangzhoumesParent/moduleService/hollowGlassModule/src/main/java/com/mes/config/ModbusConfig.java
@@ -24,7 +24,7 @@
@Bean(name = "CMJ2ModbusTcp")
public ModbusTcp CMJ2ModbusTcp() {
// ModbusTcp modbusTcp=new ModbusTcp("127.0.0.1");
- ModbusTcp modbusTcp=new ModbusTcp("192.168.30.160");
+ ModbusTcp modbusTcp=new ModbusTcp("192.168.30.162");
modbusTcp.setConnectTimeout(3000);
return modbusTcp;
}
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 9149b28..0c22324 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,6 +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;
@@ -13,6 +16,7 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -82,6 +86,26 @@
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 {
ModbusTcp modbusTcp = null;
if ("CMJ1.CMJ1.".equals(cell)) {
@@ -93,6 +117,17 @@
log.info("闄よ啘鏈簕}鏈繛鎺�", cell);
return;
}
+ String glassIdEntitys = readString(modbusTcp, 42003 - offset);
+ log.info("闄よ啘{}鑾峰彇褰撳墠鐨勭幓鐠僫d锛歿}", cell, glassIdEntitys);
+// byte[] res = CMJ1ModbusTcp.readHoldRegister(1, 42003, 14);
+// String glassId1 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.CD_AB).getString(10);
+// String glassId2 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.AB_CD).getString(10);
+// String glassId3 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.BA_DC).getString(10);
+// String glassId4 = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.DC_BA).getString(10);
+// log.info("鑾峰彇{}褰撳墠鐨勭幓鐠僫d1锛歿}", cell, glassId1);
+// log.info("鑾峰彇{}褰撳墠鐨勭幓鐠僫d2锛歿}", cell, glassId2);
+// log.info("鑾峰彇{}褰撳墠鐨勭幓鐠僫d3锛歿}", cell, glassId3);
+// log.info("鑾峰彇{}褰撳墠鐨勭幓鐠僫d4锛歿}", cell, glassId4);
Integer requestEntity = modbusTcp.readUInt16(42001 - offset);
// ReadWriteEntity requestEntity = miloService.readFromOpcUa(cell + "mesControl");
// if ("0".equals(requestEntity.getValue() + "")) {
@@ -107,7 +142,12 @@
log.info("褰撳墠鏈敹鍒拌姹傜幓鐠僫d鏁版嵁锛岀粨鏉熶换鍔�");
return;
}
- String glassIdEntity = modbusTcp.readString(42003 - offset, 20);
+
+
+// String glassIdEntity = modbusTcp.readString(42003 - offset, 20);
+ String glassIdEntity = readString(modbusTcp, 42003 - offset);
+// String glassIdEntity = ByteReadBuff.newInstance(res, 0, false, EByteBuffFormat.CD_AB).getString(10);
+ //浣犲垹浜嗭紵
log.info("闄よ啘{}鑾峰彇褰撳墠鐨勪俊鍙蜂负锛歿},鐜荤拑id:{}", cell, flagRequest, glassIdEntity);
if (null == glassIdEntity || StringUtils.isBlank(glassIdEntity)) {
// ReadWriteEntity glassIdEntity = miloService.readFromOpcUa(cell + "glassId");
--
Gitblit v1.8.0