Skip to main content

DataValue (C)

DarraUa_DataValue* All information returned by a single Read operation: value + status + timestamp.

Supporting

Public API​

CategoryPropertyTypeAccessDescription
Life CycleDarraUa_DataValue_New()DarraUa_DataValue*RWCreate a new empty instance (DataValue to populate values for DarraUa_Session_HistoryUpdateData)
DarraUa_DataValue_Delete(dv)voidWRelease; safe when dv is NULL
FieldsDarraUa_DataValue_GetValue(dv)const DarraUa_Variant*RActual value, lifetime = dv, do not delete
DarraUa_DataValue_GetStatus(dv)uint32_tRData Quality StatusCode
DarraUa_DataValue_GetSourceTimestamp(dv)DarraUa_DateTimeRData source timestamp (100ns since 1601)
DarraUa_DataValue_GetServerTimestamp(dv)DarraUa_DateTimeRServer timestamp

Usage​

DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "ns=2;s=Temperature", UA_ATTR_VALUE, &st);
if (!dv) return;

/* 1. Quality Inspection */
uint32_t dv_status = DarraUa_DataValue_GetStatus(dv);
if (UA_STATUS_IS_BAD(dv_status)) {
printf("Bad value: %s\n", DarraUa_StatusName(dv_status));
DarraUa_DataValue_Delete(dv);
return;
}

/* 2. The check value is not empty */
const DarraUa_Variant* v = DarraUa_DataValue_GetValue(dv);
if (!v || DarraUa_Variant_GetType(v) == UA_TYPE_NULL) {
printf("Null value\n");
DarraUa_DataValue_Delete(dv);
return;
}

/* 3. Value + Timestamp */
double t = 0.0;
DarraUa_Variant_GetDouble(v, &t);
DarraUa_DateTime src = DarraUa_DataValue_GetSourceTimestamp(dv);
printf("%.2f °C @ ft=%lld\n", t, (long long)src);

/* 4. Release */
DarraUa_DataValue_Delete(dv);

StatusCode Key Value​

ValueMeaning
UA_STATUS_GOOD (0x00000000)Everything is normal
0x40000000+ (Uncertain*)Uncertain but available
0x80000000+ (Bad*)Invalid data
UA_STATUS_BAD_COMMUNICATION_ERRORCommunication Failed
UA_STATUS_BAD_NODE_ID_UNKNOWNThe node does not exist
UA_STATUS_BAD_NOT_READABLEThis attribute is not readable.

Determining Macros:

UA_STATUS_IS_GOOD(code)
UA_STATUS_IS_UNCERTAIN(code)
UA_STATUS_IS_BAD(code)

Business logic must be verified DataValue.Status; you cannot simply assume it is correct.

Meaning of Timestamps​

DarraUa_DateTime is int64_t, the unit 100ns is 1601-01-01 UTC. Just like FILETIME in Windows, the conversion time_t formula is:

/* DateTime → Unix epoch (seconds) */
double unix_sec = (ft - 116444736000000000LL) / 10000000.0;

/* Unix epoch (seconds) → DateTime */
DarraUa_DateTime ft = (DarraUa_DateTime)(unix_sec * 10000000.0) + 116444736000000000LL;
TimestampMeaning
SourceTimestampActual data generation time (sensor sampling time / calculation time). Use this for historical data, trends, and synchronization.
ServerTimestampServer receive/process time. Used to diagnose network latency; generally not used for business operations.

If the server does not have a SourceTimestamp set, it is a copy of ServerTimestamp.

Memory Ownership​

SourceRelease
DarraUa_Session_ReadNode(...) Single itemDarraUa_DataValue_Delete(dv)
DarraUa_Session_ReadNodes(...) / _Read each element of the arrayEach non-NULL entry DarraUa_DataValue_Delete
DarraUa_Session_HistoryReadRaw / _Modified / _AtTime / _ProcessedDarraUa_DataValueArray_Delete(arr, count) (one-time)
DarraUa_DataValue_New()DarraUa_DataValue_Delete(dv)

A "Delete" leak causes native memory to be leaked.

Best Practices:

/* Single item */
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(h, id, attr, &st);
if (dv) {
/* ... */
DarraUa_DataValue_Delete(dv);
}

/* Batch */
DarraUa_DataValue* dvs[100] = { NULL };
DarraUa_Session_ReadNodes(h, ids, NULL, 100, dvs);
for (int i = 0; i < 100; ++i) {
if (dvs[i]) DarraUa_DataValue_Delete(dvs[i]);
}

/* History (One-time release) */
DarraUa_DataValue** hist = NULL; uint32_t cnt = 0;
DarraUa_Session_HistoryReadRaw(h, id, t1, t2, 0, 0, &hist, &cnt);
DarraUa_DataValueArray_Delete(hist, cnt);

Next Step​