This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 7bc60f7a41 fix: Made the S7Light Optimizer allow adding multiple tags 
to the same memory area.
7bc60f7a41 is described below

commit 7bc60f7a415d2b8c722ac37f9009f8c07ac2ace9
Author: Christofer Dutz <christofer.d...@c-ware.de>
AuthorDate: Thu Sep 25 14:30:18 2025 +0200

    fix: Made the S7Light Optimizer allow adding multiple tags to the same 
memory area.
    
    fixes #2277
---
 .../s7light/readwrite/optimizer/S7BlockReadOptimizer.java     | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7light/readwrite/optimizer/S7BlockReadOptimizer.java
 
b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7light/readwrite/optimizer/S7BlockReadOptimizer.java
index 41422a2ad6..c3711586c5 100644
--- 
a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7light/readwrite/optimizer/S7BlockReadOptimizer.java
+++ 
b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7light/readwrite/optimizer/S7BlockReadOptimizer.java
@@ -385,7 +385,16 @@ public class S7BlockReadOptimizer extends S7Optimizer {
                 S7Tag s7Tag2 = (S7Tag) tag2;
                 if (s7Tag1.getByteOffset() == s7Tag2.getByteOffset()) {
                     if (s7Tag1.getBitOffset() == s7Tag2.getBitOffset()) {
-                        return s7Tag1.getNumberOfElements() - 
s7Tag2.getNumberOfElements();
+                        // Include the type and size of the tags into the 
check.
+                        int s7Tag1TypeSizeInBits = s7Tag1.getDataType() == 
TransportSize.BOOL ? 1 : s7Tag1.getDataType().getSizeInBytes() * 8;
+                        int s7Tag1SizeInBits = s7Tag1TypeSizeInBits * 
s7Tag1.getNumberOfElements();
+                        int s7Tag2TypeSizeInBits = s7Tag2.getDataType() == 
TransportSize.BOOL ? 1 : s7Tag2.getDataType().getSizeInBytes() * 8;
+                        int s7Tag2SizeInBits = s7Tag2TypeSizeInBits * 
s7Tag2.getNumberOfElements();
+                        // Tie-breaker, if an identical tag is added multiple 
times.
+                        if(s7Tag1SizeInBits == s7Tag1TypeSizeInBits) {
+                            return 
Integer.compare(System.identityHashCode(s7Tag1), 
System.identityHashCode(s7Tag2));
+                        }
+                        return s7Tag1SizeInBits - s7Tag2SizeInBits;
                     }
                     return s7Tag1.getBitOffset() - s7Tag2.getBitOffset();
                 }

Reply via email to