chrisdutz commented on a change in pull request #172:
URL: https://github.com/apache/plc4x/pull/172#discussion_r456315294
##########
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:
Aaaahh yeah ... now I got you ... and yes ... indeed "address" would be
the decremented value ... so yeah ... just ignore my comment ;-)
----------------------------------------------------------------
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:
[email protected]