Search in sources :

Example 1 with HistoryReadDetails

use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails in project milo by eclipse.

the class HistoryReadExampleProsys method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    client.connect().get();
    HistoryReadDetails historyReadDetails = new ReadRawModifiedDetails(false, DateTime.MIN_VALUE, DateTime.now(), uint(0), true);
    HistoryReadValueId historyReadValueId = new HistoryReadValueId(new NodeId(3, "Counter"), null, QualifiedName.NULL_VALUE, ByteString.NULL_VALUE);
    List<HistoryReadValueId> nodesToRead = new ArrayList<>();
    nodesToRead.add(historyReadValueId);
    HistoryReadResponse historyReadResponse = client.historyRead(historyReadDetails, TimestampsToReturn.Both, false, nodesToRead).get();
    HistoryReadResult[] historyReadResults = historyReadResponse.getResults();
    if (historyReadResults != null) {
        HistoryReadResult historyReadResult = historyReadResults[0];
        StatusCode statusCode = historyReadResult.getStatusCode();
        if (statusCode.isGood()) {
            HistoryData historyData = (HistoryData) historyReadResult.getHistoryData().decode(client.getStaticSerializationContext());
            List<DataValue> dataValues = l(historyData.getDataValues());
            dataValues.forEach(v -> System.out.println("value=" + v));
        } else {
            System.out.println("History read failed: " + statusCode);
        }
    }
    future.complete(client);
}
Also used : HistoryData(org.eclipse.milo.opcua.stack.core.types.structured.HistoryData) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) ArrayList(java.util.ArrayList) ReadRawModifiedDetails(org.eclipse.milo.opcua.stack.core.types.structured.ReadRawModifiedDetails) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Example 2 with HistoryReadDetails

use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails in project milo by eclipse.

the class DefaultAttributeHistoryServiceSet method onHistoryRead.

@Override
public void onHistoryRead(ServiceRequest service) {
    historyReadMetric.record(service);
    HistoryReadRequest request = (HistoryReadRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<HistoryReadValueId> nodesToRead = l(request.getNodesToRead());
    if (nodesToRead.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToRead.size() > server.getConfig().getLimits().getMaxNodesPerRead().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    if (request.getTimestampsToReturn() == null) {
        service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
        return;
    }
    DiagnosticsContext<HistoryReadValueId> diagnosticsContext = new DiagnosticsContext<>();
    HistoryReadContext context = new HistoryReadContext(server, session, diagnosticsContext);
    HistoryReadDetails details = (HistoryReadDetails) request.getHistoryReadDetails().decode(server.getSerializationContext());
    server.getAddressSpaceManager().historyRead(context, details, request.getTimestampsToReturn(), nodesToRead);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
        HistoryReadResponse response = new HistoryReadResponse(header, a(values, HistoryReadResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) HistoryReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) HistoryReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) Session(org.eclipse.milo.opcua.sdk.server.Session)

Aggregations

HistoryReadDetails (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails)2 HistoryReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse)2 HistoryReadResult (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult)2 HistoryReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId)2 ArrayList (java.util.ArrayList)1 DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 Session (org.eclipse.milo.opcua.sdk.server.Session)1 HistoryReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext)1 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)1 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 HistoryData (org.eclipse.milo.opcua.stack.core.types.structured.HistoryData)1 HistoryReadRequest (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest)1 ReadRawModifiedDetails (org.eclipse.milo.opcua.stack.core.types.structured.ReadRawModifiedDetails)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1