|
|
|
@ -6,6 +6,8 @@ import com.zhehekeji.web.config.ConfigProperties;
|
|
|
|
import com.zhehekeji.web.service.PlcService;
|
|
|
|
import com.zhehekeji.web.service.PlcService;
|
|
|
|
import io.netty.bootstrap.Bootstrap;
|
|
|
|
import io.netty.bootstrap.Bootstrap;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelFuture;
|
|
|
|
|
|
|
|
import io.netty.channel.ChannelFutureListener;
|
|
|
|
import io.netty.channel.EventLoopGroup;
|
|
|
|
import io.netty.channel.EventLoopGroup;
|
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
|
|
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
|
|
|
@ -14,6 +16,8 @@ import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.util.concurrent.locks.Lock;
|
|
|
|
|
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Component
|
|
|
|
@Component
|
|
|
|
@ -28,6 +32,7 @@ public class KsecNettyClient {
|
|
|
|
private static Channel channel;
|
|
|
|
private static Channel channel;
|
|
|
|
|
|
|
|
|
|
|
|
public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
|
|
|
|
public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
|
|
|
|
|
|
|
|
|
|
|
|
String lotnum = FileUtil.getText("lastLotnum");
|
|
|
|
String lotnum = FileUtil.getText("lastLotnum");
|
|
|
|
if(lotnum != null){
|
|
|
|
if(lotnum != null){
|
|
|
|
KsecDecoder.setLastLotnum(lotnum);
|
|
|
|
KsecDecoder.setLastLotnum(lotnum);
|
|
|
|
@ -41,7 +46,18 @@ public class KsecNettyClient {
|
|
|
|
KsecInfo heart = KsecInfo.heart();
|
|
|
|
KsecInfo heart = KsecInfo.heart();
|
|
|
|
client.handler(new KescFilter(heart, plcService,this));
|
|
|
|
client.handler(new KescFilter(heart, plcService,this));
|
|
|
|
// 连接服务端
|
|
|
|
// 连接服务端
|
|
|
|
channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel();
|
|
|
|
|
|
|
|
|
|
|
|
ChannelFuture future = client.connect(ksec.getIp(), ksec.getPort()).sync();
|
|
|
|
|
|
|
|
channel = future.channel();
|
|
|
|
|
|
|
|
future.addListener((ChannelFutureListener) future1 -> {
|
|
|
|
|
|
|
|
if (!future1.isSuccess()) {
|
|
|
|
|
|
|
|
System.err.println("Connection attempt failed");
|
|
|
|
|
|
|
|
future1.cause().printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
future.channel().closeFuture().sync();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -93,6 +109,7 @@ public class KsecNettyClient {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort());
|
|
|
|
log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void write(KsecInfo ksecInfo){
|
|
|
|
public static void write(KsecInfo ksecInfo){
|
|
|
|
|