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 2022/08/29 12:46:56 UTC

[plc4x] branch develop updated (88c7f4a21 -> 682f3f724)

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

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


    from 88c7f4a21 chore(spi): align name of discovery item to API
     new 52526829e chore(plc4j/modbus): Updated the modbus discovery to accept a remote as a modbus device, even if it responds with an error code.
     new b7af93948 chore(plc4j/modbus): Excluded logging of modbus discovery events from the log-config
     new 682f3f724 chore(plc4j/modbus): Included Modbus in discovery

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/modbus/tcp/discovery/ModbusPlcDiscoverer.java  | 17 +++++++++++++++--
 .../discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java  |  4 ----
 .../src/main/resources/logback.xml                      |  1 +
 3 files changed, 16 insertions(+), 6 deletions(-)


[plc4x] 02/03: chore(plc4j/modbus): Excluded logging of modbus discovery events from the log-config

Posted by cd...@apache.org.
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 b7af93948cc610ad68b4ba6ebbfed3c788efa215
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 29 14:46:29 2022 +0200

    chore(plc4j/modbus): Excluded logging of modbus discovery events from the log-config
---
 .../hello-world-plc4x-discover-and-browse/src/main/resources/logback.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/resources/logback.xml b/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/resources/logback.xml
index 63f4cf41d..2641def3a 100644
--- a/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/resources/logback.xml
+++ b/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/resources/logback.xml
@@ -30,6 +30,7 @@
   <!-- Remove the messages we're not interested in -->
   <logger name="io.netty.channel" level="ERROR"/>
   <logger name="org.pcap4j" level="WARN"/>
+  <logger name="org.apache.plc4x.java.modbus.tcp.discovery" level="WARN"/>
   <logger name="org.apache.plc4x.java.transport" level="WARN"/>
   <logger name="org.apache.plc4x.java.spi" level="WARN"/>
 


[plc4x] 03/03: chore(plc4j/modbus): Included Modbus in discovery

Posted by cd...@apache.org.
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 682f3f7248c099e7af183d3f90ab28fe0e4145de
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 29 14:46:43 2022 +0200

    chore(plc4j/modbus): Included Modbus in discovery
---
 .../helloplc4x/discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java     | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/java/org/apache/plc4x/java/examples/helloplc4x/discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java b/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/java/org/apache/plc4x/java/examples/helloplc4x/discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java
index 0af740fc8..33302f38d 100644
--- a/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/java/org/apache/plc4x/java/examples/helloplc4x/discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java
+++ b/plc4j/examples/hello-world-plc4x-discover-and-browse/src/main/java/org/apache/plc4x/java/examples/helloplc4x/discoverandbrowse/HelloPlc4xDiscoverAndBrowse.java
@@ -36,10 +36,6 @@ public class HelloPlc4xDiscoverAndBrowse {
         // Iterate over all installed drivers and execute their browse functionality (If they support it)
         PlcDriverManager driverManager = new PlcDriverManager();
         for (String protocolCode : driverManager.listDrivers()) {
-            // For some reason modbus is failing on my machine ... investigate
-            if(protocolCode.startsWith("modbus")) {
-                continue;
-            }
             PlcDriver driver = driverManager.getDriver(protocolCode);
             if(driver.getMetadata().canDiscover()) {
                 logger.info("Performing discovery for {} protocol", driver.getProtocolName());


[plc4x] 01/03: chore(plc4j/modbus): Updated the modbus discovery to accept a remote as a modbus device, even if it responds with an error code.

Posted by cd...@apache.org.
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 52526829e75dfedec74062f5453492de02ae9d22
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 29 14:46:00 2022 +0200

    chore(plc4j/modbus): Updated the modbus discovery to accept a remote as a modbus device, even if it responds with an error code.
---
 .../java/modbus/tcp/discovery/ModbusPlcDiscoverer.java  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/tcp/discovery/ModbusPlcDiscoverer.java b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/tcp/discovery/ModbusPlcDiscoverer.java
index 70ca8284f..eafa99e0f 100644
--- a/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/tcp/discovery/ModbusPlcDiscoverer.java
+++ b/plc4j/drivers/modbus/src/main/java/org/apache/plc4x/java/modbus/tcp/discovery/ModbusPlcDiscoverer.java
@@ -83,7 +83,7 @@ public class ModbusPlcDiscoverer implements PlcDiscoverer {
                 logger.debug("Found {} addresses: {}", inetAddresses.size(), inetAddresses);
                 possibleAddresses.addAll(inetAddresses);
             }
-        } catch (PcapNativeException e) {
+        } catch (Throwable e) {
             logger.error("Error collecting list of possible IP addresses", e);
             future.complete(new DefaultPlcDiscoveryResponse(
                 discoveryRequest, PlcResponseCode.INTERNAL_ERROR, Collections.emptyList()));
@@ -190,7 +190,19 @@ public class ModbusPlcDiscoverer implements PlcDiscoverer {
                         try {
                             ModbusTcpADU response = (ModbusTcpADU) ModbusTcpADU.staticParse(readBuffer, DriverType.MODBUS_TCP, true);
                             PlcDiscoveryItem discoveryItem;
-                            if (!response.getPdu().getErrorFlag()) {
+                            boolean found = false;
+                            // If we got a response telling us the address is unknown, we still know there's a
+                            // Modbus device at the other side. In general ... as soon as we get a valid Modbus
+                            // response, we should accept that we're talking to a Modbus device
+                            if (response.getPdu().getErrorFlag()) {
+                                ModbusPDUError errorPdu = (ModbusPDUError) response.getPdu();
+                                if (errorPdu.getExceptionCode() == ModbusErrorCode.ILLEGAL_DATA_ADDRESS) {
+                                    found = true;
+                                }
+                            } else {
+                                found = true;
+                            }
+                            if (found) {
                                 discoveryItem = new DefaultPlcDiscoveryItem(
                                     "modbus-tcp", "tcp", possibleAddress.getHostAddress(), Collections.singletonMap("unit-identifier", Integer.toString(unitIdentifier)), "unknown", Collections.emptyMap());
                                 discoveryItems.add(discoveryItem);
@@ -201,6 +213,7 @@ public class ModbusPlcDiscoverer implements PlcDiscoverer {
                                 }
                                 break;
                             }
+
                         } catch (ParseException e) {
                             // Ignore.
                         }