StrawberryBlue commented on issue #1212: URL: https://github.com/apache/plc4x/issues/1212#issuecomment-1958518903
I continued testing, and when I looped read the data, there was an incomplete message. The test code is as follows ` @Test public void modbusRtuRead(){ try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection(MODBUS_RTU_CONNECT_OPTION)) { while (true) { // Check if this connection support reading of data. if (!connection.getMetadata().isReadSupported()) { log.error("This connection doesn't support reading."); return; } PlcReadRequest.Builder builder = connection.readRequestBuilder(); builder.addTagAddress("value-1", "400001:UINT[100]"); PlcReadRequest readRequest = builder.build(); long start = System.currentTimeMillis(); PlcReadResponse response = null; response = readRequest.execute().get(5000, TimeUnit.MILLISECONDS); if (response != null) { for (String tagName : response.getTagNames()) { if (response.getResponseCode(tagName) == PlcResponseCode.OK) { int numValues = response.getNumberOfValues(tagName); // If it's just one element, output just one single line. if (numValues == 1) { log.info("Value[" + tagName + "]: " + response.getObject(tagName)); } // If it's more than one element, output each in a single row. else { log.info("Value[" + tagName + "]:"); for (int i = 0; i < numValues; i++) { log.info(" - " + response.getObject(tagName, i)); } } } // Something went wrong, to output an error message instead. else { log.error("Error[" + tagName + "]: " + response.getResponseCode(tagName).name()); } } } long end = System.currentTimeMillis(); System.out.println(end - start); Thread.sleep(50); } } catch (Exception e) { throw new RuntimeException(e); } }` After a period of program execution, there may be a half package situation, The complete response message should be '0103c8000100000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064a2ba', but the program cannot correctly parse the message due to two returns. Should length verification be added to the modbus return message. The error message is as follows `2024-02-22 09:41:33.469 WARN 19404 --- [ntLoopGroup-2-1] .p.j.s.GeneratedDriverByteToMessageCodec : Error decoding package with content [0103c8000100000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]: Index 159 out of bounds for length 159 java.lang.ArrayIndexOutOfBoundsException: Index 159 out of bounds for length 159 at com.github.jinahya.bit.io.ArrayByteInput.read(ArrayByteInput.java:106) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.DefaultBitInput.read(DefaultBitInput.java:57) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.AbstractBitInput.unsigned8(AbstractBitInput.java:63) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.AbstractBitInput.unsigned16(AbstractBitInput.java:92) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.AbstractBitInput.readInt(AbstractBitInput.java:135) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.AbstractBitInput.readInt(AbstractBitInput.java:118) ~[bit-io-1.4.3.jar:na] at com.github.jinahya.bit.io.AbstractBitInput.readByte(AbstractBitInput.java:106) ~[bit-io-1.4.3.jar:na] at org.apache.plc4x.java.spi.generation.ReadBufferByteBased.readSignedByte(ReadBufferByteBased.java:388) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.generation.ReadBuffer.readByte(ReadBuffer.java:44) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.generation.ReadBufferByteBased.readByteArray(ReadBufferByteBased.java:126) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusPDUReadHoldingRegistersResponse.staticParseModbusPDUBuilder(ModbusPDUReadHoldingRegistersResponse.java:112) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusPDU.staticParse(ModbusPDU.java:181) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusRtuADU.lambda$0(ModbusRtuADU.java:132) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.io.DataReaderComplexDefault.read(DataReaderComplexDefault.java:70) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.io.DataReaderComplexDefault.read(DataReaderComplexDefault.java:61) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderSimple.lambda$0(FieldReaderSimple.java:34) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.FieldCommons.switchParseByteOrderIfNecessary(FieldCommons.java:52) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderSimple.readSimpleField(FieldReaderSimple.java:34) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderFactory.readSimpleField(FieldReaderFactory.java:133) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusRtuADU.staticParseModbusADUBuilder(ModbusRtuADU.java:129) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusADU.staticParse(ModbusADU.java:117) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusADU.staticParse(ModbusADU.java:103) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.rtu.ModbusRtuDriver.lambda$0(ModbusRtuDriver.java:130) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.GeneratedDriverByteToMessageCodec.decode(GeneratedDriverByteToMessageCodec.java:87) ~[plc4j-spi-0.12.0.jar:0.12.0] at io.netty.handler.codec.ByteToMessageCodec$1.decode(ByteToMessageCodec.java:42) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at org.apache.plc4x.java.transport.serial.SerialChannel$SerialNioUnsafe.read(SerialChannel.java:285) ~[plc4j-transport-serial-0.12.0.jar:0.12.0] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:689) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:652) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na] 2024-02-22 09:41:33.471 WARN 19404 --- [ntLoopGroup-2-1] .p.j.s.GeneratedDriverByteToMessageCodec : Error decoding package with content [0000000000000000000000000000000000000000000000000000000000000000000000000000000000000064a2ba]: Unsupported case for discriminated type parameters [errorFlag=false functionFlag=0 response=true] org.apache.plc4x.java.spi.generation.ParseException: Unsupported case for discriminated type parameters [errorFlag=false functionFlag=0 response=true] at org.apache.plc4x.java.modbus.readwrite.ModbusPDU.staticParse(ModbusPDU.java:310) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusRtuADU.lambda$0(ModbusRtuADU.java:132) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.io.DataReaderComplexDefault.read(DataReaderComplexDefault.java:70) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.io.DataReaderComplexDefault.read(DataReaderComplexDefault.java:61) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderSimple.lambda$0(FieldReaderSimple.java:34) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.FieldCommons.switchParseByteOrderIfNecessary(FieldCommons.java:52) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderSimple.readSimpleField(FieldReaderSimple.java:34) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.codegen.fields.FieldReaderFactory.readSimpleField(FieldReaderFactory.java:133) ~[plc4j-spi-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusRtuADU.staticParseModbusADUBuilder(ModbusRtuADU.java:129) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusADU.staticParse(ModbusADU.java:117) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.readwrite.ModbusADU.staticParse(ModbusADU.java:103) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.modbus.rtu.ModbusRtuDriver.lambda$0(ModbusRtuDriver.java:130) ~[plc4j-driver-modbus-0.12.0.jar:0.12.0] at org.apache.plc4x.java.spi.GeneratedDriverByteToMessageCodec.decode(GeneratedDriverByteToMessageCodec.java:87) ~[plc4j-spi-0.12.0.jar:0.12.0] at io.netty.handler.codec.ByteToMessageCodec$1.decode(ByteToMessageCodec.java:42) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103) ~[netty-codec-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at org.apache.plc4x.java.transport.serial.SerialChannel$SerialNioUnsafe.read(SerialChannel.java:285) ~[plc4j-transport-serial-0.12.0.jar:0.12.0] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:689) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:652) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.94.Final.jar:4.1.94.Final] at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@plc4x.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org