更新 opcua client 版本
This commit is contained in:
parent
83ac4db80f
commit
aa38946d02
14
pom.xml
14
pom.xml
@ -21,24 +21,30 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.milo</groupId>
|
||||
<artifactId>sdk-client</artifactId>
|
||||
<version>0.6.3</version>
|
||||
<version>0.6.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.milo</groupId>
|
||||
<artifactId>stack-client</artifactId>
|
||||
<version>0.6.3</version>
|
||||
<version>0.6.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.milo</groupId>
|
||||
<artifactId>stack-server</artifactId>
|
||||
<version>0.6.3</version>
|
||||
<version>0.6.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.milo</groupId>
|
||||
<artifactId>sdk-server</artifactId>
|
||||
<version>0.6.3</version>
|
||||
<version>0.6.4</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>30.1.1-jre</version>
|
||||
</dependency>
|
||||
<!-- OPC UA 模块依赖 结束 -->
|
||||
|
||||
|
@ -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;
|
@ -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]
|
||||
|
@ -101,9 +101,10 @@ public enum S7Client {
|
||||
for(int z=0;z<c;z++){
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if(connect!=null){
|
||||
logger.info("(check_ping()) 检测到有断线 ==》 现在断线恢复成功");
|
||||
connections.add(connect);
|
||||
}else {
|
||||
logger.info("(check_ping) 断线重连出现异常。。");
|
||||
logger.info("(check_ping()) 检测到有断线 ==》 现在断线恢复失败");
|
||||
}
|
||||
|
||||
}
|
||||
@ -111,13 +112,14 @@ public enum S7Client {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
}catch (Exception e){
|
||||
logger.info("(check_ping)"+e.getMessage());
|
||||
logger.info("(check_ping()) Thread.sleep 异常,异常原因:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//todo 当网络断开之后,下面这个ping() 循环不生效。。 可能是read = connector.read( 出来是null,但还是继续通过了,也可能是 ,,当连接全部断开后 getConnector(); 应该是取不到数据的。。也就会报null。这个明天再看看
|
||||
private void ping(){
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
@ -137,7 +139,7 @@ public enum S7Client {
|
||||
System.out.println(connector.hashCode()+" : ping");
|
||||
Thread.sleep(100);
|
||||
}catch (Exception e){
|
||||
logger.info(connector.hashCode()+" : connection error"+"errMessage is : "+e.getMessage());
|
||||
logger.info("(ping) "+connector.hashCode()+" : connection error"+"errMessage is : "+e.getMessage());
|
||||
//先把 socket close掉
|
||||
try {
|
||||
connector.close();
|
||||
@ -145,22 +147,20 @@ public enum S7Client {
|
||||
//如果是网络波动照成的socket断开。 等个1S 再重连试试
|
||||
Thread.sleep(100);
|
||||
}catch (Exception ee){
|
||||
logger.info("connector.close() 出现异常,errMessage is : "+ee.getMessage());
|
||||
logger.info("(ping) "+"connector.close() 出现异常,errMessage is : "+ee.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//todo 把之前的连接close 掉,然后新增一个连接到connections
|
||||
|
||||
if(connections.size()!=coreSize){
|
||||
int c = coreSize-connections.size();
|
||||
for(int z=0;z<c;z++){
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if(connect!=null){
|
||||
connections.add(connect);
|
||||
}else {
|
||||
logger.info("ping时候出现异常,尝试重连, 重连时候还是 出现异常。。");
|
||||
}
|
||||
|
||||
//todo 把之前的连接close 掉,然后新增一个连接到connections
|
||||
if(connections.size()!=coreSize){
|
||||
int c = coreSize-connections.size();
|
||||
for(int z=0;z<c;z++){
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if(connect!=null){
|
||||
logger.info("(ping) "+"ping时候出现异常,尝试重连, 重连成功!!");
|
||||
connections.add(connect);
|
||||
}else {
|
||||
logger.info("(ping) "+"ping时候出现异常,尝试重连, 重连时候还是 出现异常。。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ public enum S7Client {
|
||||
Thread.sleep(30000);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
logger.info(e.getMessage());
|
||||
logger.info("(ping) "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user