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/04/09 08:42:50 UTC
[incubator-plc4x] 02/04: Updated the example to no longer produce
warnings in IntelliJ
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
commit 195b86c5b735b8c23f0aa8590b5fe26d5bc3c3bd
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Apr 9 10:40:44 2018 +0200
Updated the example to no longer produce warnings in IntelliJ
---
.../apache/plc4x/java/s7/S7PlcReaderSample.java | 87 +++++++++++-----------
1 file changed, 43 insertions(+), 44 deletions(-)
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
index 91e119a..660d6af 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
@@ -38,52 +38,51 @@ public class S7PlcReaderSample {
* Example code do demonstrate using the S7 Plc Driver.
*
* @param args ignored.
- * @throws Exception something went wrong.
*/
@SuppressWarnings("unchecked")
-public static void main(String[] args) throws Exception {
- try (PlcConnection plcConnection =
- new PlcDriverManager().getConnection(args[0])) {
-
- Optional<PlcReader> reader = plcConnection.getReader();
-
- // Check if this connection support reading of data.
- if (reader.isPresent()) {
- PlcReader plcReader = reader.get();
-
- // Parse an address string.
- Address inputs = plcConnection.parseAddress(args[1]);
-
- //////////////////////////////////////////////////////////
- // Read synchronously ...
- // NOTICE: the ".get()" immediately lets this thread pause till
- // the response is processed and available.
- TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(
- new TypeSafePlcReadRequest<>(Byte.class, inputs)).get();
-
- System.out.println("Inputs: " + plcReadResponse.getResponseItem()
- .orElseThrow(() -> new IllegalStateException("No response available"))
- .getValues().get(0));
-
- //////////////////////////////////////////////////////////
- // Read asynchronously ...
- CompletableFuture<TypeSafePlcReadResponse<Byte>> asyncResponse = plcReader.read(
- new TypeSafePlcReadRequest(Byte.class, inputs));
-
- asyncResponse.thenAccept(bytePlcReadResponse -> {
- Byte dataAsync = bytePlcReadResponse.getResponseItem()
- .orElseThrow(() -> new IllegalStateException("No response available"))
- .getValues().get(0);
- System.out.println("Inputs: " + dataAsync);
- });
-
- // do something else ...
+ public static void main(String[] args) {
+ try (PlcConnection plcConnection =
+ new PlcDriverManager().getConnection(args[0])) {
+
+ Optional<PlcReader> reader = plcConnection.getReader();
+
+ // Check if this connection support reading of data.
+ if (reader.isPresent()) {
+ PlcReader plcReader = reader.get();
+
+ // Parse an address string.
+ Address inputs = plcConnection.parseAddress(args[1]);
+
+ //////////////////////////////////////////////////////////
+ // Read synchronously ...
+ // NOTICE: the ".get()" immediately lets this thread pause till
+ // the response is processed and available.
+ TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(
+ new TypeSafePlcReadRequest<>(Byte.class, inputs)).get();
+
+ System.out.println("Inputs: " + plcReadResponse.getResponseItem()
+ .orElseThrow(() -> new IllegalStateException("No response available"))
+ .getValues().get(0));
+
+ //////////////////////////////////////////////////////////
+ // Read asynchronously ...
+ CompletableFuture<TypeSafePlcReadResponse<Byte>> asyncResponse = plcReader.read(
+ new TypeSafePlcReadRequest(Byte.class, inputs));
+
+ asyncResponse.thenAccept(bytePlcReadResponse -> {
+ Byte dataAsync = bytePlcReadResponse.getResponseItem()
+ .orElseThrow(() -> new IllegalStateException("No response available"))
+ .getValues().get(0);
+ System.out.println("Inputs: " + dataAsync);
+ });
+
+ // do something else ...
+ }
+ }
+ // Catch any exception or the application won't be able to finish if something goes wrong.
+ catch (Exception e) {
+ logger.error("S7 PLC reader sample", e);
+ }
}
- }
- // Catch any exception or the application won't be able to finish if something goes wrong.
- catch (Exception e) {
- logger.error("S7 PLC reader sample", e);
- }
-}
}
--
To stop receiving notification emails like this one, please contact
cdutz@apache.org.