Skip to content

Commit

Permalink
refactor: Updated the discovery example to not list every device for …
Browse files Browse the repository at this point in the history
…every local device that could reach it.
  • Loading branch information
chrisdutz committed Dec 4, 2023
1 parent 7a219c4 commit 08dcb72
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -23,12 +23,22 @@
import org.apache.plc4x.java.api.messages.PlcDiscoveryItem;
import org.apache.plc4x.java.api.messages.PlcDiscoveryResponse;

import java.util.Map;
import java.util.TreeMap;

public class ManualProfinetIoDiscoveryTest {

public static void main(String[] args) throws Exception {
final PlcDriver profinetDriver = new DefaultPlcDriverManager().getDriver("profinet");
final PlcDiscoveryResponse plcDiscoveryResponse = profinetDriver.discoveryRequestBuilder().build().execute().get();
// As we can reach some devices from multiple network devices, aggregate them by connection url
Map<String, PlcDiscoveryItem> items = new TreeMap<>();
for (PlcDiscoveryItem responseValue : plcDiscoveryResponse.getValues()) {
items.put(responseValue.getConnectionUrl(), responseValue);
}
// Output the aggregated values.
for (Map.Entry<String, PlcDiscoveryItem> stringPlcDiscoveryItemEntry : items.entrySet()) {
PlcDiscoveryItem responseValue = stringPlcDiscoveryItemEntry.getValue();
System.out.println(responseValue.getName() + ": " + responseValue.getConnectionUrl());
}
}
Expand Down

0 comments on commit 08dcb72

Please sign in to comment.