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 2020/12/15 10:28:45 UTC

[plc4x] branch develop updated: - Adjusted the example to latest changes

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new e8832f4  - Adjusted the example to latest changes
e8832f4 is described below

commit e8832f40c5574c9e33dd9a28ec1545d5c9e64c10
Author: cdutz <ch...@c-ware.de>
AuthorDate: Tue Dec 15 11:28:36 2020 +0100

    - Adjusted the example to latest changes
---
 .../plc4x/java/examples/pollloop/PollLoop.java     | 30 +++-------------------
 1 file changed, 3 insertions(+), 27 deletions(-)

diff --git a/plc4j/examples/poll-loop/src/main/java/org/apache/plc4x/java/examples/pollloop/PollLoop.java b/plc4j/examples/poll-loop/src/main/java/org/apache/plc4x/java/examples/pollloop/PollLoop.java
index dd04cc1..7be85da 100644
--- a/plc4j/examples/poll-loop/src/main/java/org/apache/plc4x/java/examples/pollloop/PollLoop.java
+++ b/plc4j/examples/poll-loop/src/main/java/org/apache/plc4x/java/examples/pollloop/PollLoop.java
@@ -19,7 +19,6 @@
 
 package org.apache.plc4x.java.examples.pollloop;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -34,6 +33,7 @@ import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.messages.PlcReadResponse;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.api.value.PlcValue;
 
 public class PollLoop {
 
@@ -201,18 +201,15 @@ public class PollLoop {
         collector.start();
     }
 
-    public static Object[] response2Event(PlcReadResponse response, List<String> variables) {
+    public static Object[] response2Event(PlcReadResponse response, List<String> fieldNames) {
         // field names are returned in sorted order we do not want that
-//    List<String> fieldNames = new ArrayList<>(response.getFieldNames());
-        List<String> fieldNames = variables;
         Object[] event = new Object[fieldNames.size() + 1];
 
         event[0] = System.currentTimeMillis();
 
         for (int i = 0; i < fieldNames.size(); i++) {
             if (response.getResponseCode(fieldNames.get(i)) == PlcResponseCode.OK) {
-                Object value = response.getObject(fieldNames.get(i));
-                value = convertBoolean(value);
+                PlcValue value = response.getPlcValue(fieldNames.get(i));
                 event[i + 1] = value.toString();
             }
 
@@ -227,25 +224,4 @@ public class PollLoop {
         return event;
     }
 
-    /**
-     * converts an array of boolean into  a more readable "0101" String
-     */
-    public static Object convertBoolean(Object input) {
-        StringBuilder stringBuilder = new StringBuilder();
-
-        if (input instanceof ArrayList) {
-            ArrayList<Boolean> list = (ArrayList<Boolean>) input;
-
-            for (Boolean boolElem : list) {
-                String tmp2;
-                boolean tmp = Boolean.parseBoolean(boolElem.toString());
-                tmp2 = tmp ? "1" : "0";
-
-                stringBuilder.append(tmp2);
-            }
-            return stringBuilder.toString();
-        } else {
-            return input;
-        }
-    }
 }