You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sk...@apache.org on 2018/10/26 14:26:33 UTC
[incubator-plc4x] branch feature/refactor-abstract-connection
updated: fixed hello plc4x example
This is an automated email from the ASF dual-hosted git repository.
skorikov pushed a commit to branch feature/refactor-abstract-connection
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/feature/refactor-abstract-connection by this push:
new 9ed446b fixed hello plc4x example
9ed446b is described below
commit 9ed446be18867690df87372af83f1411814850c7
Author: Andrey Skorikov <an...@codecentric.de>
AuthorDate: Fri Oct 26 16:26:30 2018 +0200
fixed hello plc4x example
---
.../org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java b/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java
index 20253e4..1204bd3 100644
--- a/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java
+++ b/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java
@@ -55,14 +55,14 @@ public static void main(String[] args) throws Exception {
for (int i = 1; i < args.length; i++) {
builder.addItem("value-" + i, args[i]);
}
- PlcReadRequest readRequest = builder.build();
//////////////////////////////////////////////////////////
// Read synchronously ...
// NOTICE: the ".get()" immediately lets this thread pause until
// the response is processed and available.
System.out.println("Synchronous request ...");
- PlcReadResponse syncResponse = readRequest.execute().get();
+ PlcReadRequest syncReadRequest = builder.build();
+ PlcReadResponse syncResponse = syncReadRequest.execute().get();
// Simply iterating over the field names returned in the response.
printResponse(syncResponse);
@@ -70,15 +70,17 @@ public static void main(String[] args) throws Exception {
// Read asynchronously ...
// Register a callback executed as soon as a response arrives.
System.out.println("Asynchronous request ...");
- CompletableFuture<? extends PlcReadResponse> asyncResponse = readRequest.execute();
+ PlcReadRequest asyncReadRequest = builder.build();
+ CompletableFuture<? extends PlcReadResponse> asyncResponse = asyncReadRequest.execute();
asyncResponse.whenComplete((readResponse, throwable) -> {
if (readResponse != null) {
- printResponse(syncResponse);
+ printResponse(readResponse);
} else {
System.err.println("An error occurred: " + throwable.getMessage());
throwable.printStackTrace();
}
});
+
}
}