use of org.apache.plc4x.java.canopen.api.conversation.canopen.SDOUploadConversation in project plc4x by apache.
the class CANOpenProtocolLogic method readInternally.
private void readInternally(PlcReadRequest readRequest, CANOpenSDOField field, CompletableFuture<PlcReadResponse> response) {
String fieldName = readRequest.getFieldNames().iterator().next();
final RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
CompletableFuture<PlcValue> callback = new CompletableFuture<>();
callback.whenComplete((value, error) -> {
if (error != null) {
Map<String, ResponseItem<PlcValue>> fields = new HashMap<>();
if (error instanceof CANOpenAbortException) {
fields.put(fieldName, new ResponseItem<>(PlcResponseCode.REMOTE_ERROR, new PlcLINT(((CANOpenAbortException) error).getAbortCode())));
} else {
fields.put(fieldName, new ResponseItem<>(PlcResponseCode.REMOTE_ERROR, null));
}
response.complete(new DefaultPlcReadResponse(readRequest, fields));
transaction.endRequest();
return;
}
Map<String, ResponseItem<PlcValue>> fields = new HashMap<>();
fields.put(fieldName, new ResponseItem<>(PlcResponseCode.OK, value));
response.complete(new DefaultPlcReadResponse(readRequest, fields));
transaction.endRequest();
});
SDOUploadConversation upload = new SDOUploadConversation(conversation, field.getNodeId(), field.getAnswerNodeId(), new IndexAddress(field.getIndex(), field.getSubIndex()), field.getCanOpenDataType());
transaction.submit(() -> upload.execute(callback));
}
Aggregations