From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目
---
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java | 37 ++++++++++++++++++++++++++++++++-----
1 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java
index 1324f3a..1d52f8d 100644
--- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java
+++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java
@@ -39,11 +39,38 @@
public static Future<int[]> read(IotModbusTcpClientConnectionManager.ModbusConnection connection,
Integer slaveId,
IotModbusPointRespDTO point) {
+ return read(connection, slaveId, point.getFunctionCode(),
+ point.getRegisterAddress(), point.getRegisterCount(), point.getIdentifier());
+ }
+
+ /**
+ * 璇诲彇 Modbus 鏁版嵁
+ *
+ * @param connection Modbus 杩炴帴
+ * @param slaveId 浠庣珯鍦板潃
+ * @param functionCode 鍔熻兘鐮�
+ * @param registerAddress 瀵勫瓨鍣ㄨ捣濮嬪湴鍧�
+ * @param registerCount 瀵勫瓨鍣ㄦ暟閲�
+ * @return 鍘熷鍊硷紙int 鏁扮粍锛�
+ */
+ public static Future<int[]> read(IotModbusTcpClientConnectionManager.ModbusConnection connection,
+ Integer slaveId,
+ Integer functionCode,
+ Integer registerAddress,
+ Integer registerCount) {
+ return read(connection, slaveId, functionCode, registerAddress, registerCount, null);
+ }
+
+ private static Future<int[]> read(IotModbusTcpClientConnectionManager.ModbusConnection connection,
+ Integer slaveId,
+ Integer functionCode,
+ Integer registerAddress,
+ Integer registerCount,
+ String identifier) {
return connection.executeBlocking(tcpConnection -> {
try {
// 1. 鍒涘缓璇锋眰
- ModbusRequest request = createReadRequest(point.getFunctionCode(),
- point.getRegisterAddress(), point.getRegisterCount());
+ ModbusRequest request = createReadRequest(functionCode, registerAddress, registerCount);
request.setUnitID(slaveId);
// 2. 鎵ц浜嬪姟锛堣姹傦級
@@ -53,10 +80,10 @@
// 3. 瑙f瀽鍝嶅簲
ModbusResponse response = transaction.getResponse();
- return extractValues(response, point.getFunctionCode());
+ return extractValues(response, functionCode);
} catch (Exception e) {
- throw new RuntimeException(String.format("Modbus 璇诲彇澶辫触 [slaveId=%d, identifier=%s, address=%d]",
- slaveId, point.getIdentifier(), point.getRegisterAddress()), e);
+ throw new RuntimeException(String.format("Modbus 璇诲彇澶辫触 [slaveId=%d, identifier=%s, functionCode=%d, address=%d, count=%d]",
+ slaveId, identifier, functionCode, registerAddress, registerCount), e);
}
});
}
--
Gitblit v1.9.3