You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/06/28 12:59:41 UTC

[incubator-plc4x] branch feature/mobbus-support-with-lib updated: modbus test display byte[]

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

sruehl pushed a commit to branch feature/mobbus-support-with-lib
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/feature/mobbus-support-with-lib by this push:
     new 7920c4f  modbus test display byte[]
7920c4f is described below

commit 7920c4f421fc707c02b1252c18a945352aba1882
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 28 14:59:38 2018 +0200

    modbus test display byte[]
---
 .../apache/plc4x/java/modbus/ManualPlc4XModbusTest.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java b/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
index e320b1f..11b0586 100644
--- a/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
+++ b/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.modbus;
 
+import org.apache.commons.io.HexDump;
 import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.connection.PlcConnection;
 import org.apache.plc4x.java.api.connection.PlcReader;
@@ -26,6 +27,7 @@ import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse;
 import org.apache.plc4x.java.api.model.Address;
 
+import java.io.ByteArrayOutputStream;
 import java.util.concurrent.CompletableFuture;
 
 public class ManualPlc4XModbusTest {
@@ -45,13 +47,15 @@ public class ManualPlc4XModbusTest {
             PlcReader reader = plcConnection.getReader().orElseThrow(() -> new RuntimeException("No Reader found"));
 
             Address address = plcConnection.parseAddress("readcoils:1/0");
-            CompletableFuture<TypeSafePlcReadResponse<Integer>> response = reader
-                .read(new TypeSafePlcReadRequest<>(Integer.class, address));
-            TypeSafePlcReadResponse<Integer> readResponse = response.get();
+            CompletableFuture<TypeSafePlcReadResponse<byte[]>> response = reader
+                .read(new TypeSafePlcReadRequest<>(byte[].class, address));
+            TypeSafePlcReadResponse<byte[]> readResponse = response.get();
             System.out.println("Response " + readResponse);
-            ReadResponseItem<Integer> responseItem = readResponse.getResponseItem().orElseThrow(() -> new RuntimeException("No Item found"));
+            ReadResponseItem<byte[]> responseItem = readResponse.getResponseItem().orElseThrow(() -> new RuntimeException("No Item found"));
             System.out.println("ResponseItem " + responseItem);
-            responseItem.getValues().stream().map(integer -> "Value: " + integer).forEach(System.out::println);
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            HexDump.dump(responseItem.getValues().get(0), 0, byteArrayOutputStream, 0);
+            responseItem.getValues().stream().map(integer -> "Value: " + byteArrayOutputStream).forEach(System.out::println);
         }
         System.exit(0);
     }