Skip to main content

HistoryReadRaw (C)

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryReadRaw(
DarraUa_SessionHandle h,
const char* node_id_str,
DarraUa_DateTime start_time,
DarraUa_DateTime end_time,
uint32_t num_values_per_node, /* 0 = No limit */
DarraUa_Boolean return_bounds,
DarraUa_DataValue*** out_values,
uint32_t* out_count);

The most commonly used historical read returns the raw data points within the [start_time, end_time] interval; the actual number of points is limited num_values_per_node.

Preliminary / Supporting
  • Switch to this when there are too many high-frequency data points ReadProcessed Aggregation.
  • If you want to include revision history, please use ReadModified.

Parameters​

ParametersDefaultNote
node_id_str—Target NodeId String
start_time—Since (UTC, 100ns since 1601)
end_time—Range Stop
num_values_per_node0 (No limit)Maximum number of results per query
return_bounds0/1Whether to return boundary points (endpoints must be included)
out_values—Output parameters: out_values points to an array of DataValue allocated by Stack's malloc
out_count—Parameter, array length

Memory Release​

DarraUa_DataValue** arr = NULL;
uint32_t cnt = 0;
DarraUa_Session_HistoryReadRaw(h, "ns=2;s=Temperature",
start, end, 1000, /*bounds*/ 1, &arr, &cnt);

/* ... Use ... */

DarraUa_DataValueArray_Delete(arr, cnt); /* Release an array in one go + each item */

Complete Usage​

#include <opcua/opcua.h>
#include <opcua/opcua_history.h>
#include <stdio.h>
#include <time.h>

static DarraUa_DateTime utc_now_ft(void) {
return (DarraUa_DateTime)((int64_t)time(NULL) * 10000000LL + 116444736000000000LL);
}

int main(void)
{
/* ... Connect [omitted] ... */
DarraUa_SessionHandle h = /* ... */ 0;

DarraUa_DateTime end = utc_now_ft();
DarraUa_DateTime start = end - 36000000000LL; /* 1 hour = 3600 seconds */

DarraUa_DataValue** values = NULL;
uint32_t count = 0;

DarraUa_Status st = DarraUa_Session_HistoryReadRaw(
h, "ns=2;s=Temperature",
start, end,
/*num*/ 1000,
/*return_bounds*/ 1,
&values, &count);

if (!UA_STATUS_IS_GOOD(st)) {
fprintf(stderr, "HistoryReadRaw failed: %s\n", DarraUa_StatusName(st));
return -1;
}

printf("Got %u points\n", (unsigned)count);
for (uint32_t i = 0; i < count; ++i) {
const DarraUa_Variant* v = DarraUa_DataValue_GetValue(values[i]);
DarraUa_DateTime ts = DarraUa_DataValue_GetSourceTimestamp(values[i]);
double d = 0.0; DarraUa_Variant_GetDouble(v, &d);
printf(" ft=%lld v=%g\n", (long long)ts, d);
}

DarraUa_DataValueArray_Delete(values, count);
return 0;
}

Error Code​

The response returned by the server consists StatusCode of SDK Pass-through as-is (BadHistoryOperationUnsupported / BadNotSupported / BadNotReadable etc., are server-side codes; there are no corresponding macros in the client-side headers). Errors generated by the client stack use the following predefined macros:

Status CodeMeaning
UA_STATUS_GOODSuccess
UA_STATUS_BAD_SERVER_NOT_CONNECTEDSession Not Connected
UA_STATUS_INVALID_HANDLEInvalid session handle
UA_STATUS_INVALID_ARGUMENTInvalid parameter (including node_id_str parsing errors)
UA_STATUS_BAD_COMMUNICATION_ERRORNetwork Outage
UA_STATUS_BAD_TIMEOUTSingle-use RPC Timeout
UA_STATUS_BAD_ENCODING_ERROR / UA_STATUS_BAD_DECODING_ERROREncoding/decoding failed

The severity of the return value is UA_STATUS_IS_GOOD determined using UA_STATUS_IS_UNCERTAIN / UA_STATUS_IS_BAD /, and the result is printed as a short English DarraUa_StatusName name.

Performance and Best Practices​

  • High-frequency data generates an extremely large number of raw data points per day → It is necessary to apply a limit num_values_per_node or switch to ReadProcessed Aggregation
  • You must use a one-time DarraUa_DataValueArray_Delete release; do not repeatedly use "Delete + free" on the array.
  • All timestamps UTC

Next Step​