OpcUaDataValue
OpcUaDataValue All information returned by a single read operation: value + status + timestamp.
- For the internal value container, please see OpcUaVariant.
- For standard node constants, see WellKnownNodes.
Public Attributes
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Value | value | Any | R | Pythonic decoding (= variant.value, automatic DataType ) |
variant | OpcUaVariant | R | Primitive Variant (borrowed, no need to dispose) | |
status | StatusCode | R | Data quality: Good / Bad* / Uncertain* | |
is_good | bool | R | (status == StatusCode.Good) | |
| Timestamps (UTC) | source_timestamp | Optional[datetime] | R | Timestamp from the data source |
server_timestamp | Optional[datetime] | R | Timestamp when the server received the request |
Structure
It is typically constructed SDK (returns read_many from read / read_history /). Users can also wrap a resource handle themselves (advanced usage; generally not necessary).
There are currently no publicly available Python side constructors.: OpcUaDataValue.__init__ It only accepts resource handles; there is no entry point for creating them from_value(...). So, at this stage ua.update_history(node_id, update_type, values) OpcUaDataValue, you can only pass in read or retrieve read_history them—you can't create your own and write them in. This is a current limitation, not a problem with the implementation.
Usage
import datetime as dt
def read_temperature(ua) -> "float | None":
with ua.read("ns=2;s=Temperature") as dv:
# Quality Inspection
if not dv.is_good:
print(f"Bad value: {dv.status.name}")
return None
# Check for Null
if dv.variant.is_null:
print("Null value")
return None
# Value (Pythonic)
temp: float = dv.value
t: dt.datetime = dv.source_timestamp or dt.datetime.now(dt.timezone.utc)
print(f"{t.isoformat()}: {temp} °C")
# Or strong type extraction (Optional[float]; returns None if the types do not match)
temp = dv.variant.as_double
return temp
StatusCode Key Value
| Value | Meaning |
|---|---|
| Good (0x00000000) | Everything is normal |
| Uncertain* (0x40000000+) | Uncertain but usable (e.g., sensor out of range) |
| Bad* (0x80000000+) | Invalid data |
| BadCommunicationError | Communication Failed |
| BadNodeIdUnknown | The node does not exist |
| BadNotReadable | This attribute is not readable. |
Business logic must check status (or use is_good), and should not assume Good.
Meaning of Timestamps
source_timestamp— Actual Time the Data Was Generated (Sensor sampling time / calculation time). Use this for history, trends, and synchronization.server_timestamp— Server Receive/Processing Time. Used to diagnose network latency. Generally not used for business purposes.
The SDK does not pad timestamps: when the server supplies none, the property is simply None. Handle DB insertion and sorting yourself (source_timestamp or server_timestamp or datetime.now(timezone.utc)).
Both timestamps are Optional[datetime] (UTC). Use .isoformat() to output the string ISO 8601 .
Memory Ownership
OpcUaDataValue Hold a resource handle. Anything returned ua.read_many from ua.read / ua.read_history / must be disposed of.
Best Practices:
# Single: with
with ua.read("ns=2;s=T1") as dv:
print(dv.value)
# Batch: Each one must be disposed of
dvs = ua.read_many(nodes)
for dv in dvs:
if dv is None: continue
with dv:
print(dv.value)
# or try/finally
try:
for dv in dvs:
if dv: print(dv.value)
finally:
for dv in dvs:
if dv: dv.close()
Failing to call ua.read_many will cause a memory leak (the memory usage will continue to increase with each poll).
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| DataValue | OpcUaDataValue | — | — | — | — |
| Value (→ Variant) | variant | — | — | — | — |
| None | value (→ Python values) | — | — | — | — |
| Status | status | — | — | — | — |
| IsGood | is_good | — | — | — | — |
| SourceTimestamp / ServerTimestamp | source_timestamp / server_timestamp | — | — | — | — |
Java / C++ / Rust / C: The four columns marked "read-only, unverified" in this entry — indicate that the information has not been verified, not that it does not exist.
In Python, this type is called OpcUaDataValue, Don't call DataValue — In the "C#" column of the table above, DataValue is the name of a C# class; if you copy it directly into Python, it will ImportError.
In C#, is dv.Value Variant Container; In Python, is dv.valuePython values that have already been decoded. In Python dv.variant, you need to write the container first, then retrieve .as_double the typed value—writing it directly dv.value.as_double is incorrect (dv.value it returns a float or str, not typed as_double).