Hi Vlad, I didn't miss the email, but for me it's almost impossible to give you an advice to what might be going wrong. The error you are getting I usually got in the past as soon as I send out something the PLC doesn't like. Just recently when we didn't reset the message-id counters and they overflowed, some PLCs just hung up.
So what I would do, would be to use WireShark to check what's actually going over the wire and to check if this is ok. If it's not, well you know what to fix. Chris Am 17.09.20, 11:56 schrieb "Vladyslav Milutin" <[email protected]>: Hi guys, I just will resend this message in case you missed it. Hi guys, I can send you this code, which doesn't have much business logic, and all params are renamed. public abstract class LalelDriver<T extends Message> extends GeneratedDriverBase<T> { private final ChannelHandler handler; @Override public String getProtocolName() { return "Lalel"; } @Override protected Class<? extends Configuration> getConfigurationType() { return LalelConfiguration.class; } @Override protected String getDefaultTransport() { return "tcp"; } @Override protected boolean canSubscribe() { return true; } @Override protected LalelFieldHandler getFieldHandler() { return new LalelFieldHandler(); } @Override protected void initializePipeline(ChannelFactory channelFactory) { try { final Channel channel = channelFactory.createChannel(this.handler); channelFactory.initializePipeline(channel.pipeline()); } catch (PlcConnectionException e) { log.error("Failed to create channel"); } } } public classLalelDriverTcp extends LalelDriver<EthernetMessage> { public LalelDriverTcp(final ChannelHandler handler){ super(handler); } @Override public String getProtocolCode() { return "lalel-tcp"; } @Override protected ProtocolStackConfigurer<EthernetMessage> getStackConfigurer() { return DriverUtils.buildStackConfigurer( EthernetMessage.class, EthernetMessageIO.class, LalelProtocolLogicTcp.class, ByteLengthEstimator.class ); } /** * Estimate the Length of a Packet */ public static class ByteLengthEstimator implements ToIntFunction<ByteBuf> { @Override public int applyAsInt(ByteBuf byteBuf) { if (byteBuf.readableBytes() >= 2) { return byteBuf.getUnsignedShortLE(byteBuf.readerIndex()); } return -1; } } } And connection code: this.connection = driver.getConnection(connectionString); this.connection.connect(); Kind regards, Vlad Kind regards, Vlad чт, 17 сент. 2020 г. в 12:09, Christofer Dutz <[email protected]>: > Hi Vlad, > > 0.8.0-SNAPSHOT is the current development version ... > we'll be releasing that as soon as we tied up some things we're currently > working on. > > Chris > > > > Am 17.09.20, 11:02 schrieb "Vladyslav Milutin" <[email protected]>: > > Hi Stefano, > > I'm curious about the 0.8.0 version, where I can find it? Since maven > repo > contains the latest version 0.7.0. > > Kind regards, > Vlad > > ср, 16 сент. 2020 г. в 17:30, Stefano Bossi <[email protected]>: > > > Hi Vlad, > > > > this seems similar to a bug fixed some time ago, I am not really > sure but > > it worth to try to use the 0.8.0 version where this fix is present. > > > > You should try to build the version and here you could fine some > help: > > https://plc4x.apache.org/developers/index.html > > > > Regards, > > Stefano > > > > On 16/09/2020 14:32, Vladyslav Milutin wrote: > > > > Hello guys, > > > > I'm writing to you with a hope that you can help me with exception > > handling. > > Currently after a long time connection can be reset by peer. See > stacktrace > > below. > > > > I've tried to add a custom ChannelHandler which Overrides > exceptionCaught() > > and add it in Driver#initializePipeline() see code below. Also has > tried to > > add a channel that can be obtained from DefaultNettyPlcConnection. > And none > > of them actualy was added to the pipeline where this exception was > thrown. > > > > plc4x version: 0.7.0 > > > > StatckTrace: > > 2020-09-16 13:50:03.340 WARN [nioEventLoopGroup-58-1] > > [io.netty.channel.DefaultChannelPipeline] > onUnhandledInboundException - An > > exceptionCaught() event was fired, and it reached at the tail of the > > pipeline. It usually means the last handler in the pipeline did not > handle > > the exception. > > java.io.IOException: Connection reset by peer > > at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method) > > at java.base/sun.nio.ch > .SocketDispatcher.read(SocketDispatcher.java:39) > > at > java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276) > > at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233) > > at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223) > > at java.base/sun.nio.ch > .SocketChannelImpl.read(SocketChannelImpl.java:358) > > at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253) > > at > io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133) > > at > > > io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350) > > at > > > io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148) > > at > > > io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) > > at > > > io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) > > at > > > io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) > > at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) > > at > > > io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) > > at > > > io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) > > at > > > io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) > > at java.base/java.lang.Thread.run(Thread.java:834) > > > > Driver#initializePipeline: > > try { > > final Channel channel = > > channelFactory.createChannel(this.handler); > > channelFactory.initializePipeline(channel.pipeline()); > > > > } catch (PlcConnectionException e) { > > log.error("Failed to create channel"); > > } > > > > ChannelHandler: > > @Override > > public void exceptionCaught(ChannelHandlerContext ctx, Throwable > cause) > > { > > log.warn("ExceptionCaught in worker: ctx = [{}], cause = > [{}, {}], > > workerName = [{}]", > > ctx, cause.getClass(), cause.getMessage(), > workerName); > > if (cause instanceof ConnectTimeoutException) { > > log.warn("ConnectionTimeout caught: workerName = [{}]", > > workerName); > > } > > if ((cause instanceof IOException) && > > cause.getMessage().contains("Connection reset by peer")) { > > log.warn("Connection reset by peer caught: workerName = > [{}]", > > workerName); > > } else { > > log.info("Unexpected exception caught: workerName = > [{}]", > > workerName); > > } > > > > this.callback.accept(cause); > > } > > > > DefaultNettyPlcConnection#channel:log.info("Trying to get > connection channel: worker name = [{}]", > > this.workerName); > > final Channel channel = ((DefaultNettyPlcConnection) > > this.connection).getChannel(); > > log.info("Channel obtained successfully. Adding custom > > channelHandler to it: channel = [{}], workerName = [{}]", channel, > > this.workerName); > > channel.pipeline().addLast(this.channelHandler); > > log.info("ChannelHandler added: channel = [{}], > channelHandler = > > [{}], workerName = [{}]", channel, this.channelHandler, > this.workerName); > > > > Kind regards, > > Vlad > > > > > > > > > >
