44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package com.qgs.dc.s7.service;
|
|
|
|
import org.apache.plc4x.java.PlcDriverManager;
|
|
import org.apache.plc4x.java.api.PlcConnection;
|
|
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
|
|
import org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager;
|
|
import org.apache.plc4x.java.utils.connectionpool2.CachedDriverManager;
|
|
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* @Desc: ""
|
|
* @Author: caixiang
|
|
* @DATE: 2021/9/23 15:16
|
|
*/
|
|
|
|
@Component
|
|
public class S7Service {
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
private HashMap<String, PlcConnection> plcConnections = new HashMap<>();
|
|
private PlcDriverManager driverManager;
|
|
|
|
|
|
public S7Service(){
|
|
driverManager = new PooledPlcDriverManager();
|
|
|
|
}
|
|
|
|
public Integer addPlc(String plcName,String url) throws PlcConnectionException {
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
public PlcConnection getConnection(String url) throws PlcConnectionException {
|
|
return driverManager.getConnection(url);
|
|
}
|
|
}
|