From de48dec1b464fc95e857752a1db0476d362c7b6d Mon Sep 17 00:00:00 2001
From: 86156 <823267011@qq.com>
Date: Mon, 13 Apr 2026 15:48:37 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=89=88=E6=9C=AC=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
business/pom.xml | 23 +++++++-------
.../service/impl/OpcDataServiceImpl.java | 31 +++++++------------
pom.xml | 7 +++--
3 files changed, 27 insertions(+), 34 deletions(-)
diff --git a/business/pom.xml b/business/pom.xml
index 4f14cda..0ead927 100644
--- a/business/pom.xml
+++ b/business/pom.xml
@@ -16,6 +16,15 @@
* 说明:
* 1) 写入逻辑已切换为 iot-communication(S7)
* 2) 读取逻辑仍保留在原 OPC 体系(不在本类中)
@@ -27,26 +27,21 @@ public class OpcDataServiceImpl implements OpcDataService {
@Override
public boolean writeData(OpcWriteDataForm form) {
- try (S7PLC s7PLC = s7WriteClient.newClient()) {
- writeByGuessType(s7PLC, form.getFieldName(), form.getValue());
- return true;
- } catch (Exception e) {
- log.error("写入 S7 数据异常,address={}, value={}", form.getFieldName(), form.getValue(), e);
- return false;
- }
+
+ S7PLC s7PLC = s7WriteClient.newClient();
+ writeByGuessType(s7PLC, form.getFieldName(), form.getValue());
+ return true;
+
}
@Override
public boolean batchWriteData(OpcBatchWriteDataForm form) {
- try (S7PLC s7PLC = s7WriteClient.newClient()) {
- for (OpcWriteDataForm item : form.getDataList()) {
- writeByGuessType(s7PLC, item.getFieldName(), item.getValue());
- }
- return true;
- } catch (Exception e) {
- log.error("批量写入 S7 数据异常", e);
- return false;
+ S7PLC s7PLC = s7WriteClient.newClient();
+ for (OpcWriteDataForm item : form.getDataList()) {
+ writeByGuessType(s7PLC, item.getFieldName(), item.getValue());
}
+ return true;
+
}
private void writeByGuessType(S7PLC s7PLC, String address, Object value) {
@@ -73,10 +68,6 @@ public class OpcDataServiceImpl implements OpcDataService {
s7PLC.writeInt32(address, (Integer) value);
return;
}
- if (value instanceof Long) {
- s7PLC.writeInt64(address, (Long) value);
- return;
- }
if (value instanceof Float) {
s7PLC.writeFloat32(address, (Float) value);
return;
diff --git a/pom.xml b/pom.xml
index 806d31a..9a1fe43 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">