ReadHistory (Raw)
The following prototypes are member methods Session of.
std::vector<DataValue> ReadHistory(
std::string const& node_id,
int64_t start_utc_100ns,
int64_t end_utc_100ns,
uint32_t max_values = 0,
bool return_bounds = false);
The most commonly used historical read, which returns all raw data points within the specified [start, end] interval.
Preliminary / Supporting
- Switch to this when there are too many high-frequency data points ReadHistoryProcessed Aggregation.
- If you want to include revision history, please use ReadHistoryModified.
- Time spent FileTime (UTC 100ns since 1601), see the conversion formula at History Overview.
Parameters
| Parameters | Default | Note |
|---|---|---|
| node_id | — | Objective NodeId |
| start_utc_100ns | — | Range starts at (FileTime) |
| end_utc_100ns | — | Range Stop (FileTime) |
| max_values | 0 | Maximum number of records per response; 0 = no limit (the server may still set its own limit) |
| return_bounds | false | true = The endpoint must be included in the results |
Usage
#include <darra/opcua/client.hpp>
#include <chrono>
#include <iostream>
using namespace darra::opcua;
Session s("opc.tcp://localhost:4840");
s.Connect();
constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;
auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
int64_t end_ft = WIN_EPOCH_OFFSET + now_ns / 100;
int64_t start_ft = end_ft - 3600LL * 10000000LL; // 1 hour ago
auto dvs = s.ReadHistory("ns=2;s=Temperature",
start_ft, end_ft, /*max_values=*/1000);
for (auto const& dv : dvs) {
std::cout << "ft=" << dv.SourceTimestamp()
<< " val=" << dv.Value().AsString()
<< " status=0x" << std::hex << dv.StatusCode() << "\n";
}
Exception
When an error occurs Exception, throw an exception with a message in the following format HistoryRead 'ns=2;s=Temperature' failed: 0x80720000: The status code is returned as-is by the server; use (e.status_code() uint32_t) or e.status()(Status enum) to retrieve it, and use for the human-readable name Stack::StatusName(e.status_code()).
| Status Code | Meaning |
|---|---|
BadHistoryOperationUnsupported | There is no Historian on the server |
BadNotReadable | The node does not have permission HistoryRead. |
BadCommunicationError | Network Outage |
Performance and Best Practices
- High-frequency data (1000 Hz+) pulled for one day = 86 million+ points → Must use a
max_valueslimit or switch to ReadHistoryProcessed Aggregation std::vector<DataValue>Elements are automatically released when the object is destroyed; there is no need to manually call Delete.- All timestamps must be consistent UTC FileTime; do not use local time.