Skip to main content

NumericRange

Overview​

OPC UA Part 4 §7.27 NumericRange denotes a sub-range of the array or matrix behind the Value property:

StringMeaning
""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​

FunctionCategoryReading and WritingNote
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)ExtensionsReadRead the passage
DarraUa_Session_WriteRange(h, nid, &range, value, attr)ExtensionsWriteWriting 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_WriteRange When the range covers the entire segment (DarraUa_NumericRange_IsAll returns a non-0 value), forward directly to DarraUa_Session_ReadNode / DarraUa_Session_WriteNode.
  • Implementation Notes: When IndexRange Stack does not support, DarraUa_Session_ReadRange / DarraUa_Session_WriteRange returns UA_STATUS_NOT_IMPLEMENTED(opcua_numeric_range.h the return value convention). The capabilities for parsing, constructing, and serializing ranges are complete; batch reads and writes of struct DarraUa_ReadValueId.index_range / DarraUa_WriteValue.index_range fields still accept format strings (such as "0:9",NULL which indicates all).
  • DarraUa_NumericRange_Multi Even if a deep copy is made dims to out_r.sub_dims, the caller must still iterate over each dims element of DarraUa_NumericRange_Clear.
  • DarraUa_NumericRange_Clear Recursive deallocation sub_dims; the structure itself is not deallocated.

Error Handling​

StatusCodeMeaning
UA_STATUS_GOODSuccess
UA_STATUS_BAD_INDEX_RANGE_INVALIDInvalid range string / Node is not an array
UA_STATUS_BAD_INDEX_RANGE_NO_DATAThe value falls outside the data range
UA_STATUS_BAD_TYPE_MISMATCHThe write type does not match the node.
UA_STATUS_BAD_NOT_WRITABLENode is not writable
UA_STATUS_NOT_IMPLEMENTEDStack is not supported IndexRange
UA_STATUS_INVALID_ARGUMENTInvalid multidimensional structure parameters

Best Practices​

  • Array/matrix subsets should always be expressed DarraUa_NumericRange using, not by manually constructing strings.
  • Don't parse it every time; use the Span/ Single construct instead.
  • After using tiaoDarraUa_NumericRange_Clear, free sub_dims the heap memory allocated for tiao.
  • Use strings when DarraUa_NumericRange_ToString passing data across ABI contexts to avoid passing structures

Cross-Language Comparison​

C#PythonJavaC++RustC
NumericRangeNumericRangeNumericRangeNumericRangeNumericRangeDarraUa_NumericRange
ReadRangeread_rangereadRangeReadRangeread_rangeDarraUa_Session_ReadRange
WriteRangewrite_rangewriteRangeWriteRangewrite_rangeDarraUa_Session_WriteRange

Next Step​