History: Historical Access
OPC UA defines 5 HistoryRead patterns, all of which this SDK implements.
Server Capabilities
The server must implement the Historian (historical archive) to return data; otherwise, it will return a uniform response BadHistoryOperationUnsupported.
Further Reading
- Basics — Historical Models — Concept
- Related Standards — HA Historical Access — Aggregate Functions NodeId
- Example — Exporting Historical Data — Complete Code
ReadHistory — Raw data for the time period
var dvs = ua.ReadHistory(
nodeId: "ns=2;s=Temperature",
startTime: DateTime.UtcNow.AddHours(-1),
endTime: DateTime.UtcNow,
maxValues: 1000);
foreach (var dv in dvs)
Console.WriteLine($"{dv.SourceTimestamp}: {dv.Value} ({dv.Status})");
A Quick Overview of the 5 Modes
| API | Uses |
|---|---|
| ReadHistory(nodeId, startTime, endTime, maxValues) | All raw data for the time period |
| ReadHistoryModified(nodeId, start, end, maxValues, returnBounds) | History including revision records (revision metadata is not currently visible) |
| ReadHistoryAtTime(nodeId, times, useSimpleBounds) | Interpolation at Specified Discrete Time Points |
| ReadHistoryProcessed(nodeId, start, end, processingInterval, aggregateNodeId) | Aggregation (Average / Minimum / Maximum / Count / Total / TimeAverage / ...) |
| ReadHistoryEvents(nodeId, start, end, maxEvents) | Event History |
For detailed specifications and examples, see SDK History Chapters.
HistoryUpdate — Write historical data
DataValue The constructor is not exposed externally; when committing the history, the retrieved instance is placed into it as-is values:
var values = ua.ReadHistory(
nodeId: "ns=2;s=Temperature",
startTime: DateTime.UtcNow.AddHours(-1),
endTime: DateTime.UtcNow);
// Submit as-is (Insert / Replace / Update)
var codes = ua.UpdateHistory(
"ns=2;s=Temperature", HistoryUpdateType.Update, values);
// Press SourceTimestamp Delete (Remove)
var del = ua.UpdateHistory(
"ns=2;s=Temperature", HistoryUpdateType.Remove, values);
DeleteHistoryRange — Delete historical data
var st = ua.DeleteHistoryRange(
"ns=2;s=Temperature",
start: DateTime.UtcNow.AddDays(-30),
end: DateTime.UtcNow.AddDays(-7),
deleteModifiedToo: false);
HistoryUpdate / Delete: Disabled by default
On most production servers, the HistoryUpdate/Delete command is disabled by default and must be explicitly enabled by an administrator.