use of org.eclipse.milo.opcua.stack.core.types.structured.WriteValue in project milo by eclipse.
the class DefaultAttributeServiceSet method onWrite.
@Override
public void onWrite(ServiceRequest service) {
WriteRequest request = (WriteRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<WriteValue> nodesToWrite = l(request.getNodesToWrite());
if (nodesToWrite.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToWrite.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DiagnosticsContext<WriteValue> diagnosticsContext = new DiagnosticsContext<>();
WriteContext context = new WriteContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().write(context, nodesToWrite);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToWrite);
WriteResponse response = new WriteResponse(header, values.toArray(new StatusCode[0]), diagnosticInfos);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.WriteValue in project milo by eclipse.
the class ManagedAddressSpace method write.
@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
for (WriteValue writeValue : writeValues) {
UaServerNode node = nodeManager.get(writeValue.getNodeId());
if (node != null) {
try {
node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(), writeValue.getValue(), writeValue.getIndexRange());
results.add(StatusCode.GOOD);
logger.debug("Wrote value {} to {} attribute of {}", writeValue.getValue().getValue(), AttributeId.from(writeValue.getAttributeId()).map(Object::toString).orElse("unknown"), node.getNodeId());
} catch (UaException e) {
logger.error("Unable to write value={}", writeValue.getValue(), e);
results.add(e.getStatusCode());
}
} else {
results.add(new StatusCode(StatusCodes.Bad_NodeIdUnknown));
}
}
context.success(results);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.WriteValue in project milo by eclipse.
the class AttributeServices method writeValues.
/**
* This service is used to write to the value attribute of one or more nodes.
*
* @param nodeIds the {@link NodeId}s identifying the nodes to write to.
* @param values the {@link DataValue}s to write.
* @return a {@link CompletableFuture} containing a list of results for the writes.
*/
default CompletableFuture<List<StatusCode>> writeValues(List<NodeId> nodeIds, List<DataValue> values) {
if (nodeIds.size() != values.size()) {
CompletableFuture<List<StatusCode>> failed = new CompletableFuture<>();
failed.completeExceptionally(new IllegalArgumentException("nodeIds.size() != values.size()"));
return failed;
} else {
Stream<WriteValue> stream = Streams.zip(nodeIds.stream(), values.stream(), (nodeId, value) -> new WriteValue(nodeId, uint(13), null, value));
return write(stream.collect(Collectors.toList())).thenApply(response -> l(response.getResults()));
}
}
use of org.eclipse.milo.opcua.stack.core.types.structured.WriteValue in project milo by eclipse.
the class UaNode method writeAttributeAsync.
/**
* An asynchronous implementation of {@link #writeAttribute(AttributeId, DataValue)}.
*
* @return a CompletableFuture that completes successfully with the operation result or
* completes exceptionally if a service-level error occurs.
*/
public CompletableFuture<StatusCode> writeAttributeAsync(AttributeId attributeId, DataValue value) {
WriteValue writeValue = new WriteValue(getNodeId(), attributeId.uid(), null, value);
CompletableFuture<WriteResponse> future = client.write(newArrayList(writeValue));
return future.thenApply(response -> response.getResults()[0]);
}
Aggregations