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

cgarcia pushed a commit to branch feature/merlot
in repository https://gitbox.apache.org/repos/asf/plc4x-extras.git


The following commit(s) were added to refs/heads/feature/merlot by this push:
     new 095ef8f  Fix Modbus/S7 support functions.
095ef8f is described below

commit 095ef8f922b7be201b75311ed0887ef505ed9c87
Author: César García <[email protected]>
AuthorDate: Wed Oct 23 22:19:58 2024 -0400

    Fix Modbus/S7 support functions.
---
 .../java/org/apache/plc4x/merlot/api/PlcItem.java  |  2 +-
 .../apache/plc4x/merlot/api/PlcTagFunction.java    | 15 ++++----
 .../plc4x/merlot/api/command/DemoCommand004.java   |  2 +-
 .../plc4x/merlot/api/impl/PlcDeviceImpl.java       |  4 +-
 .../plc4x/merlot/api/impl/PlcDeviceWriteEvent.java | 19 ++++++---
 .../apache/plc4x/merlot/api/impl/PlcItemImpl.java  |  5 ++-
 .../org/apache/plc4x/merlot/db/api/DBRecord.java   | 37 ++++++++++++++++--
 .../apache/plc4x/merlot/db/core/DBBaseFactory.java |  9 +++--
 .../plc4x/merlot/db/core/DBBooleanFactory.java     | 35 +++++++++++------
 .../apache/plc4x/merlot/db/core/DBByteFactory.java |  9 +++--
 .../plc4x/merlot/db/core/DBDoubleFactory.java      |  9 +++--
 .../plc4x/merlot/db/core/DBFloatFactory.java       | 11 +++---
 .../apache/plc4x/merlot/db/core/DBIntFactory.java  |  9 +++--
 .../apache/plc4x/merlot/db/core/DBLongFactory.java |  9 +++--
 .../merlot/db/core/DBRecordsManagedService.java    |  2 +-
 .../plc4x/merlot/db/core/DBShortFactory.java       |  9 +++--
 .../plc4x/merlot/db/core/DBStringFactory.java      |  5 ++-
 .../plc4x/merlot/db/core/DBUByteFactory.java       |  9 +++--
 .../apache/plc4x/merlot/db/core/DBUIntFactory.java |  9 +++--
 .../plc4x/merlot/db/core/DBULongFactory.java       |  9 +++--
 .../plc4x/merlot/db/core/DBUShortFactory.java      |  9 +++--
 .../apache/plc4x/merlot/db/impl/DBPersistImpl.java |  4 +-
 .../plc4x/merlot/db/impl/DBWriterHandlerImpl.java  |  2 +-
 .../drv/mb/impl/ModbusPlcTagFunctionImpl.java      |  8 ++--
 .../merlot/drv/s7/impl/S7PlcTagFunctionImpl.java   | 45 +++++++++++-----------
 .../impl/SimulatedPlcTagFunctionImpl.java          | 10 ++---
 26 files changed, 181 insertions(+), 115 deletions(-)

diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcItem.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcItem.java
index 66c9199..89a8c2b 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcItem.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcItem.java
@@ -222,6 +222,6 @@ public interface PlcItem {
     /*
     *
     */    
-    public void itemWrite(final ByteBuf byteBuf, int offset);
+    public void itemWrite(final ByteBuf byteBuf, int byteOffset, byte 
bitOffset);
     
 }
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcTagFunction.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcTagFunction.java
index 38e39a4..2cf0802 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcTagFunction.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcTagFunction.java
@@ -34,16 +34,17 @@ import org.osgi.service.dal.Function;
  */
 public interface PlcTagFunction  extends Function {
         
-    
     /*
     * PlcTag reference for constructing the String that represents 
-    * the write tag.
+    * the write tag
     *
-    * @param plcTag PlcTag reference PlcTag 
-    * @paraf byteBuf ByteBuf
-    * @paraf offset 
-    * @return 
+    * @param plcTag
+    * @param byteBuf
+    * @param byteOffset
+    * @param byteOffset
+    * @return
     */
-    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int offset);    
+
+    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int byteOffset, byte bitOffset);    
     
 }
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
index 08f7fb7..31d9e11 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
@@ -116,7 +116,7 @@ public class DemoCommand004  implements Action  {
                             optPlcDevice.get().getUid().toString(),
                             "S7BOOLS_" + i,
                             "Item description _" + i,
-                            "%DB100:50.0:BOOL[8]",
+                            "%MB190:BYTE[20]",
                             "true");
                     if (optPlcItem.isPresent()){
                         optPlcItem.get().enable();
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
index bc23883..b92e4d3 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
@@ -231,7 +231,7 @@ public class PlcDeviceImpl implements PlcDevice {
                                     if (null != plcTagFunction) { 
                                         
writeBuffer.add(plcTagFunction.getPlcTag(
                                             
event.getPlcItem().getItemPlcTag(), 
-                                            event.getByteBuf(), 
event.getOffset()));
+                                            event.getByteBuf(), 
event.getByteOffset(), event.getBitOffset()));
                                     }
 
                                     /*
@@ -241,7 +241,7 @@ public class PlcDeviceImpl implements PlcDevice {
                                     */
                                     if ((messageCounter[0] > 
DEFAULT_WRITE_BATCH_SIZE) || (endofbatch)) {
                                         if (!writeBuffer.isEmpty()) {
-                                            System.out.println("PLCCONNECTION: 
" +  refPlcConnection.get().toString());
+
                                             final Builder builder = 
refPlcConnection.get().writeRequestBuilder();
 
                                             writeBuffer.forEach(i -> {
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceWriteEvent.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceWriteEvent.java
index 02710da..fb9eb35 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceWriteEvent.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceWriteEvent.java
@@ -22,7 +22,8 @@ import org.apache.plc4x.merlot.api.PlcItem;
 public class PlcDeviceWriteEvent {
     private PlcItem plcItem;
     private ByteBuf byteBuf;
-    private int offset;
+    private int byteOffset;
+    private byte bitOffset;
 
     public PlcItem getPlcItem() {
         return plcItem;
@@ -40,13 +41,21 @@ public class PlcDeviceWriteEvent {
         this.byteBuf = byteBuf;
     } 
     
-    public int getOffset() {
-        return offset;
+    public int getByteOffset() {
+        return byteOffset;
     }
     
-    public void setOffset(int offset) {
-        this.offset = offset;
+    public void setByteOffset(int byteOffset) {
+        this.byteOffset = byteOffset;
     }    
     
+    public byte getBitOffset() {
+        return bitOffset;
+    }
+    
+    public void setBitOffset(int bitOffset) {
+        this.bitOffset = (byte) bitOffset;
+    }     
+    
     
 }
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
index be3251d..bff0b88 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
@@ -342,7 +342,7 @@ public class PlcItemImpl implements PlcItem {
     }
 
     @Override
-    public void itemWrite(final ByteBuf byteBuf, int offset) {
+    public void itemWrite(final ByteBuf byteBuf, int byteOffset, byte 
bitOffset) {
         if (null == writeRingBuffer) {
             LOGGER.info("*** Rinbuffer es null ***");
             return;
@@ -351,7 +351,8 @@ public class PlcItemImpl implements PlcItem {
         final PlcDeviceWriteEvent writeEvent = 
writeRingBuffer.get(sequenceId); 
         writeEvent.setPlcItem(this);
         writeEvent.setByteBuf(byteBuf);
-        writeEvent.setOffset(offset);
+        writeEvent.setByteOffset(byteOffset);
+        writeEvent.setBitOffset(bitOffset);        
         writeRingBuffer.publish(sequenceId);
     }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
index ddcadd8..b4e2fa5 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
@@ -22,6 +22,8 @@ package org.apache.plc4x.merlot.db.api;
 
 import io.netty.buffer.ByteBuf;
 import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.apache.plc4x.merlot.api.PlcItem;
 import org.epics.pvdata.pv.PVStructure;
 import org.epics.pvdatabase.PVRecord;
@@ -41,11 +43,23 @@ public class DBRecord extends PVRecord  {
     protected static final String MONITOR_VALUE_FIELD = "field(value)";
     protected static final String MONITOR_WRITE_FIELD = "field(write_value)"; 
     
+    private static final Pattern BYTE_OFFSET_PATTERN = 
+             Pattern.compile("(?<byteOffset>\\d{1,5})");
+    
+    private static final Pattern BIT_OFFSET_PATTERN = 
+             Pattern.compile( 
"(?<byteOffset>\\d{1,5}).(?<bitOffset>\\d{1,5})");
+    
+    protected static final String BYTE_OFFSET = "byteOffset";
+    protected static final String BIT_OFFSET = "bitOffset"; 
+    
+    protected int byteOffset = -1;
+    protected byte bitOffset = -1;    
+    
     
     protected PlcItem plcItem = null; 
     protected ByteBuf innerBuffer = null; 
     protected ByteBuf innerWriteBuffer = null;     
-    protected  int offset = 0;      
+   
     
     public DBRecord(String recordName, PVStructure pvStructure) {
         super(recordName, pvStructure);
@@ -66,13 +80,30 @@ public class DBRecord extends PVRecord  {
         return Optional.of(innerWriteBuffer);
     };    
     
-    public int getOffset(){
-        return offset;
+    public int getByteOffset(){
+        return byteOffset;
     }
     
+    public byte getBiteOffset(){
+        return bitOffset;
+    }    
+    
+    
     public String getFieldsToMonitor(){
         return MONITOR_VALUE_FIELD;
     };
     
+    public void getOffset(String strOffset){
+        Matcher matcher;
+        if ((matcher = BYTE_OFFSET_PATTERN.matcher(strOffset)).matches()){
+            byteOffset = Integer.parseInt(matcher.group(BYTE_OFFSET ));
+        } else if ((matcher = 
BIT_OFFSET_PATTERN.matcher(strOffset)).matches()){
+            byteOffset = Integer.parseInt(matcher.group(BYTE_OFFSET ));
+            bitOffset  = (byte) Integer.parseInt(matcher.group(BIT_OFFSET ));  
          
+        }
+    }
+    
+    
+    
     
 }
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
index e271a02..2d54518 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.merlot.db.core;
 
+import java.util.regex.Pattern;
 import org.apache.plc4x.merlot.db.api.DBRecord;
 import org.apache.plc4x.merlot.db.api.DBRecordFactory;
 import org.epics.pvdata.copy.CreateRequest;
@@ -32,8 +33,8 @@ import org.slf4j.LoggerFactory;
 
 //TODO: Replace string processing with with regex.
 public class DBBaseFactory implements DBRecordFactory  {
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(DBBaseFactory.class); 
-    
+    protected static final Logger LOGGER = 
LoggerFactory.getLogger(DBBaseFactory.class); 
+         
     @Override
     public DBRecord create(String recordName) {
         throw new UnsupportedOperationException("Not supported yet.");
@@ -79,8 +80,8 @@ public class DBBaseFactory implements DBRecordFactory  {
             } else return null;
 
             if (!fields[2].isEmpty()) {          
-                PVInt pvInt = structure.getIntField("offset");
-                pvInt.put(Integer.parseInt(fields[2]));
+                PVString pvStrOffset = structure.getStringField("offset");
+                pvStrOffset.put(fields[2]);
             } else return null;             
             
             if (!fields[3].isEmpty()) {          
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
index 1855849..8db87f6 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
@@ -48,7 +48,7 @@ public class DBBooleanFactory extends DBBaseFactory {
             value(ScalarType.pvBoolean).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)). 
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -70,7 +70,7 @@ public class DBBooleanFactory extends DBBaseFactory {
             value(ScalarType.pvBoolean).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)). 
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -92,6 +92,7 @@ public class DBBooleanFactory extends DBBaseFactory {
         private PVBoolean value;
         private PVBoolean write_value;
         private PVBoolean write_enable;
+        private boolean blnValue = false;
                  
         public DBBooleanRecord(String recordName,PVStructure pvStructure) {
             super(recordName, pvStructure);
@@ -120,14 +121,13 @@ public class DBBooleanFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             try {
-            this.plcItem = plcItem;
-                offset = this.getPVStructure().getIntField("offset").get() * 
Byte.BYTES;              
-                innerBuffer = plcItem.getItemByteBuf().slice(offset, 
Byte.BYTES);
+                this.plcItem = plcItem;
+                //offset = this.getPVStructure().getIntField("offset").get() * 
Byte.BYTES; 
+                getOffset( 
this.getPVStructure().getStringField("offset").get());
+                innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Byte.BYTES);
                 innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
             } catch (Exception ex) {
-                System.out.println("Falla al atach()");
-                System.out.println(plcItem.toString());
-                ex.printStackTrace();
+                LOGGER.error(this.getClass().getName() + " : " + 
ex.getMessage());
             }
         }
 
@@ -136,11 +136,24 @@ public class DBBooleanFactory extends DBBaseFactory {
             this.plcItem  = null;
         }
 
+        /*
+        * 
***************************************************************************
+        * Modbus      : Return a array of bytes, where every byte is a boolean.
+        * S7          : Return a array of bytes, where every byte, packet 8 
booleans.        
+        * Ethernet/IP : TODO:
+        * 
***************************************************************************     
   
+        */
         @Override
         public void update() {
-            if (null != plcItem)      
-                if (value.get() != innerBuffer.getBoolean(0))                  
  
-                    value.put(innerBuffer.getBoolean(0));
+            if (null != plcItem)   {   
+                if (bitOffset == -1) {
+                    if (value.get() != innerBuffer.getBoolean(0))              
      
+                        value.put(innerBuffer.getBoolean(0));
+                } else {
+                    blnValue = ((innerBuffer.getByte(0) >> bitOffset & 1) == 
1);
+                    value.put(blnValue);
+                }
+            }
         }
 
         @Override
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
index ea66b02..e45fc6a 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
@@ -54,7 +54,7 @@ public class DBByteFactory extends DBBaseFactory {
             value(ScalarType.pvByte).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)). 
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -76,7 +76,7 @@ public class DBByteFactory extends DBBaseFactory {
             value(ScalarType.pvByte).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).  
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).   
@@ -125,8 +125,9 @@ public class DBByteFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get() * 
Byte.BYTES;    
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Byte.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get() * 
Byte.BYTES;  
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Byte.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
index 07de6c6..3a99a7a 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
@@ -48,7 +48,7 @@ public class DBDoubleFactory extends DBBaseFactory {
             value(ScalarType.pvDouble).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -70,7 +70,7 @@ public class DBDoubleFactory extends DBBaseFactory {
             value(ScalarType.pvDouble).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).   
@@ -119,8 +119,9 @@ public class DBDoubleFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
       
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Double.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get(); 
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Double.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
index c23ef44..c506d89 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
@@ -48,7 +48,7 @@ public class DBFloatFactory extends DBBaseFactory {
             value(ScalarType.pvFloat).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).  
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
          
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
             
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -70,7 +70,7 @@ public class DBFloatFactory extends DBBaseFactory {
             value(ScalarType.pvFloat).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
          
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
             
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -98,7 +98,7 @@ public class DBFloatFactory extends DBBaseFactory {
             value = pvStructure.getFloatField("value");
             write_value = pvStructure.getFloatField("write_value");
             write_enable = pvStructure.getBooleanField("write_enable");
-            offset = pvStructure.getIntField("offset").get();  
+            //offset = pvStructure.getIntField("offset").get();  
         }    
 
         /**
@@ -120,8 +120,9 @@ public class DBFloatFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem; 
-            offset = this.getPVStructure().getIntField("offset").get();        
   
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Float.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get();  
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Float.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
index e4df2f5..b8d9023 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
@@ -47,7 +47,7 @@ public class DBIntFactory extends DBBaseFactory {
             value(ScalarType.pvInt).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -69,7 +69,7 @@ public class DBIntFactory extends DBBaseFactory {
             value(ScalarType.pvInt).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -118,8 +118,9 @@ public class DBIntFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
     
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, 
Integer.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get();  
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Integer.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
index 187f19b..97450c6 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
@@ -47,7 +47,7 @@ public class DBLongFactory extends DBBaseFactory {
             value(ScalarType.pvLong).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -69,7 +69,7 @@ public class DBLongFactory extends DBBaseFactory {
             value(ScalarType.pvLong).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -118,8 +118,9 @@ public class DBLongFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
       
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Long.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get();    
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Long.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
index ba95bad..5b57d52 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
@@ -171,7 +171,7 @@ public class DBRecordsManagedService implements 
ManagedServiceFactory, Job {
                 } else {
                     strScalarType = dataFields[0];
                 }
-                
+
                 recordFactory = getRecordFactory(strScalarType);
                 
                 if (recordFactory != null){
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
index 37cada1..38ae653 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
@@ -51,7 +51,7 @@ public class DBShortFactory extends DBBaseFactory {
             value(ScalarType.pvShort).
             addDescriptor().            
             add("id", fieldCreate.createScalar(ScalarType.pvString)).  
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -74,7 +74,7 @@ public class DBShortFactory extends DBBaseFactory {
             value(ScalarType.pvShort).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)). 
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -123,8 +123,9 @@ public class DBShortFactory extends DBBaseFactory {
         @Override
         public void atach(final PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get() * 
Short.BYTES;                
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Short.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get() * 
Short.BYTES;  
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Short.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
index 3896ff6..081db47 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
@@ -47,7 +47,7 @@ public class DBStringFactory extends DBBaseFactory {
             value(ScalarType.pvString).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).              
@@ -68,7 +68,7 @@ public class DBStringFactory extends DBBaseFactory {
             value(ScalarType.pvString).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -114,6 +114,7 @@ public class DBStringFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
             innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), 0, 
offset);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
index 3c1bb20..18e08b5 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
@@ -47,7 +47,7 @@ public class DBUByteFactory extends DBBaseFactory {
             value(ScalarType.pvUByte).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -69,7 +69,7 @@ public class DBUByteFactory extends DBBaseFactory {
             value(ScalarType.pvUByte).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)). 
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -118,8 +118,9 @@ public class DBUByteFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;            
-            offset = this.getPVStructure().getIntField("offset").get();        
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Byte.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get();     
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Byte.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
index 0385326..fa5913f 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
@@ -47,7 +47,7 @@ public class DBUIntFactory extends DBBaseFactory {
             value(ScalarType.pvUInt).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -69,7 +69,7 @@ public class DBUIntFactory extends DBBaseFactory {
             value(ScalarType.pvUInt).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -118,8 +118,9 @@ public class DBUIntFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
      
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, 
Integer.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get();    
+            getOffset( this.getPVStructure().getStringField("offset").get());
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Integer.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
index 2b37578..a5db228 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
@@ -49,7 +49,7 @@ public class DBULongFactory extends DBBaseFactory {
             value(ScalarType.pvULong).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)). 
@@ -71,7 +71,7 @@ public class DBULongFactory extends DBBaseFactory {
             value(ScalarType.pvULong).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
         
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
            
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).    
@@ -120,8 +120,9 @@ public class DBULongFactory extends DBBaseFactory {
         @Override
         public void atach(PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
      
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Long.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get(); 
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Long.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
index 6bef3c1..081d684 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
@@ -49,7 +49,7 @@ public class DBUShortFactory extends DBBaseFactory {
             value(ScalarType.pvUShort).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).  
@@ -71,7 +71,7 @@ public class DBUShortFactory extends DBBaseFactory {
             value(ScalarType.pvUShort).
             addDescriptor(). 
             add("id", fieldCreate.createScalar(ScalarType.pvString)).   
-            add("offset", fieldCreate.createScalar(ScalarType.pvInt)).         
        
+            add("offset", fieldCreate.createScalar(ScalarType.pvString)).      
           
             add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
             add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
             add("write_enable", 
fieldCreate.createScalar(ScalarType.pvBoolean)).   
@@ -120,8 +120,9 @@ public class DBUShortFactory extends DBBaseFactory {
         @Override
         public void atach(final PlcItem plcItem) {
             this.plcItem = plcItem;
-            offset = this.getPVStructure().getIntField("offset").get();        
      
-            innerBuffer = plcItem.getItemByteBuf().slice(offset, Short.BYTES);
+            //offset = this.getPVStructure().getIntField("offset").get(); 
+            getOffset( this.getPVStructure().getStringField("offset").get());  
          
+            innerBuffer = plcItem.getItemByteBuf().slice(byteOffset, 
Short.BYTES);
             innerWriteBuffer = Unpooled.copiedBuffer(innerBuffer);
         }
 
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
index 00e60cd..4719fa2 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
@@ -209,7 +209,7 @@ public class DBPersistImpl implements EventHandler{
 
                     PVRecord pvRecord = 
recordFactory.create(rs.getString("PvName"));
                     
pvRecord.getPVStructure().getStringField("id").put(rs.getString("PvId"));
-                    
pvRecord.getPVStructure().getIntField("offset").put(Integer.parseInt(rs.getString("PvOffset")));
+                    
pvRecord.getPVStructure().getStringField("offset").put(rs.getString("PvOffset"));
                     
pvRecord.getPVStructure().getStringField("descriptor").put(rs.getString("PvDescriptor"));
                    
                     
pvRecord.getPVStructure().getStringField("scan_time").put(rs.getString("pvScanTime"));
 
                     
pvRecord.getPVStructure().getBooleanField("scan_enable").put(Boolean.parseBoolean(rs.getString("PvScanEnable")));
@@ -257,7 +257,7 @@ public class DBPersistImpl implements EventHandler{
             query.setString(3, value.getScalar().getScalarType().toString());
             
             query.setString(4, ((PVString) 
pvRecord.getPVStructure().getSubField("id")).get()); 
-            query.setString(5, Integer.toString(((PVInt) 
pvRecord.getPVStructure().getSubField("offset")).get()));  
+            query.setString(5, ((PVString) 
pvRecord.getPVStructure().getSubField("offset")).get());   
             query.setString(6, ((PVString) 
pvRecord.getPVStructure().getSubField("descriptor")).get()); 
             query.setString(7, ((PVString) 
pvRecord.getPVStructure().getSubField("scan_time")).get());     
             query.setString(8, Boolean.toString(((PVBoolean) 
pvRecord.getPVStructure().getSubField("scan_enable")).get()));   
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBWriterHandlerImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBWriterHandlerImpl.java
index 4e43927..c9c6dcd 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBWriterHandlerImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBWriterHandlerImpl.java
@@ -77,7 +77,7 @@ public class DBWriterHandlerImpl implements DBWriterHandler {
                     
LOGGER.info(ByteBufUtil.prettyHexDump(dbRecord.getWriteBuffer().get()));
                     
                     if (optPlcItem.isPresent()) {
-                        
optPlcItem.get().itemWrite(dbRecord.getWriteBuffer().get(), 
dbRecord.getOffset());  
+                        
optPlcItem.get().itemWrite(dbRecord.getWriteBuffer().get(), 
dbRecord.getByteOffset(), dbRecord.getBiteOffset());  
                     }
 
                 }
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.mb/src/main/java/org/apache/plc4x/merlot/drv/mb/impl/ModbusPlcTagFunctionImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.mb/src/main/java/org/apache/plc4x/merlot/drv/mb/impl/ModbusPlcTagFunctionImpl.java
index 427825a..de85537 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.mb/src/main/java/org/apache/plc4x/merlot/drv/mb/impl/ModbusPlcTagFunctionImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.mb/src/main/java/org/apache/plc4x/merlot/drv/mb/impl/ModbusPlcTagFunctionImpl.java
@@ -52,7 +52,7 @@ public class ModbusPlcTagFunctionImpl implements 
PlcTagFunction {
     /*
     * MODBUS is a protocol oriented to data stored in bits or words, 
     * therefore the handling of individual bytes is considered a special case.
-    * Byte reading is accomplished with the offset over the read buffer, 
+    * Byte reading is accomplished with the byteOffset over the read buffer, 
     * but a byte write is rejected since the process would overwrite its 
     * partner byte.
     * The user can read individual bytes, but must mask the write in a 
@@ -60,7 +60,7 @@ public class ModbusPlcTagFunctionImpl implements 
PlcTagFunction {
     * 
     */
     @Override
-    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int offset) {
+    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int byteOffset, byte bitOffset) {
         LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),  
plcTag.getPlcValueType());
         ModbusTag mbPlcTag = null;
         Object[] objValues = null;
@@ -70,7 +70,7 @@ public class ModbusPlcTagFunctionImpl implements 
PlcTagFunction {
             switch (mbTag.getPlcValueType()) { 
                 case BOOL:   
                         objValues = new Object[byteBuf.capacity()];            
        
-                        byteOffset = mbTag.getAddress() + offset;
+                        byteOffset = mbTag.getAddress() + byteOffset;
                      
                         if (mbTag instanceof ModbusTagCoil) {
                             mbPlcTag = new ModbusTagCoil(
@@ -94,7 +94,7 @@ public class ModbusPlcTagFunctionImpl implements 
PlcTagFunction {
                             LOGGER.info("In MODBUS writing 'byte' types is 
rejected.");
                             return null;
                         }                     
-                        byteOffset = mbTag.getAddress() + offset / 2;          
          
+                        byteOffset = mbTag.getAddress() + byteOffset / 2;      
              
                         if (mbTag instanceof ModbusTagHoldingRegister) {       
                   
                             mbPlcTag = new ModbusTagHoldingRegister(
                                             byteOffset,
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
index fbde802..2bb0440 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
@@ -20,11 +20,13 @@ import io.netty.buffer.ByteBuf;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.plc4x.java.api.model.PlcTag;
 import static org.apache.plc4x.java.api.types.PlcValueType.BOOL;
+import org.apache.plc4x.java.s7.readwrite.MemoryArea;
 import static org.apache.plc4x.java.s7.readwrite.MemoryArea.DATA_BLOCKS;
 import static 
org.apache.plc4x.java.s7.readwrite.MemoryArea.DIRECT_PERIPHERAL_ACCESS;
 import static org.apache.plc4x.java.s7.readwrite.MemoryArea.FLAGS_MARKERS;
 import static org.apache.plc4x.java.s7.readwrite.MemoryArea.INPUTS;
 import static org.apache.plc4x.java.s7.readwrite.MemoryArea.OUTPUTS;
+import org.apache.plc4x.java.s7.readwrite.TransportSize;
 import org.apache.plc4x.java.s7.readwrite.tag.S7Tag;
 import org.apache.plc4x.merlot.api.PlcTagFunction;
 import org.osgi.framework.BundleContext;
@@ -39,15 +41,13 @@ public class S7PlcTagFunctionImpl implements PlcTagFunction 
{
     private static final boolean PLC4X_TAG = true;    
     private BundleContext bc; 
     
-    int byteOffset = 0;
-    byte bitOffset = 0;
-            
+          
     public S7PlcTagFunctionImpl(BundleContext bc) {
         this.bc = bc;
     }   
     
     //TODO: Remove since the S7Tag builder is public
-    private ImmutablePair<PlcTag, Object[]> getStringPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int offset) {
+    private ImmutablePair<PlcTag, Object[]> getStringPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int byteOffset, byte bitOffset) {
         LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),  
plcTag.getPlcValueType());
         short tempValue = 0;
         S7Tag s7PlcTag = null;        
@@ -58,8 +58,6 @@ public class S7PlcTagFunctionImpl implements PlcTagFunction {
             StringBuilder strTagBuilder = new StringBuilder();
             switch (s7Tag.getPlcValueType()) { 
                 case BOOL:
-                        byteOffset = s7Tag.getByteOffset() + (offset / 8);
-                        bitOffset = (byte) ((s7Tag.getBitOffset() + offset) % 
8);
                         switch (s7Tag.getMemoryArea()){
                             case DATA_BLOCKS:;
                                 strTagBuilder.append("%DB").
@@ -98,7 +96,7 @@ public class S7PlcTagFunctionImpl implements PlcTagFunction {
                         }                        
                     break;
                 case UINT:  
-                        byteOffset = s7Tag.getByteOffset() + offset * 
byteBuf.capacity();                    
+                        byteOffset = s7Tag.getByteOffset() + byteOffset * 
byteBuf.capacity();                    
                         switch (s7Tag.getMemoryArea()){
                             case DATA_BLOCKS:;
                                 strTagBuilder.append("%DB").
@@ -143,39 +141,42 @@ public class S7PlcTagFunctionImpl implements 
PlcTagFunction {
         return null;
     }
 
-    private ImmutablePair<PlcTag, Object[]> getPlc4xPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int offset) {
+    private ImmutablePair<PlcTag, Object[]> getPlc4xPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int byteOffset, byte bitOffset) {
         LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),  
plcTag.getPlcValueType());
         short tempValue = 0;
+        int intBlockNumber = 0;
+        int intByteOffset = 0;
         S7Tag s7PlcTag = null;
         if (plcTag instanceof S7Tag){
             final S7Tag s7Tag = (S7Tag) plcTag;
             LOGGER.info("Processing S7Tag: {}", s7Tag.toString()); 
             Object[] objValues = new Object[byteBuf.capacity()];
             switch (s7Tag.getPlcValueType()) { 
-                case BOOL:                    
-                        byteOffset = s7Tag.getByteOffset() + (offset / 8);
-                        bitOffset = (byte) ((s7Tag.getBitOffset() + offset) % 
8);
-                        s7PlcTag = new S7Tag(s7Tag.getDataType(),
+                case BYTE:  
+                        intBlockNumber = (s7Tag.getMemoryArea() == 
MemoryArea.DATA_BLOCKS)?
+                                            s7Tag.getBlockNumber() : 0;
+                        intByteOffset = s7Tag.getByteOffset() + byteOffset;    
                     
+                        s7PlcTag = new S7Tag(TransportSize.BOOL,
                                             s7Tag.getMemoryArea(),
-                                            s7Tag.getBlockNumber(),
-                                            byteOffset,
+                                            intBlockNumber,
+                                            intByteOffset,
                                             bitOffset,
                                             byteBuf.capacity());
+                        LOGGER.info("Write BOOL S7Tag: {}", s7Tag.toString()); 
                        
                         byteBuf.resetReaderIndex();
                         for (int i=0; i < byteBuf.capacity(); i++){
                             objValues[i] = byteBuf.readBoolean();
                         }                        
                     break;
                 case USINT:  
-                        byteOffset = s7Tag.getByteOffset() + offset;           
         
-                        System.out.println("byteOffset =  " + byteOffset);
+                        intByteOffset = s7Tag.getByteOffset() + byteOffset;    
                
                         s7PlcTag = new S7Tag(s7Tag.getDataType(),
                                             s7Tag.getMemoryArea(),
                                             s7Tag.getBlockNumber(),
-                                            byteOffset,
+                                            intByteOffset,
                                             (byte) 0,
                                             byteBuf.capacity());
-                        System.out.println("s7Tag: " + s7PlcTag.toString());
+                        LOGGER.info("Write ANY S7Tag: {}", s7Tag.toString()); 
                         byteBuf.resetReaderIndex();
                         for (int i=0; i < byteBuf.capacity(); i++){
                             tempValue = (short) (byteBuf.readByte() & 0xFF);   
                         
@@ -193,13 +194,11 @@ public class S7PlcTagFunctionImpl implements 
PlcTagFunction {
     }
  
     @Override
-    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int offset) {
+    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int byteOffset, byte bitOffset) {
         if (!PLC4X_TAG) {
-            System.out.println("Como String...");
-            return getStringPlcTag(plcTag, byteBuf, offset);
+            return getStringPlcTag(plcTag, byteBuf, byteOffset, bitOffset);
         } else {
-            System.out.println("Como PlcTag...");
-            return getPlc4xPlcTag(plcTag, byteBuf, offset);            
+            return getPlc4xPlcTag(plcTag, byteBuf, byteOffset, bitOffset);     
       
         }
     }    
     
diff --git 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
index 325e085..11a68f9 100644
--- 
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
+++ 
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
@@ -44,7 +44,7 @@ public class SimulatedPlcTagFunctionImpl implements 
PlcTagFunction {
     /*
     *
     */
-    private ImmutablePair<PlcTag, Object[]> getStringPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int offset) {
+    private ImmutablePair<PlcTag, Object[]> getStringPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int byteOffset, byte bitOffset) {
         LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),  
plcTag.getPlcValueType());
         short tempValue = 0;
         if (plcTag instanceof SimulatedTag){
@@ -88,7 +88,7 @@ public class SimulatedPlcTagFunctionImpl implements 
PlcTagFunction {
     /*
     * TODO: Change constructor of SimulatedTag to public.
     */
-    private ImmutablePair<PlcTag, Object[]> getPlc4xPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int offset) {
+    private ImmutablePair<PlcTag, Object[]> getPlc4xPlcTag(PlcTag plcTag, 
ByteBuf byteBuf, int byteOffset, byte bitOffset) {
         LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),  
plcTag.getPlcValueType());
         short tempValue = 0;
         SimulatedTag simPlcTag = null;
@@ -133,11 +133,11 @@ public class SimulatedPlcTagFunctionImpl implements 
PlcTagFunction {
     }
     
     @Override
-    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int offset) {
+    public ImmutablePair<PlcTag, Object[]> getPlcTag(PlcTag plcTag, ByteBuf 
byteBuf, int byteOffset, byte bitOffset) {
         if (!PLC4X_TAG) {
-            return getStringPlcTag(plcTag, byteBuf, offset);
+            return getStringPlcTag(plcTag, byteBuf, byteOffset, bitOffset);
         } else {
-            return getPlc4xPlcTag(plcTag, byteBuf, offset);            
+            return getPlc4xPlcTag(plcTag, byteBuf, byteOffset, bitOffset);     
       
         }
     }    
     

Reply via email to