NumericRange
Overview
OPC UA Part 4 §7.27 NumericRange denotes a sub-range of the array or matrix behind the Value property:
| String | Meaning |
|---|---|
| "" | The entire interval |
| "5" | No. 5 |
| "3:7" | 3–7 |
| "1:3,2:4" | Two-dimensional |
Structure
#define UA_NUMERIC_RANGE_MAX_DIMS 4
struct DarraUa_NumericRange {
int32_t start; /* Starting subscript; -1 = entire paragraph */
int32_t end; /* End of index (inclusive) */
uint32_t sub_count; /* Dimensions in Multidimensional Time */
DarraUa_NumericRange* sub_dims; /* Memory available: sub_count units */
};
For a single dimension sub_count = 0; for multiple dimensions start = end = -1, the range for each dimension is set to sub_dims. start = end = -1 And sub_count = 0 — that is, the entire segment.
API
| Function | Category | Reading and Writing | Note |
|---|---|---|---|
| DarraUa_NumericRange_All(&out_r) | Structure | — | The entire interval |
| DarraUa_NumericRange_Single(&out_r, idx) | Structure | — | Single Index |
| DarraUa_NumericRange_Span(&out_r, start, end) | Structure | — | Range |
| DarraUa_NumericRange_Multi(&out_r, dims, dims_count) | Structure | — | Multidimensional |
| DarraUa_NumericRange_Parse(s, &out_r) | Analysis | — | Parse a String |
| DarraUa_NumericRange_ToString(r, buf, buf_len) | Serialization | — | Writes to the caller's buffer and returns the number of bytes written |
| DarraUa_NumericRange_IsAll(r) | Determination | — | The entire segment returns a non-0 value |
| DarraUa_NumericRange_Clear(&r) | Release | — | Free sub_dims, but do not free r itself |
| DarraUa_Session_ReadRange(h, nid, &range, attr, &out_dv) | Extensions | Read | Read the passage |
| DarraUa_Session_WriteRange(h, nid, &range, value, attr) | Extensions | Write | Writing Subintervals |
Code Example
This example demonstrates the construction, serialization, and release of a range, as well as the call signature of ReadRange WriteRange/. For a description UA_STATUS_NOT_IMPLEMENTED of in the return value, see "Implementation Notes" below.
#include <opcua.h>
#include <opcua_numeric_range.h>
int main(void) {
DarraUa_Initialize();
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = "opc.tcp://localhost:4840";
DarraUa_SessionHandle h = 0;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);
/* 1) Entire paragraph — Forward ReadRange to DarraUa_Session_ReadNode */
DarraUa_NumericRange rall;
DarraUa_NumericRange_All(&rall);
DarraUa_DataValue* dv0 = NULL;
DarraUa_Session_ReadRange(h, "ns=2;s=Arr", &rall, UA_ATTR_VALUE, &dv0);
DarraUa_DataValue_Delete(dv0);
DarraUa_NumericRange_Clear(&rall);
/* 2) Single Index — Construction / Determination / Serialization */
DarraUa_NumericRange r1;
DarraUa_NumericRange_Single(&r1, 3);
char buf[32];
size_t n = DarraUa_NumericRange_ToString(&r1, buf, sizeof(buf));
(void)n; /* buf = "3" */
DarraUa_NumericRange_Clear(&r1);
/* 3) Interval */
DarraUa_NumericRange r2;
DarraUa_NumericRange_Span(&r2, 0, 99);
DarraUa_DataValue* dv2 = NULL;
DarraUa_Session_ReadRange(h, "ns=2;s=Arr", &r2, UA_ATTR_VALUE, &dv2);
DarraUa_DataValue_Delete(dv2);
DarraUa_NumericRange_Clear(&r2);
/* 4) Two-Dimensional Subsegments — Construction */
DarraUa_NumericRange dim_a, dim_b;
DarraUa_NumericRange_Span(&dim_a, 0, 9);
DarraUa_NumericRange_Span(&dim_b, 0, 9);
DarraUa_NumericRange dims[] = { dim_a, dim_b };
DarraUa_NumericRange r2d;
DarraUa_NumericRange_Multi(&r2d, dims, 2);
DarraUa_NumericRange_Clear(&r2d);
DarraUa_NumericRange_Clear(&dim_a);
DarraUa_NumericRange_Clear(&dim_b);
/* 5) Write the entire paragraph — WriteRange Forward to DarraUa_Session_WriteNode */
DarraUa_NumericRange rall2;
DarraUa_NumericRange_All(&rall2);
DarraUa_Variant* v = DarraUa_Variant_New();
DarraUa_Variant_SetDouble(v, 42.5);
DarraUa_Status st = DarraUa_Session_WriteRange(
h, "ns=2;s=Arr", &rall2, v, UA_ATTR_VALUE);
if (!UA_STATUS_IS_GOOD(st))
fprintf(stderr, "WriteRange failed: %s\n", DarraUa_StatusName(st));
DarraUa_Variant_Delete(v);
DarraUa_NumericRange_Clear(&rall2);
DarraUa_Session_Close(h);
DarraUa_Shutdown();
return 0;
}
Implementation Notes
DarraUa_Session_ReadRange/DarraUa_Session_WriteRangeWhen the range covers the entire segment (DarraUa_NumericRange_IsAllreturns a non-0 value), forward directly toDarraUa_Session_ReadNode/DarraUa_Session_WriteNode.- Implementation Notes: When IndexRange Stack does not support,
DarraUa_Session_ReadRange/DarraUa_Session_WriteRangereturnsUA_STATUS_NOT_IMPLEMENTED(opcua_numeric_range.hthe return value convention). The capabilities for parsing, constructing, and serializing ranges are complete; batch reads and writes of structDarraUa_ReadValueId.index_range/DarraUa_WriteValue.index_rangefields still accept format strings (such as"0:9",NULLwhich indicates all). DarraUa_NumericRange_MultiEven if a deep copy is madedimstoout_r.sub_dims, the caller must still iterate over eachdimselement ofDarraUa_NumericRange_Clear.DarraUa_NumericRange_ClearRecursive deallocationsub_dims; the structure itself is not deallocated.
Error Handling
| StatusCode | Meaning |
|---|---|
| UA_STATUS_GOOD | Success |
| UA_STATUS_BAD_INDEX_RANGE_INVALID | Invalid range string / Node is not an array |
| UA_STATUS_BAD_INDEX_RANGE_NO_DATA | The value falls outside the data range |
| UA_STATUS_BAD_TYPE_MISMATCH | The write type does not match the node. |
| UA_STATUS_BAD_NOT_WRITABLE | Node is not writable |
| UA_STATUS_NOT_IMPLEMENTED | Stack is not supported IndexRange |
| UA_STATUS_INVALID_ARGUMENT | Invalid multidimensional structure parameters |
Best Practices
- Array/matrix subsets should always be expressed
DarraUa_NumericRangeusing, not by manually constructing strings. - Don't parse it every time; use the
Span/Singleconstruct instead. - After using tiao
DarraUa_NumericRange_Clear, freesub_dimsthe heap memory allocated for tiao. - Use strings when
DarraUa_NumericRange_ToStringpassing data across ABI contexts to avoid passing structures
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| NumericRange | NumericRange | NumericRange | NumericRange | NumericRange | DarraUa_NumericRange |
| ReadRange | read_range | readRange | ReadRange | read_range | DarraUa_Session_ReadRange |
| WriteRange | write_range | writeRange | WriteRange | write_range | DarraUa_Session_WriteRange |