use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult 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);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult in project milo by eclipse.
the class AttributeHistoryServices method historyRead.
/**
* Read history values from nodes belonging to this {@link AttributeHistoryServices}.
* <p>
* Complete the operation with {@link HistoryReadContext#success(Object)}.
*
* @param context the {@link HistoryReadContext}.
* @param timestamps requested timestamp values.
* @param readValueIds the values to read.
*/
default void historyRead(HistoryReadContext context, HistoryReadDetails readDetails, TimestampsToReturn timestamps, List<HistoryReadValueId> readValueIds) {
HistoryReadResult result = new HistoryReadResult(new StatusCode(StatusCodes.Bad_HistoryOperationUnsupported), null, null);
context.success(Collections.nCopies(readValueIds.size(), result));
}
use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult in project tech-pdai-spring-demos by realpdai.
the class OpcUaClientServiceImpl method retrieveCustomHistoryData.
/**
* retrieve custom type history data.
*
* @param historyReadValueId node id
* @return data
* @throws java.security.UnrecoverableKeyException UnrecoverableKey Exception
* @throws org.eclipse.milo.opcua.stack.core.UaException Ua Exception
* @throws java.security.cert.CertificateException Certificate Exception
* @throws java.io.IOException IO Exception
* @throws java.security.KeyStoreException KeyStore Exception
* @throws java.security.NoSuchAlgorithmException NoSuchAlgorithm Exception
* @throws java.util.concurrent.ExecutionException Execution Exception
* @throws InterruptedException Interrupted Exception
*/
@Override
public List<CustomStructType> retrieveCustomHistoryData(HistoryReadValueId historyReadValueId) throws UnrecoverableKeyException, UaException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ExecutionException, InterruptedException {
log.info("trying to get custom data from node {}", historyReadValueId);
OpcUaClient opcClient = getOpcUaClient();
try {
// connect
log.info("connect to opc server");
opcClient.addSessionInitializer(new DataTypeDictionarySessionInitializer(new GenericBsdParser()));
opcClient.connect().get();
// read history
HistoryReadResponse historyReadResponse = opcClient.historyRead(new ReadRawModifiedDetails(false, DateTime.MIN_VALUE, DateTime.now(), uint(0), true), TimestampsToReturn.Both, false, Collections.singletonList(historyReadValueId)).get();
// register custom codec
log.info("register custom codec");
registerCustomCodec(opcClient);
// parse result
log.info("parse history data result");
HistoryReadResult[] historyReadResults = historyReadResponse.getResults();
if (historyReadResults != null) {
HistoryReadResult historyReadResult = historyReadResults[0];
StatusCode statusCode = historyReadResult.getStatusCode();
// check if status code is good
if (statusCode.isGood()) {
HistoryData historyData = (HistoryData) historyReadResult.getHistoryData().decode(opcClient.getStaticSerializationContext());
// parse node value to custom type
return l(historyData.getDataValues()).stream().map(value -> {
log.info("Value={}", value);
Variant variant = value.getValue();
ExtensionObject xo = (ExtensionObject) variant.getValue();
// decode value
CustomStructType decoded = (CustomStructType) xo.decode(opcClient.getStaticSerializationContext());
log.info("Decoded={}", decoded);
return decoded;
}).collect(Collectors.toList());
} else {
log.error("History read failed: {}", statusCode);
}
}
return new ArrayList<>();
} finally {
opcClient.disconnect();
}
}
use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult in project tech-pdai-spring-demos by realpdai.
the class OpcUaClientServiceImpl method retrieveGenericHistoryData.
/**
* retrieve history data.
*
* @param historyReadValueId historyReadValueId
* @return history data value
* @throws java.security.UnrecoverableKeyException UnrecoverableKey Exception
* @throws UaException Ua Exception
* @throws java.security.cert.CertificateException Certificate Exception
* @throws java.io.IOException IO Exception
* @throws java.security.KeyStoreException KeyStore Exception
* @throws java.security.NoSuchAlgorithmException NoSuchAlgorithm Exception
* @throws java.util.concurrent.ExecutionException Execution Exception
* @throws InterruptedException Interrupted Exception
*/
@Override
public List<DataValue> retrieveGenericHistoryData(HistoryReadValueId historyReadValueId) throws UnrecoverableKeyException, UaException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, ExecutionException, InterruptedException {
OpcUaClient opcClient = getOpcUaClient();
try {
HistoryReadResponse historyReadResponse = opcClient.historyRead(new ReadRawModifiedDetails(false, DateTime.MIN_VALUE, DateTime.now(), uint(0), true), TimestampsToReturn.Both, false, Collections.singletonList(historyReadValueId)).get();
// parse result
HistoryReadResult[] historyReadResults = historyReadResponse.getResults();
if (historyReadResults != null) {
HistoryReadResult historyReadResult = historyReadResults[0];
StatusCode statusCode = historyReadResult.getStatusCode();
if (statusCode.isGood()) {
HistoryData historyData = (HistoryData) historyReadResult.getHistoryData().decode(opcClient.getStaticSerializationContext());
return l(historyData.getDataValues());
} else {
log.error("History read failed: {}", statusCode);
}
}
return new ArrayList<>();
} finally {
opcClient.disconnect();
}
}
Aggregations