[英]Error fetching data from Rockwell OPC UA Server using Eclipse Milo JAva Client
[英]Milo OPC UA Server with Historical Data Access
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
所需的對象。
覆蓋historyRead是正確的方法。
HistoryReadResult result = new HistoryReadResult(StatusCode.GOOD, ByteString.NULL_VALUE,ExtensionObject.encode(data) );
但是,在使用特定的AccessLevel和Historizing模式定義我的variableNode之前,通用客戶端(例如UA-Expert)未調用method:
Set<AccessLevel> acclevels = new LinkedHashSet<>();
acclevels.add(AccessLevel.CurrentRead);
acclevels.add(AccessLevel.CurrentWrite);
acclevels.add(AccessLevel.HistoryRead);
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(server.getNodeMap())
.setNodeId(new NodeId(namespaceIndex, "HelloWorld/Test/" + name))
.setAccessLevel(ubyte(AccessLevel.getMask(acclevels)))
.setUserAccessLevel(ubyte(AccessLevel.getMask(acclevels)))
.setBrowseName(new QualifiedName(namespaceIndex, name))
.setDisplayName(LocalizedText.english(name))
.setDataType(typeId)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.setHistorizing(true)
.build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.