You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by "andvasp (via GitHub)" <gi...@apache.org> on 2026/08/05 19:49:27 UTC
[PR] fix(plc4j/eip): fix ConnectionManager
andvasp opened a new pull request, #2673:
URL: https://github.com/apache/plc4x/pull/2673
The field connectionSerialNumber is out of range to establish connection
Add missing encoding for unsigned integers to reading tags
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3747018419
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -93,7 +91,7 @@ public class EipTcpConnection extends PollingSubscriptionConnectionBase<EIPConfi
private final NullAddressItem nullAddressItem = new NullAddressItem();
private final List<PathSegment> routingAddress = new ArrayList<>();
private short connectionPathSize = 0;
- private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt();
+ private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt(1, 0xFFFF);
Review Comment:
Think I'm just going to merge this and fix this myself after merging ... don't want to go another set of rounds for this tiny change.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3746998592
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -93,7 +91,7 @@ public class EipTcpConnection extends PollingSubscriptionConnectionBase<EIPConfi
private final NullAddressItem nullAddressItem = new NullAddressItem();
private final List<PathSegment> routingAddress = new ArrayList<>();
private short connectionPathSize = 0;
- private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt();
+ private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt(1, 0xFFFF);
Review Comment:
`ThreadLocalRandom.nextInt(origin, bound)` uses an exclusive upper bound, so `nextInt(1, 0xFFFF)` will never produce `0xFFFF` (65535). If the intent is the full 16-bit unsigned range (or 1..65535), use an exclusive bound of `0x1_0000` to avoid an off-by-one and make the range explicit.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3731550680
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
I think my system used Little endian and my code was obviously bad. So making it dynamic like in the other cases is the way forward ... if you find more places, where I created the buffer manually, I think it would be good to allways use the transportCodec functions for generating them.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "andvasp (via GitHub)" <gi...@apache.org>.
andvasp commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3731644576
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
> if you find more places, where I created the buffer manually, I think it would be good to allways use the
> transportCodec functions for generating them.
I found places using LITTLE_ENDIAN not creating the buffer but ByteBuffer show below. I do not know if would be a problem.
What do you think?
```java
private byte[] encodeValue(PlcValue value, CIPDataTypeCode type) {
ByteBuffer buffer = ByteBuffer.allocate(type.getSize()).order(ByteOrder.LITTLE_ENDIAN);
```
```java
private PlcValue parsePlcValue(EipTag tag, byte[] rawData, CIPDataTypeCode type) {
final int STRING_LEN_OFFSET = 2;
final int STRING_DATA_OFFSET = 6;
ByteBuffer data = ByteBuffer.wrap(rawData).order(ByteOrder.LITTLE_ENDIAN);
```
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3724123802
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
I'm a bit surprized this would work ... if I look in mspec, the type PathSegment doesn't define the different encodings. So they should be null if you remove them all. It should require setting the unsigned integer and the string encodings. Also would you be changing the endianess from little-endian to big-endian.
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -93,7 +91,7 @@ public class EipTcpConnection extends PollingSubscriptionConnectionBase<EIPConfi
private final NullAddressItem nullAddressItem = new NullAddressItem();
private final List<PathSegment> routingAddress = new ArrayList<>();
private short connectionPathSize = 0;
- private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt();
+ private final int connectionSerialNumber = ThreadLocalRandom.current().nextInt(1, 0xFFFF);
Review Comment:
Great job spotting this ... indeed the field is defined as unsigned int 16 bit ... and for that 0xFFFF is indeed the max value.
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
If you look at EipTcpMessageCodec this should take care of creating the write buffer with a call to "createWriteBuffer" ... this should also automatically handle the case of a big-endian and little-endian device. So I think your system might be a big-endian one and for that reason this part of the code probably failed and removing the byte order should make it default to big-endian.
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -795,8 +788,7 @@ private PlcReadResponse decodeReadResponse(CipService p, PlcReadRequest readRequ
List<CipService> arr = new ArrayList<>(nb);
try {
byte[] servicesData = responses.getServicesData();
- ReadBufferByteBased read = new ReadBufferByteBased(servicesData,
- WithByteBasedOption.WithByteOrder("LITTLE_ENDIAN"));
+ ReadBufferByteBased read = messageCodec.createReadBuffer(servicesData);
Review Comment:
As mentioned in the other change ... I assume the problem you were having was that your system was a big-endian one and all of mine were little-endian ones. This change looks a lot better than the one in lines 774++
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "andvasp (via GitHub)" <gi...@apache.org>.
andvasp commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3731015711
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
> I'm a bit surprized this would work ... if I look in mspec, the type PathSegment doesn't define the different encodings. So they should be null if you remove them all. It should require setting the unsigned integer and the string encodings. Also would you be changing the endianess from little-endian to big-endian.
Now that you mentioned the point about byte order, I am surprised too why it was working because it looks like it is mixing the byte order. Let me summarise my scenario:
- I did not change the configuration of the byte order. So I am using big endian.
- I can read the value of most of the tags.
- There are some tags that I cannot, even on same device (addressing this issue later) but I did not check them after the modification of this PR.
- I did not have the opportunity to test the write value but I can and I plan to do.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "andvasp (via GitHub)" <gi...@apache.org>.
andvasp commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3730942253
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
Yes. I am using EipTcpMessageCodec to create the buffer. Look at added line below.
There are other places on EipTcpConnection that is using LITTLE_ENDIAN (encodeValue and parsePlcValue). Shold be used the byte order from configuration?
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "andvasp (via GitHub)" <gi...@apache.org>.
andvasp commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3730954241
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -795,8 +788,7 @@ private PlcReadResponse decodeReadResponse(CipService p, PlcReadRequest readRequ
List<CipService> arr = new ArrayList<>(nb);
try {
byte[] servicesData = responses.getServicesData();
- ReadBufferByteBased read = new ReadBufferByteBased(servicesData,
- WithByteBasedOption.WithByteOrder("LITTLE_ENDIAN"));
+ ReadBufferByteBased read = messageCodec.createReadBuffer(servicesData);
Review Comment:
I tested here just changing "LITTLE_ENDIAN" to "BIG_ENDIAN" and still raising the same error: "No encoding defined for unsigned integer values" when using connection manager.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#issuecomment-5208744142
Argh!!!! ... stupid signatures :-( (I think we're stalled here till that "feature" is turned off again :-( )
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz merged PR #2673:
URL: https://github.com/apache/plc4x/pull/2673
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(plc4j/eip): fix ConnectionManager
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on code in PR #2673:
URL: https://github.com/apache/plc4x/pull/2673#discussion_r3731560808
##########
plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EipTcpConnection.java:
##########
@@ -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"),
Review Comment:
Also just noticed that you already had it right ... I shouldn't play with crazy protocols to deep in the night ;-) Sorry for the confusion ... will approve it right away.
--
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: commits-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org