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() | Static | — | The entire interval |
| NumericRange::Single(int) | Static | — | Single Index |
| NumericRange::Span(start, end) | Static | — | Closed interval |
| NumericRange::Multi(std::vector<NumericRange>) | Static | — | Multidimensional |
| NumericRange::Parse(s) | Static | — | Analysis: Illegal throw of std::invalid_argument |
| NumericRange::TryParse(s) | Static | — | Analysis, Illegal Returns std::nullopt |
| range.ToString() | Methods | Read | Serialize to a NumericRange string; return "" for the entire segment |
| range.start / range.end / range.sub_ranges | Field | Reading and Writing | Range Subscripts and Multidimensional Subsegments |
| range.IsAll() | Methods | Read | Is this the entire interval? |
| ReadRange(session, nid, range, attr) | Free Functions | Read | Read the "Value" subsection |
| WriteRange(session, nid, range, value, attr) | Free Functions | Write | Write the "Value" subsection |
ReadRange / WriteRange is a free function in the namespace darra::opcua; it is not a member of Session.
Code Example
#include <darra/opcua/client.hpp>
#include <darra/opcua/numeric_range.hpp>
using namespace darra::opcua;
Stack::Init();
Session s("opc.tcp://localhost:4840");
s.Connect();
// 1) Read the entire passage — Forward directly Session::Read
auto dv = ReadRange(s, "ns=2;s=Arr", NumericRange::All());
std::cout << "Arr = " << dv.Value().AsString() << "\n";
// 2) Copy the entire paragraph — Forward directly Session::Write
Variant v;
v.SetDouble(42.5);
auto st = WriteRange(s, "ns=2;s=Arr", NumericRange::All(), v);
// 3) Construction and Serialization of Subsegments (See "Implementation Notes" for restrictions on reading and writing subsegments)
auto single = NumericRange::Single(3); // "3"
auto span = NumericRange::Span(0, 99); // "0:99"
auto r2D = NumericRange::Multi({
NumericRange::Span(0, 9), NumericRange::Span(0, 9)
}); // "0:9,0:9"
std::cout << r2D.ToString() << "\n";
// 4) Analysis
auto r = NumericRange::Parse("3:7");
std::cout << r.ToString() << "\n";
Implementation Notes
- The entire section (
range.IsAll())ReadRange/WriteRangeSkip aheadSession::Read/Session::Write - Non-integer segments are not supported by the current stack:
ReadRangeThrow an exception and issueException(Status::Bad)a warning,WriteRangeReturns and issueStatus::Bada warning
Error Handling
| Status | Meaning |
|---|---|
| Status::Good | Success |
| Status::Bad | Outside the scope of a non-whole-block; not currently supported by Stack. |
NumericRange::Parse If an invalid string is encountered std::invalid_argument, a throw occurs; no Status is returned.
Best Practices
ToString()The result is a string OPC UA NumericRange; the entire segment returns "".- Cache frequently used ranges so you don't have to do it every time.
Parse - For multidimensional subsections, list them in order by
Multidimension.
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 |