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 2025/01/28 13:38:33 UTC

(plc4x) 02/02: feat: Made the S7 driver output a better warning, if there are issues loading libpcap

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 6543af45ccf3a2fe2ad031ff037f57501961033b
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jan 28 14:38:07 2025 +0100

    feat: Made the S7 driver output a better warning, if there are issues loading libpcap
---
 .../main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java   | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java
index f814cd3a49..e623e09ca2 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/S7Driver.java
@@ -35,6 +35,8 @@ import org.apache.plc4x.java.spi.messages.DefaultPlcDiscoveryRequest;
 import org.apache.plc4x.java.spi.optimizer.BaseOptimizer;
 import org.pcap4j.core.PcapNativeException;
 import org.pcap4j.core.Pcaps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.Collections;
 import java.util.List;
@@ -45,6 +47,7 @@ import java.util.function.ToIntFunction;
 public class S7Driver extends S7HGeneratedDriverBase {
 
     public static final int ISO_ON_TCP_PORT = 102;
+    private static final Logger log = LoggerFactory.getLogger(S7Driver.class);
 
     @Override
     public String getProtocolCode() {
@@ -106,6 +109,12 @@ public class S7Driver extends S7HGeneratedDriverBase {
             return new DefaultPlcDiscoveryRequest.Builder(discoverer);
         } catch (PcapNativeException e) {
             throw new RuntimeException(e);
+        } catch (NoClassDefFoundError e) {
+            // This is usually due to some setup problems on the system ...
+            // we can possibly output a better error message here, that helps the user fix the issue himself.
+            if("Could not initialize class com.sun.jna.Native".equals(e.getMessage()) && e.getCause() instanceof UnsatisfiedLinkError) {
+                log.error("Could not discover devices as there were issues loading the pcap wrapper. Please make sure you have set the \"-Djna.library.path\" VM option correctly.");
+            }
         }
     }