diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java index d58b8e32c40..d59eb17048c 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HMuxImpl.java @@ -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; @@ -130,9 +131,8 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf outBB, List 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()); } /* @@ -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()); } @@ -199,7 +204,6 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc if (evt instanceof DisconnectEvent) { logger.info("DisconnectEvent"); } - } @Override @@ -250,7 +254,6 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { embededChannel.pipeline().fireUserEventTriggered(new ConnectEvent()); } } - ; if ((tcpChannel == secondaryChannel) && @@ -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; @@ -351,5 +352,4 @@ public Channel getTCPChannel() { return tcpChannel; } - } diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java index ea0a1e258b6..597dfdb8b75 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7HPlcConnection.java @@ -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()); } @@ -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) { @@ -364,7 +364,7 @@ public void run() { } } } else { - logger.info("Creating firts prymary connection."); + logger.info("Creating first primary connection."); doPrimaryTcpConnections(); } @@ -384,7 +384,7 @@ public void run() { } } else { if (secondaryChannelFactory != null) { - logger.info("Creating firts secondary connection."); + logger.info("Creating first secondary connection."); doSecondaryTcpConnections(); } }