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/09/26 15:52:47 UTC
[plc4x] 09/10: - Made the driver catch exceptions and report them
better.
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
commit cb80703f09a918637817903b114941c9096718a7
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Sep 26 17:44:35 2020 +0200
- Made the driver catch exceptions and report them better.
---
.../plc4x/java/ads/protocol/AdsProtocolLogic.java | 31 +++++++++++++---------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
index e324f9e..69a00ec 100644
--- a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
+++ b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
@@ -316,7 +316,7 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
}).toArray(PlcValue[]::new);
return new ResponseItem<>(PlcResponseCode.OK, PlcValues.of(resultItems));
}
- } catch (ParseException e) {
+ } catch (Exception e) {
LOGGER.warn(String.format("Error parsing field item of type: '%s'", field.getAdsDataType()), e);
return new ResponseItem<>(PlcResponseCode.INTERNAL_ERROR, null);
}
@@ -601,18 +601,23 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
.check(adsDataResponse -> adsDataResponse instanceof AdsReadWriteResponse)
.unwrap(adsDataResponse -> (AdsReadWriteResponse) adsDataResponse)
.handle(responseAdsData -> {
- ReadBuffer readBuffer = new ReadBuffer(responseAdsData.getData(), true);
- try {
- // Read the handle.
- long handle = readBuffer.readUnsignedLong(32);
-
- DirectAdsField directAdsField = new DirectAdsField(
- ReservedIndexGroups.ADSIGRP_SYM_VALBYHND.getValue(), handle,
- symbolicAdsField.getAdsDataType(), symbolicAdsField.getNumberOfElements());
- symbolicFieldMapping.put(symbolicAdsField, directAdsField);
- future.complete(null);
- } catch (ParseException e) {
- future.completeExceptionally(e);
+ if(responseAdsData.getResult() != ReturnCode.OK) {
+ future.completeExceptionally(new PlcException("Couldn't retrieve handle for symbolic field " +
+ symbolicAdsField.getSymbolicField() + " got return code " + responseAdsData.getResult().name()));
+ } else {
+ ReadBuffer readBuffer = new ReadBuffer(responseAdsData.getData(), true);
+ try {
+ // Read the handle.
+ long handle = readBuffer.readUnsignedLong(32);
+
+ DirectAdsField directAdsField = new DirectAdsField(
+ ReservedIndexGroups.ADSIGRP_SYM_VALBYHND.getValue(), handle,
+ symbolicAdsField.getAdsDataType(), symbolicAdsField.getNumberOfElements());
+ symbolicFieldMapping.put(symbolicAdsField, directAdsField);
+ future.complete(null);
+ } catch (ParseException e) {
+ future.completeExceptionally(e);
+ }
}
transaction.endRequest();
}));