hutcheb commented on a change in pull request #172:
URL: https://github.com/apache/plc4x/pull/172#discussion_r456313688



##########
File path: 
plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusField.java
##########
@@ -28,33 +28,33 @@ Licensed to the Apache Software Foundation (ASF) under one
 public abstract class ModbusField implements PlcField {
 
     public static final Pattern ADDRESS_PATTERN = 
Pattern.compile("(?<address>\\d+)(\\[(?<quantity>\\d+)])?");
+    protected static final int protocolAddressOffset = 1;
 
     private final int address;
 
     private final int quantity;
 
     public static ModbusField of(String addressString) throws 
PlcInvalidFieldException {
-        Matcher matcher = 
ModbusFieldCoil.ADDRESS_PATTERN.matcher(addressString);
-        if(matcher.matches()) {
+        if(ModbusFieldCoil.matches(addressString)) {
             return ModbusFieldCoil.of(addressString);
         }
-        matcher = 
ModbusFieldDiscreteInput.ADDRESS_PATTERN.matcher(addressString);
-        if(matcher.matches()) {
+        if(ModbusFieldDiscreteInput.matches(addressString)) {
             return ModbusFieldDiscreteInput.of(addressString);
         }
-        matcher = 
ModbusFieldHoldingRegister.ADDRESS_PATTERN.matcher(addressString);
-        if(matcher.matches()) {
+        if(ModbusFieldHoldingRegister.matches(addressString)) {
             return ModbusFieldHoldingRegister.of(addressString);
         }
-        matcher = 
ModbusFieldInputRegister.ADDRESS_PATTERN.matcher(addressString);
-        if(matcher.matches()) {
+        if(ModbusFieldInputRegister.matches(addressString)) {
             return ModbusFieldInputRegister.of(addressString);
         }
         throw new PlcInvalidFieldException("Unable to parse address: " + 
addressString);
     }
 
     protected ModbusField(int address, Integer quantity) {
         this.address = address;
+        if ((this.address + protocolAddressOffset) <= 0) {

Review comment:
       this.address stores the address sent over the wire starting at 0 instead 
of address 1. I didn't want to have a check that checks if the value is < 0 and 
have the exception say you can't have an address < 1 as it might be confusing.
   
   In the constructor for each memory area I subtract 1 from the address before 
storing it in this.address.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to