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()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()MethodsReadSerialize to a NumericRange string; return "" for the entire segment
range.start / range.end / range.sub_rangesFieldReading and WritingRange Subscripts and Multidimensional Subsegments
range.IsAll()MethodsReadIs this the entire interval?
ReadRange(session, nid, range, attr)Free FunctionsReadRead the "Value" subsection
WriteRange(session, nid, range, value, attr)Free FunctionsWriteWrite 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/ WriteRange Skip ahead Session::Read / Session::Write
  • Non-integer segments are not supported by the current stack: ReadRange Throw an exception and issue Exception(Status::Bad) a warning, WriteRange Returns and issue Status::Bad a warning

Error Handling​

StatusMeaning
Status::GoodSuccess
Status::BadOutside 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 Multi dimension.

Cross-Language Comparison​

C++PythonJavaC#RustC
NumericRangeNumericRangeNumericRangeNumericRangeNumericRangeDarraUa_NumericRange
ReadRangeread_rangereadRangeReadRangeread_rangeDarraUa_Session_ReadRange
WriteRangewrite_rangewriteRangeWriteRangewrite_rangeDarraUa_Session_WriteRange

Next Step​