From aa38946d02c60f2e9d84a6061d7221dc700a8e50 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Sun, 20 Mar 2022 09:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20opcua=20client=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 14 +++++--- ...7Controller.java => S7DemoController.java} | 8 ++--- .../qgs/dc/s7/my/s7connector/MainForRead.java | 17 +++++---- .../dc/s7/my/s7connector/enmuc/S7Client.java | 36 +++++++++---------- 4 files changed, 40 insertions(+), 35 deletions(-) rename src/main/java/com/qgs/dc/s7/controller/{S7Controller.java => S7DemoController.java} (91%) diff --git a/pom.xml b/pom.xml index 75a148e..70583a6 100644 --- a/pom.xml +++ b/pom.xml @@ -21,24 +21,30 @@ org.eclipse.milo sdk-client - 0.6.3 + 0.6.4 org.eclipse.milo stack-client - 0.6.3 + 0.6.4 org.eclipse.milo stack-server - 0.6.3 + 0.6.4 org.eclipse.milo sdk-server - 0.6.3 + 0.6.4 + + + + com.google.guava + guava + 30.1.1-jre diff --git a/src/main/java/com/qgs/dc/s7/controller/S7Controller.java b/src/main/java/com/qgs/dc/s7/controller/S7DemoController.java similarity index 91% rename from src/main/java/com/qgs/dc/s7/controller/S7Controller.java rename to src/main/java/com/qgs/dc/s7/controller/S7DemoController.java index 85c3707..f660ab3 100644 --- a/src/main/java/com/qgs/dc/s7/controller/S7Controller.java +++ b/src/main/java/com/qgs/dc/s7/controller/S7DemoController.java @@ -1,9 +1,6 @@ package com.qgs.dc.s7.controller; import com.qgs.dc.opcua.controller.R; -import com.qgs.dc.s7.my.s7connector.api.DaveArea; -import com.qgs.dc.s7.my.s7connector.api.S7Connector; -import com.qgs.dc.s7.my.s7connector.api.utils.ByteUtils; import com.qgs.dc.s7.my.s7connector.enmuc.PlcVarActual; import com.qgs.dc.s7.my.s7connector.enmuc.S7Client; @@ -16,13 +13,12 @@ import org.springframework.web.bind.annotation.*; import java.io.UnsupportedEncodingException; import java.text.ParseException; -import java.util.ArrayList; import java.util.List; @RestController @RequestMapping("/s7") -public class S7Controller { - private static final Logger logger = LoggerFactory.getLogger(S7Controller.class); +public class S7DemoController { + private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class); @Autowired S7Service s7Service; diff --git a/src/main/java/com/qgs/dc/s7/my/s7connector/MainForRead.java b/src/main/java/com/qgs/dc/s7/my/s7connector/MainForRead.java index 9ba192e..438cd82 100644 --- a/src/main/java/com/qgs/dc/s7/my/s7connector/MainForRead.java +++ b/src/main/java/com/qgs/dc/s7/my/s7connector/MainForRead.java @@ -4,6 +4,7 @@ import com.qgs.dc.s7.my.s7connector.api.DaveArea; import com.qgs.dc.s7.my.s7connector.api.S7Connector; import com.qgs.dc.s7.my.s7connector.api.factory.S7ConnectorFactory; import com.qgs.dc.s7.my.s7connector.api.utils.ByteUtils; +import com.qgs.dc.s7.my.s7connector.enmuc.S7Client; import java.util.List; @@ -19,13 +20,15 @@ public class MainForRead { //缺陷: 不支持 DB3.1.1 //Create connection - S7Connector connector = - S7ConnectorFactory - .buildTCPConnector() - .withHost("192.168.0.51") - .withRack(0) //optional rack 是机架号 - .withSlot(0) //optional slot 是插槽号 - .build(); +// S7Connector connector = +// S7ConnectorFactory +// .buildTCPConnector() +// .withHost("192.168.0.51") +// .withRack(0) //optional rack 是机架号 +// .withSlot(0) //optional slot 是插槽号 +// .build(); + + S7Connector connector = S7Client.S7_1200.getConnector(); // // [0] diff --git a/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java b/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java index f33eb97..b6d52d2 100644 --- a/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java +++ b/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java @@ -101,9 +101,10 @@ public enum S7Client { for(int z=0;z