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/02/19 14:01:38 UTC

[incubator-plc4x] branch master updated: Added a prototype for a batch supplier to the Edgent integration (Currently consuming batch values will not be implemented)

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


The following commit(s) were added to refs/heads/master by this push:
     new faa06e1  Added a prototype for a batch supplier to the Edgent integration (Currently consuming batch values will not be implemented)
faa06e1 is described below

commit faa06e1a3838a8ff3244928b887fbdb690d1a72c
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Feb 19 15:01:34 2018 +0100

    Added a prototype for a batch supplier to the Edgent integration (Currently consuming batch values will not be implemented)
---
 .../apache/plc4x/edgent/PlcConnectionAdapter.java  | 22 ++++++++++++++++++++++
 .../java/org/apache/plc4x/edgent/PlcFunctions.java |  5 +++++
 2 files changed, 27 insertions(+)

diff --git a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
index ca6955d..4403aba 100644
--- a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
+++ b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
@@ -28,6 +28,8 @@ import org.apache.plc4x.java.api.connection.PlcConnection;
 import org.apache.plc4x.java.api.connection.PlcReader;
 import org.apache.plc4x.java.api.connection.PlcWriter;
 import org.apache.plc4x.java.api.exceptions.PlcException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
 import org.apache.plc4x.java.api.messages.PlcWriteRequest;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteRequest;
@@ -129,6 +131,26 @@ public class PlcConnectionAdapter implements AutoCloseable {
         };
     }
 
+    Supplier<PlcReadResponse> newSupplier(PlcReadRequest readRequest) {
+        return new Supplier<PlcReadResponse>() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public PlcReadResponse get() {
+                PlcConnection connection = null;
+                try {
+                    connection = getConnection();
+                    PlcReader reader = connection.getReader()
+                        .orElseThrow(() -> new NullPointerException("No reader available"));
+                    return reader.read(readRequest).get();
+                } catch (Exception e) {
+                    logger.error("reading from plc device {} {} failed", connection, readRequest, e);
+                    return null;
+                }
+            }
+        };
+    }
+
     <T> Consumer<T> newConsumer(Class<T> datatype, String addressStr) {
         PlcConnectionAdapter.checkDatatype(datatype);
         return new Consumer<T>() {
diff --git a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcFunctions.java b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcFunctions.java
index d44c7a8..43fe00d 100644
--- a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcFunctions.java
+++ b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcFunctions.java
@@ -25,6 +25,8 @@ import org.apache.edgent.function.Function;
 import org.apache.edgent.function.Supplier;
 
 import com.google.gson.JsonObject;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
 
 /**
  * WIP - A plc4x Apache Edgent {@link Supplier} and {@link Consumer} connector factory.
@@ -110,6 +112,9 @@ public class PlcFunctions {
   public static Supplier<Calendar> calendarSupplier(PlcConnectionAdapter adapter, String addressStr) {
     return adapter.newSupplier(Calendar.class, addressStr);
   }
+  public static Supplier<PlcReadResponse> batchSupplier(PlcConnectionAdapter adapter, PlcReadRequest readRequest) {
+    return adapter.newSupplier(readRequest);
+  }
 
   /**
    * Create a new Edgent {@link Consumer} to write data to the 

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.