You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/03/06 08:51:52 UTC
[plc4x] 01/02: - Removed field types which are not explicitly
specified in the modbus spec - Decreased the timeout back to one second
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
commit a3b28b7fa3abd601959864ba47db948ef7757fa2
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Mar 6 09:51:21 2020 +0100
- Removed field types which are not explicitly specified in the modbus spec
- Decreased the timeout back to one second
---
.../java/modbus/config/ModbusConfiguration.java | 2 +-
.../java/modbus/field/ModbusFieldHandler.java | 6 +-
.../modbus/field/ModbusFieldMaskWriteRegister.java | 98 ----------------------
.../java/modbus/field/ModbusFieldRegister.java | 47 -----------
4 files changed, 2 insertions(+), 151 deletions(-)
diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/config/ModbusConfiguration.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/config/ModbusConfiguration.java
index 1cf97df..8d9146a 100644
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/config/ModbusConfiguration.java
+++ b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/config/ModbusConfiguration.java
@@ -27,7 +27,7 @@ import org.apache.plc4x.java.transport.tcp.TcpTransportConfiguration;
public class ModbusConfiguration implements Configuration, TcpTransportConfiguration {
@ConfigurationParameter("request-timeout")
- @IntDefaultValue(10_000)
+ @IntDefaultValue(1_000)
private int requestTimeout;
@ConfigurationParameter("unit-identifier")
diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldHandler.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldHandler.java
index b904743..22fe420 100644
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldHandler.java
+++ b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldHandler.java
@@ -32,9 +32,7 @@ public class ModbusFieldHandler extends DefaultPlcFieldHandler {
@Override
public PlcField createField(String fieldQuery) throws PlcInvalidFieldException {
- if (ModbusFieldMaskWriteRegister.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
- return ModbusFieldMaskWriteRegister.of(fieldQuery);
- } else if (ModbusFieldDiscreteInput.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
+ if (ModbusFieldDiscreteInput.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
return ModbusFieldDiscreteInput.of(fieldQuery);
} else if (ModbusFieldHoldingRegister.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
return ModbusFieldHoldingRegister.of(fieldQuery);
@@ -42,8 +40,6 @@ public class ModbusFieldHandler extends DefaultPlcFieldHandler {
return ModbusFieldInputRegister.of(fieldQuery);
} else if (ModbusFieldCoil.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
return ModbusFieldCoil.of(fieldQuery);
- } else if (ModbusFieldRegister.ADDRESS_PATTERN.matcher(fieldQuery).matches()) {
- return ModbusFieldRegister.of(fieldQuery);
}
throw new PlcInvalidFieldException(fieldQuery);
}
diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldMaskWriteRegister.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldMaskWriteRegister.java
deleted file mode 100644
index 7c3d513..0000000
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldMaskWriteRegister.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-package org.apache.plc4x.java.modbus.field;
-
-import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
-
-import java.util.Objects;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * This is not really an address, but a different type of operation.
- * Perhaps in the future we will use this in order to send optimized requests,
- * but for now it shouldn't be used and is just implemented for the sake of
- * completeness.
- */
-@Deprecated
-public class ModbusFieldMaskWriteRegister extends ModbusField {
-
- public static final Pattern ADDRESS_PATTERN = Pattern.compile("mask-write:" + ModbusField.ADDRESS_PATTERN + "/" + "(?<andMask>\\d+)/(?<orMask>\\d+)");
-
- private final int andMask;
- private final int orMask;
-
- protected ModbusFieldMaskWriteRegister(int address, int andMask, int orMask, Integer quantity) {
- super(address, quantity);
- this.andMask = andMask;
- this.orMask = orMask;
- }
-
- public static ModbusFieldMaskWriteRegister of(String addressString) throws PlcInvalidFieldException {
- Matcher matcher = ADDRESS_PATTERN.matcher(addressString);
- if (!matcher.matches()) {
- throw new PlcInvalidFieldException(addressString, ADDRESS_PATTERN);
- }
- int address = Integer.parseInt(matcher.group("address"));
- int andMask = Integer.parseInt(matcher.group("andMask"));
- int orMask = Integer.parseInt(matcher.group("orMask"));
-
- String quantityString = matcher.group("quantity");
- Integer quantity = quantityString != null ? Integer.valueOf(quantityString) : null;
- return new ModbusFieldMaskWriteRegister(address, andMask, orMask, quantity);
- }
-
- public int getAndMask() {
- return andMask;
- }
-
- public int getOrMask() {
- return orMask;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof ModbusFieldMaskWriteRegister)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- ModbusFieldMaskWriteRegister that = (ModbusFieldMaskWriteRegister) o;
- return andMask == that.andMask &&
- orMask == that.orMask;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), andMask, orMask);
- }
-
- @Override
- public String toString() {
- return "MaskWriteRegisterModbusField{" +
- "andMask=" + andMask +
- ", orMask=" + orMask +
- "} " + super.toString();
- }
-
-}
diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldRegister.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldRegister.java
deleted file mode 100644
index 10da1ee..0000000
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/field/ModbusFieldRegister.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-package org.apache.plc4x.java.modbus.field;
-
-import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-// TODO: Default to {@link ReadHoldingRegistersModbusField}
-public class ModbusFieldRegister extends ModbusField {
-
- public static final Pattern ADDRESS_PATTERN = Pattern.compile("register:" + ModbusField.ADDRESS_PATTERN);
-
- protected ModbusFieldRegister(int address, Integer quantity) {
- super(address, quantity);
- }
-
- public static ModbusFieldRegister of(String addressString) throws PlcInvalidFieldException {
- Matcher matcher = ADDRESS_PATTERN.matcher(addressString);
- if (!matcher.matches()) {
- throw new PlcInvalidFieldException(addressString, ADDRESS_PATTERN);
- }
- int address = Integer.parseInt(matcher.group("address"));
-
- String quantityString = matcher.group("quantity");
- Integer quantity = quantityString != null ? Integer.valueOf(quantityString) : null;
- return new ModbusFieldRegister(address, quantity);
- }
-
-}