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 |
API
| Members | Category | Reading and Writing | Note |
|---|---|---|---|
| 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() | Properties | Read | Field |
| ua.readRange(nid, range) | Session | Read | Read the "Value" subsection (currently, only the entire section is valid) |
| ua.readRange(nid, range, attr) | Session | Read | Read the sub-segments of a specified attribute (currently only valid for entire segments) |
| ua.writeRange(nid, range, value) | Session | Write | Write the "Value" subsection (currently, only the entire section is valid) |
| ua.writeRange(nid, range, value, attr) | Session | Write | Write 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()), forwardreadRangedirectlyread; forward directlywriteRangewrite rangePass null to process the entire interval- Partial ranges throw
UnsupportedOperationExceptionand log a "Warn"-level event (status codeBadNotSupported)
Error Handling
| StatusCode | Meaning |
|---|---|
| Good | Success |
| BadNotReadable | Node is not readable |
| BadNotWritable | Node is not writable |
| BadTypeMismatch | The value type does not match DataType the node. |
| BadNotSupported | This 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/singleto specify the target range; don't use a stringparseevery time. - The matrix range is assembled
multidimension-by-dimension and expressed in the form of a concatenation oftoString()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# | 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 |