You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/11/18 21:57:03 UTC

[incubator-streampipes-extensions] branch dev updated: Update PLC4X S7 adapter

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

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git


The following commit(s) were added to refs/heads/dev by this push:
     new 14388c1  Update PLC4X S7 adapter
14388c1 is described below

commit 14388c168671109baa41654be8a0742b1488354e
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Nov 18 22:56:30 2020 +0100

    Update PLC4X S7 adapter
---
 .../connect/adapters/plc4x/s7/Plc4xS7Adapter.java  | 60 +++++++++++-----------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/plc4x/s7/Plc4xS7Adapter.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/plc4x/s7/Plc4xS7Adapter.java
index 9c1cd75..078b65c 100644
--- a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/plc4x/s7/Plc4xS7Adapter.java
+++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/plc4x/s7/Plc4xS7Adapter.java
@@ -213,43 +213,43 @@ public class Plc4xS7Adapter extends PullAdapter {
     protected void pullData() {
 
         // Create PLC read request
-
-        PlcConnection plcConnection = null;
-        try {
-            plcConnection = this.driverManager.getConnection("s7://" + this.ip);
-        } catch (PlcConnectionException e) {
-            this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
-        }
-
-        PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
-        for (Map<String, String> node : this.nodes) {
-            builder.addItem(node.get(PLC_NODE_NAME), node.get(PLC_NODE_NAME) + ":" + node.get(PLC_NODE_TYPE).toUpperCase());
-        }
-        PlcReadRequest readRequest = builder.build();
-
-        // Execute the request
-        PlcReadResponse response = null;
         try {
-            response = readRequest.execute().get();
+            PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip);
 
-            // Create an event containing the value of the PLC
-            Map<String, Object> event = new HashMap<>();
+            PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
             for (Map<String, String> node : this.nodes) {
-                if(response.getResponseCode(node.get(PLC_NODE_NAME)) == PlcResponseCode.OK) {
-                    event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getObject(node.get(PLC_NODE_NAME)));
-                }
+                builder.addItem(node.get(PLC_NODE_NAME), node.get(PLC_NODE_NAME) + ":" + node.get(PLC_NODE_TYPE).toUpperCase());
+            }
+            PlcReadRequest readRequest = builder.build();
 
-                else {
-                    logger.error("Error[" + node.get(PLC_NODE_NAME) + "]: " +
-                            response.getResponseCode(node.get(PLC_NODE_NAME)).name());
+            // Execute the request
+            PlcReadResponse response = null;
+            try {
+                response = readRequest.execute().get();
+
+                // Create an event containing the value of the PLC
+                Map<String, Object> event = new HashMap<>();
+                for (Map<String, String> node : this.nodes) {
+                    if(response.getResponseCode(node.get(PLC_NODE_NAME)) == PlcResponseCode.OK) {
+                        event.put(node.get(PLC_NODE_RUNTIME_NAME), response.getObject(node.get(PLC_NODE_NAME)));
+                    }
+
+                    else {
+                        logger.error("Error[" + node.get(PLC_NODE_NAME) + "]: " +
+                                response.getResponseCode(node.get(PLC_NODE_NAME)).name());
+                    }
                 }
-            }
 
-            // publish the final event
-            adapterPipeline.process(event);
-        } catch (InterruptedException | ExecutionException e) {
-            LOG.error(e.getMessage());
+                // publish the final event
+                adapterPipeline.process(event);
+            } catch (InterruptedException | ExecutionException e) {
+                LOG.error(e.getMessage());
+            }
+        } catch (PlcConnectionException e) {
+            this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
         }
+
+
     }
 
     /**