From f1f97ae5386b1dd3200171473c9dd3d5b3171f01 Mon Sep 17 00:00:00 2001 From: Anderson Vasconcelos Pires Date: Wed, 5 Aug 2026 15:56:28 -0300 Subject: [PATCH] fix(plc4j/eip): fix ConnectionManager connectionSerialNumber is out of range to establish connection add missing encoding for unsigned integers to reading tags --- .../plc4x/java/eip/base/EipTcpConnection.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java index a2a920bbbd..3cc402e109 100644 --- a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java +++ b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java @@ -29,10 +29,8 @@ import org.apache.plc4x.java.eip.base.tag.EipTag; import org.apache.plc4x.java.eip.base.tag.EipTagHandler; import org.apache.plc4x.java.eip.readwrite.*; -import org.apache.plc4x.java.spi.buffers.api.WithOption; import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; import org.apache.plc4x.java.spi.buffers.bytebased.ReadBufferByteBased; -import org.apache.plc4x.java.spi.buffers.bytebased.WithByteBasedOption; import org.apache.plc4x.java.spi.buffers.bytebased.WriteBufferByteBased; import org.apache.plc4x.java.utils.subscriptionemulation.PollingSubscriptionConnectionBase; import org.apache.plc4x.java.spi.drivers.exceptions.MessageCodecException; @@ -93,7 +91,7 @@ public class EipTcpConnection extends PollingSubscriptionConnectionBase routingAddress = new ArrayList<>(); private short connectionPathSize = 0; - private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt(); + private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt(1, 0xFFFF); public EipTcpConnection(EIPConfiguration configuration, TransportInstance transportInstance, AuditLog auditLog) { this(configuration, transportInstance, auditLog, configuration.isBigEndian()); @@ -749,7 +747,7 @@ private Map writeErrorMap(DefaultPlcWriteRequest reques // Encoders / decoders //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - private static byte[] toAnsi(String tag) throws BufferException { + private byte[] toAnsi(String tag) throws BufferException { Pattern resourcePattern = Pattern.compile("([.\\[\\]])*([A-Za-z_0-9]+)"); Matcher matcher = resourcePattern.matcher(tag); List segments = new LinkedList<>(); @@ -767,12 +765,7 @@ private static byte[] toAnsi(String tag) throws BufferException { segments.add(newSegment); lengthBytes += newSegment.getLengthInBytes(); } - WriteBufferByteBased buffer = new WriteBufferByteBased(new byte[lengthBytes], - WithByteBasedOption.WithByteOrder("LITTLE_ENDIAN"), - WithOption.WithUnsignedIntegerEncoding("unsigned-binary"), - WithOption.WithSignedIntegerEncoding("twos-complement"), - WithOption.WithFloatEncoding("IEEE754"), - WithOption.WithStringEncoding("UTF8")); + WriteBufferByteBased buffer = messageCodec.createWriteBuffer(lengthBytes); for (PathSegment segment : segments) { segment.serialize(buffer); } @@ -795,8 +788,7 @@ private PlcReadResponse decodeReadResponse(CipService p, PlcReadRequest readRequ List arr = new ArrayList<>(nb); try { byte[] servicesData = responses.getServicesData(); - ReadBufferByteBased read = new ReadBufferByteBased(servicesData, - WithByteBasedOption.WithByteOrder("LITTLE_ENDIAN")); + ReadBufferByteBased read = messageCodec.createReadBuffer(servicesData); int total = servicesData.length; for (int i = 0; i < nb; i++) { int offset = responses.getOffsets().get(i) - responses.getOffsets().getFirst(); @@ -934,8 +926,7 @@ private PlcWriteResponse decodeWriteResponse(CipService p, PlcWriteRequest write List arr = new ArrayList<>(nb); try { byte[] servicesData = resp.getServicesData(); - ReadBufferByteBased read = new ReadBufferByteBased(servicesData, - WithByteBasedOption.WithByteOrder("LITTLE_ENDIAN")); + ReadBufferByteBased read = messageCodec.createReadBuffer(servicesData); int total = servicesData.length; for (int i = 0; i < nb; i++) { int offset = resp.getOffsets().get(i);