From b0138dbfe9cfeeb658dddc324a4c29a30a9e9052 Mon Sep 17 00:00:00 2001 From: tuqiang <437016993@qq.com> Date: Tue, 10 Sep 2024 17:55:59 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9Eopcurl=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nlsso-server/src/main/java/org/nl/acs/AcsConfig.java | 5 +++++ .../java/org/nl/acs/opc/DeviceOpcProtocolRunable.java | 5 ++++- .../src/main/java/org/nl/acs/opc/TestOpcUA.java | 8 +++++++- .../src/main/java/org/nl/acs/utils/ReadUtil.java | 9 ++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/AcsConfig.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/AcsConfig.java index 0d1e780..861eb82 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/AcsConfig.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/AcsConfig.java @@ -78,6 +78,11 @@ public interface AcsConfig { */ String HASWMS = "hasWms"; + /** + * OPC数据源URL + */ + String OPCURL = "opcUrl"; + /** * 是否请求wms系统 */ diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 8d4afde..5d41ea7 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -345,9 +345,12 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC } } - private final static String endPointUrl = "opc.tcp://127.0.0.1:49320"; + +// private final static String endPointUrl = "opc.tcp://127.0.0.1:49320"; private static OpcUaClient createClient() throws Exception { + ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); + String endPointUrl = paramService.findByCode(AcsConfig.OPCURL).getValue(); //opc ua服务端地址 Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "security"); Files.createDirectories(securityTempDir); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/TestOpcUA.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/TestOpcUA.java index bf3fef0..b6b72f0 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/TestOpcUA.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/TestOpcUA.java @@ -19,6 +19,9 @@ import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn; import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest; import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters; import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId; +import org.nl.acs.AcsConfig; +import org.nl.config.SpringContextHolder; +import org.nl.system.service.param.ISysParamService; import java.nio.file.Files; import java.nio.file.Path; @@ -32,13 +35,16 @@ import java.util.concurrent.atomic.AtomicInteger; public class TestOpcUA { // private final static String endPointUrl = "opc.tcp://192.168.10.60:49320"; - private final static String endPointUrl = "opc.tcp://127.0.0.1:49320"; +// private final static String endPointUrl = "opc.tcp://127.0.0.1:49320"; /** * 创建OPC UA客户端 */ private static OpcUaClient createClient() throws Exception { + ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); + String endPointUrl = paramService.findByCode(AcsConfig.OPCURL).getValue(); + //opc ua服务端地址 Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "security"); Files.createDirectories(securityTempDir); diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java index 2d4255c..86f7d76 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java @@ -15,6 +15,7 @@ import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn; import org.jinterop.dcom.common.JIException; import org.jinterop.dcom.core.JIVariant; +import org.nl.acs.AcsConfig; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.device_driver.standard_inspect.ItemProtocol; import org.nl.acs.opc.OpcUtl; @@ -23,6 +24,7 @@ import org.nl.acs.opc.service.mapper.OpcMapper; import org.nl.common.exception.BadRequestException; import org.nl.config.SpringContextHolder; import org.nl.config.language.LangProcess; +import org.nl.system.service.param.ISysParamService; import org.openscada.opc.dcom.list.ClassDetails; import org.openscada.opc.lib.common.AlreadyConnectedException; import org.openscada.opc.lib.common.ConnectionInformation; @@ -44,6 +46,7 @@ import java.util.concurrent.Executors; @Slf4j public class ReadUtil { + static OpcMapper opcMapper = SpringContextHolder.getBean("opcMapper"); public static Server getServer(String opc_id) { @@ -78,7 +81,11 @@ public class ReadUtil { * 创建OPC UA客户端 */ private static OpcUaClient createClient() throws Exception { - String endPointUrl = "opc.tcp://127.0.0.1:49320"; + ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class); + String endPointUrl = paramService.findByCode(AcsConfig.OPCURL).getValue(); + if (StrUtil.isEmpty(endPointUrl)){ + throw new BadRequestException("opc地址未配置!"); + } //opc ua服务端地址 Path securityTempDir = Paths.get(System.getProperty("java.io.tmpdir"), "security");