Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plc4j/drivers/s7): fix NoSuchElementException when watchdog ChannelHandler was not added yet & fix exception "MessageToMessageCodec$1 must produce at least one message." & fix some typos #1873

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
Expand Down Expand Up @@ -130,9 +131,8 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf outBB, List<Object> lis
if ((embedCtx == null) && (ctx.channel() instanceof EmbeddedChannel)) embedCtx = ctx;
if ((tcpChannel != null) && (embedCtx == ctx)) {
tcpChannel.writeAndFlush(outBB.copy());
} else {
list.add(outBB.copy());
}
list.add(outBB.copy());
}

/*
Expand Down Expand Up @@ -175,9 +175,14 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
super.userEventTriggered(ctx, evt);
logger.info(LocalTime.now() + " userEventTriggered: " + ctx.name() + " Event: " + evt);

if (evt instanceof ConnectedEvent) {
try {
tcpChannel.pipeline().remove("watchdog");
ChannelHandler watchdog = tcpChannel.pipeline().get("watchdog");
if (watchdog != null) {
tcpChannel.pipeline().remove(watchdog);
}

} catch (Exception ex) {
logger.info(ex.toString());
}
Expand All @@ -199,7 +204,6 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
if (evt instanceof DisconnectEvent) {
logger.info("DisconnectEvent");
}

}

@Override
Expand Down Expand Up @@ -250,7 +254,6 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
embededChannel.pipeline().fireUserEventTriggered(new ConnectEvent());
}
}
;


if ((tcpChannel == secondaryChannel) &&
Expand All @@ -265,10 +268,8 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
embededChannel.pipeline().fireUserEventTriggered(new ConnectEvent());
}
}

}


@Override
public void setEmbededhannel(Channel embeded_channel, PlcConnectionConfiguration configuration) {
final S7Configuration conf = (S7Configuration) configuration;
Expand Down Expand Up @@ -351,5 +352,4 @@ public Channel getTCPChannel() {
return tcpChannel;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void doSecondaryTcpConnections() {
* The user application must take the measures to make the connection again.
*/
protected void sendChannelDisconectEvent() {
logger.trace("Channels was not created, firing DisconnectEvent Event");
logger.trace("Channel was not created, firing DisconnectEvent Event");
// Send an event to the pipeline telling the Protocol filters what's going on.
channel.pipeline().fireUserEventTriggered(new DisconnectEvent());
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public void run() {

if (primaryChannel != null) {
if (!primaryChannel.isActive()) {
logger.info("Creating prymary connection.");
logger.info("Creating primary connection.");
primaryChannel.eventLoop().shutdownGracefully();
doPrimaryTcpConnections();
} else if (null == secondaryChannel) {
Expand All @@ -364,7 +364,7 @@ public void run() {
}
}
} else {
logger.info("Creating firts prymary connection.");
logger.info("Creating first primary connection.");
doPrimaryTcpConnections();
}

Expand All @@ -384,7 +384,7 @@ public void run() {
}
} else {
if (secondaryChannelFactory != null) {
logger.info("Creating firts secondary connection.");
logger.info("Creating first secondary connection.");
doSecondaryTcpConnections();
}
}
Expand Down
Loading