use of org.apache.plc4x.java.canopen.api.conversation.canopen.SDODownloadConversation in project plc4x by apache.
the class CANOpenProtocolLogic method writeInternally.
private void writeInternally(DefaultPlcWriteRequest writeRequest, CANOpenSDOField field, CompletableFuture<PlcWriteResponse> response) {
final RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
String fieldName = writeRequest.getFieldNames().iterator().next();
CompletableFuture<PlcResponseCode> callback = new CompletableFuture<>();
callback.whenComplete((code, error) -> {
if (error != null) {
if (error instanceof CANOpenAbortException) {
response.complete(new DefaultPlcWriteResponse(writeRequest, Collections.singletonMap(fieldName, PlcResponseCode.REMOTE_ERROR)));
} else {
response.complete(new DefaultPlcWriteResponse(writeRequest, Collections.singletonMap(fieldName, PlcResponseCode.INTERNAL_ERROR)));
}
transaction.endRequest();
return;
}
response.complete(new DefaultPlcWriteResponse(writeRequest, Collections.singletonMap(fieldName, code)));
transaction.endRequest();
});
PlcValue writeValue = writeRequest.getPlcValues().get(0);
SDODownloadConversation download = new SDODownloadConversation(conversation, field.getNodeId(), field.getAnswerNodeId(), new IndexAddress(field.getIndex(), field.getSubIndex()), writeValue, field.getCanOpenDataType());
transaction.submit(() -> download.execute(callback));
}
Aggregations