mark
This commit is contained in:
parent
e373cd8e01
commit
eb30974d6d
@ -4,7 +4,9 @@ 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.exception.S7Exception;
|
||||
import com.qgs.dc.s7.my.s7connector.type.PlcVar;
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -27,9 +29,9 @@ import java.util.concurrent.TimeUnit;
|
||||
public enum S7Client {
|
||||
//TODO 步骤1 这里是配置多PLC 的,,,有多个plc 就在这里配置一个枚举类
|
||||
//1500 西门子200smart、1200、1500默认的 机架号=0 槽位号=1; 300/400 默认的 机架-0 插槽-2
|
||||
S7_1500("192.168.0.51",0,1,2,PlcVarActual.HeartBeat),
|
||||
S7_1500("192.168.0.51",0,1,1,PlcVarActual.HeartBeat),
|
||||
//1500 机架-0 插槽-1
|
||||
S7_1200("192.168.0.52",0,1,2,PlcVarActual.HeartBeatFor1200)
|
||||
S7_1200("192.168.0.52",0,1,1,PlcVarActual.HeartBeatFor1200)
|
||||
//后续 在这里扩展 多PLC应用。
|
||||
|
||||
|
||||
@ -70,7 +72,7 @@ public enum S7Client {
|
||||
connectionPool();
|
||||
|
||||
ping();
|
||||
|
||||
//
|
||||
check_ping();
|
||||
}
|
||||
|
||||
@ -268,8 +270,8 @@ public enum S7Client {
|
||||
.withSlot(slot) //optional slot 是插槽号
|
||||
.build();
|
||||
return connector;
|
||||
}catch (Exception e){
|
||||
logger.info("创建S7Connector 连接失败");
|
||||
}catch (S7Exception e){
|
||||
logger.info("创建S7Connector 连接失败,原因:"+e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -277,7 +279,10 @@ public enum S7Client {
|
||||
|
||||
private void connectionPool(){
|
||||
for(int i=0;i<coreSize;i++){
|
||||
connections.add(connect(host,rack,slot));
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if(connect!=null){
|
||||
connections.add(connect);
|
||||
}
|
||||
}
|
||||
//todo 在plc上新增一个 变量来解决 心跳问题 okok
|
||||
}
|
||||
@ -301,10 +306,15 @@ public enum S7Client {
|
||||
|
||||
}
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}catch (Exception e){
|
||||
logger.info(" ( outside check_ping catched ) host:"+host +" ;;(check_ping()) Thread.sleep 异常,异常原因:"+e.getMessage());
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -358,11 +368,17 @@ public enum S7Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread.sleep(30000);
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
logger.info(" ( outside ping catched ) host:"+host +" ;;(ping) "+e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(30000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user