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

API​

MembersCategoryReading and WritingNote
NumericRange.all()Factory—The entire interval
NumericRange.single(int)Factory—Single Index
NumericRange.span(start, end)Factory—Range
NumericRange.multi(NumericRange...)Factory—Multidimensional
NumericRange.parse(s)Static—Analysis (IllegalArgumentException)
NumericRange.tryParse(s)Static—Security Analysis (Optional)
range.toString()——Serialization (Returns an empty string for the entire segment)
range.start() / end() / subRanges() / isAll()PropertiesReadField
ua.readRange(nid, range)SessionReadRead the "Value" subsection (currently, only the entire section is valid)
ua.readRange(nid, range, attr)SessionReadRead the sub-segments of a specified attribute (currently only valid for entire segments)
ua.writeRange(nid, range, value)SessionWriteWrite the "Value" subsection (currently, only the entire section is valid)
ua.writeRange(nid, range, value, attr)SessionWriteWrite a subinterval with specified attributes (currently only valid for entire intervals)

Code Example​

import com.darra.opcua.*;

try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();

// 1) Scope Construction and Serialization
NumericRange one = NumericRange.single(3);
NumericRange seg = NumericRange.span(0, 99);
NumericRange r2D = NumericRange.multi(
NumericRange.span(0, 9), NumericRange.span(0, 9));

System.out.println(one); // 3
System.out.println(seg); // 0:99
System.out.println(r2D); // 0:9,0:9
System.out.println(seg.isAll()); // false

// 2) Read the entire paragraph — equivalent to ua.read(nid)
try (OpcUaDataValue dv = ua.readRange("ns=2;s=Arr", NumericRange.all())) {
System.out.println("Arr = " + dv.variant());
}

// 3) Write the entire block — equivalent to ua.write(nid, value)
try (OpcUaVariant v = new OpcUaVariant().setDouble(42.5)) {
Enums.StatusCode rc = ua.writeRange("ns=2;s=Arr", NumericRange.all(), v);
System.out.println("write = " + rc);
}

// 4) Analysis
NumericRange r = NumericRange.parse("3:7");
System.out.println(r.start() + " .. " + r.end());
}
Sub-segment read/write operations are not currently supported

readRange / An exception is thrown when a non-integer segment range is writeRange received UnsupportedOperationException; only NumericRange.all() works (internally, it is directly forwarded to read / write). Read/write entry points for array sub-segments are not currently provided.

Implementation Notes​

  • When the scope is the entire segment (range.isAll()), forward readRange directly read; forward directly writeRange write
  • range Pass null to process the entire interval
  • Partial ranges throw UnsupportedOperationException and log a "Warn"-level event (status code BadNotSupported)

Error Handling​

StatusCodeMeaning
GoodSuccess
BadNotReadableNode is not readable
BadNotWritableNode is not writable
BadTypeMismatchThe value type does not match DataType the node.
BadNotSupportedThis request is not supported on the server or client side.

parse Thrown when the range string is invalid IllegalArgumentException; returns tryParse Optional.empty(). A dedicated status code for out-of-range errors is not currently provided.

Best Practices​

  • For large arrays, first use span / single to specify the target range; don't use a string parse every time.
  • The matrix range is assembled multi dimension-by-dimension and expressed in the form of a concatenation of toString() submatrices.
  • Sub-segment read/write operations are not currently supported. To modify a portion of an array, you must first read the entire segment and then write the entire segment back after making the changes.

Cross-Language Comparison​

C#PythonJavaC++RustC
NumericRangeNumericRangeNumericRangeNumericRangeNumericRangeDarraUa_NumericRange
ReadRangeread_rangereadRangeReadRangeread_rangeDarraUa_Session_ReadRange
WriteRangewrite_rangewriteRangeWriteRangewrite_rangeDarraUa_Session_WriteRange

Next Step​