Skip to content

Commit

Permalink
feat: Made the S7 driver output a better warning, if there are issues…
Browse files Browse the repository at this point in the history
… loading libpcap
  • Loading branch information
chrisdutz committed Jan 28, 2025
1 parent 3ea9bc2 commit 6543af4
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
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;
Expand All @@ -45,6 +47,7 @@
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() {
Expand Down Expand Up @@ -106,6 +109,12 @@ public PlcDiscoveryRequest.Builder discoveryRequestBuilder() {
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.");
}
}
}

Expand Down

0 comments on commit 6543af4

Please sign in to comment.