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 2018/10/24 20:29:58 UTC

[incubator-plc4x] 02/07: - Resolving some simple Sonar findings

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

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 8b146e1836769217dcd0908f9da73a8c00256411
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Oct 24 21:27:21 2018 +0100

    - Resolving some simple Sonar findings
---
 .../java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java     | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
index a9994be..1d6d3fa 100644
--- a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
+++ b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
@@ -53,15 +53,13 @@ public class S7PlcToAzureIoTHubSample {
         String iotConnectionString = args[2];
         LOGGER.info("Connecting {}, {}, {}", plc4xConnectionString, addressString, iotConnectionString);
 
-        // Open a connection to the remote PLC.
-        try (PlcConnection plcConnection = new PlcDriverManager().getConnection(plc4xConnectionString)) {
+        // Open both a connection to the remote PLC as well as a connection to the cloud service.
+        try (PlcConnection plcConnection = new PlcDriverManager().getConnection(plc4xConnectionString);
+             DeviceClient client = new DeviceClient(iotConnectionString, IotHubClientProtocol.MQTT)) {
             LOGGER.info("Connected");
 
-            // Open a connection to the cloud service.
-            DeviceClient client = new DeviceClient(iotConnectionString, IotHubClientProtocol.MQTT);
             client.open();
 
-
             // Prepare a read request.
             PlcReadRequest request = plcConnection.readRequestBuilder().get().addItem(FIELD_NAME, addressString).build();
 
@@ -82,7 +80,6 @@ public class S7PlcToAzureIoTHubSample {
                 // Wait a second.
                 TimeUnit.SECONDS.sleep(1);
             }
-
         }
     }
 }