HY,
我是milo(和OPC-UA)的新手,并尝试通过历史数据访问实现OPC-UA服务器。我重用了当前的milo服务器示例,并创建了一个历史节点。在此节点上,我可以(使用Prosys OPC UA客户端)查询空历史记录。我知道我必须自己实现历史节点的持久性。
到目前为止一切顺利–但是我找不到有关处理历史读取请求以及如何返回响应的任何信息。更精确地讲,如何将HistoryData
添加到HistoryReadResult
@Override
public void historyRead(HistoryReadContext context, HistoryReadDetails readDetails, TimestampsToReturn timestamps,
List<HistoryReadValueId> readValueIds)
{
List<HistoryReadResult> results = Lists.newArrayListWithCapacity(readValueIds.size());
for (HistoryReadValueId readValueId : readValueIds){
//return 3 historical entries
DataValue v1 = new DataValue(new Variant(new Double(1)), StatusCode.GOOD, new DateTime(Date.from(Instant.now().minus(1, ChronoUnit.MINUTES))));
DataValue v2 = new DataValue(new Variant(new Double(2)), StatusCode.GOOD, new DateTime(Date.from(Instant.now().minus(2, ChronoUnit.MINUTES))));
DataValue v3 = new DataValue(new Variant(new Double(3)), StatusCode.GOOD, new DateTime(Date.from(Instant.now().minus(3, ChronoUnit.MINUTES))));
HistoryData data = new HistoryData(new DataValue[] {v1,v2,v3});
//???
HistoryReadResult result = new HistoryReadResult(StatusCode.GOOD, ByteString.NULL_VALUE, ??? );
results.add(result);
}
context.complete(results);
}
最佳答案
您将需要访问规范才能成功实现历史访问服务。第4部分和第11部分。HistoryReadResult
构造函数中的最后一个参数应该是HistoryData
结构。 ExtensionObject
基本上是对结构进行编码和传输的容器。
要创建该ExtensionObject
,您首先要创建一个HistoryData
(或HistoryModifiedData
,取决于...请参见规格),然后执行类似ExtensionObject.encode(historyData)
的操作来获取完成该HistoryReadResult
所需的对象。