修复版本问题

This commit is contained in:
2026-04-13 15:48:37 +08:00
parent 8610b76a1d
commit de48dec1b4
3 changed files with 27 additions and 34 deletions

View File

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
/**
* OPC 数据读写服务实现类
*
* <p>
* 说明:
* 1) 写入逻辑已切换为 iot-communicationS7
* 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;