UpdateHistory
Write data to the server's historical storage (rather than the "real-time values" from the current read/write operations):
Writing to the history modifies the archived data on the server.The client does not perform any permission checks and does not generate any audit logs. —— Whether a call succeeds and whether it is possible to determine "who made the change" afterward depends entirely on the server. For more details, see "Permissions and Auditing."
Signature
public IReadOnlyList<StatusCode> UpdateHistory(
string nodeId,
HistoryUpdateType updateType,
IReadOnlyList<DataValue> values);
| Parameters | Type | Default | Note |
|---|---|---|---|
| nodeId | string | — | Target; NodeId null / empty string exception ArgumentNullException |
| updateType | HistoryUpdateType | — | Operation Types—see the table below |
| values | IReadOnlyList<DataValue> | — | List DataValue of elements to be written; throws null ArgumentNullException; throws if an element is null or has already been Dispose() released ArgumentException |
Returns a list IReadOnlyList<StatusCode> in the same order values as the input, where each item represents the write status of that entry.
values If the list is empty, it returns an empty list directly without sending a request to the server.
HistoryUpdateType
| Value | Value | Meaning |
|---|---|---|
Insert | 1 | Insert a new value; if it already exists, the operation fails. |
Replace | 2 | Replace the existing one; if it doesn't exist, the operation fails. |
Update | 3 | "Insert" or "Replace"—either works |
Remove | 4 | Delete by time, using only the SourceTimestamp for each entry; the Value is ignored. |
Usage
DataValue No external constructors are provided — values can values only be obtained from the return value API of the read class
(e.g., ReadHistory / ReadHistoryModified), we can't make them ourselves.
Copy the history of one node to another node
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
var startUtc = DateTime.UtcNow.AddDays(-1);
var endUtc = DateTime.UtcNow;
var src = ua.ReadHistory("ns=2;s=Temperature", startUtc, endUtc, maxValues: 1000);
try
{
var results = ua.UpdateHistory("ns=2;s=TemperatureCopy",
HistoryUpdateType.Update, src);
for (int i = 0; i < results.Count; i++)
Console.WriteLine($" [{i}] {results[i]}");
}
finally
{
foreach (var dv in src) dv.Dispose();
}
Insert only (do not overwrite existing entries)
ua.UpdateHistory("ns=2;s=Temperature", HistoryUpdateType.Insert, src);
Delete by Date
ua.UpdateHistory("ns=2;s=Temperature", HistoryUpdateType.Remove, src);
Remove Currently, the server only looks at the DataValue of each message SourceTimestamp;Value the is ignored.
Notes
Add a note to the history; this feature is currently unavailable SDK.
Permissions and Auditing
- There is no permission verification on the client side.: Can we have the server handle this? When
UpdateHistorythe server refuses, it throws an exception.OpcUaException,ex.StatusCodewhich is the raw code returned by the server. - Servers are typically
AccessLevelorganized by node HistoryWrite Position (0x08) Whether to grant access is determined based on the user's identity. - SDK No record of operator, time of operation, or reason...nor will the changes be reported to any audit channel. Compliance audits can only be implemented by the server itself.
- After making changes, if you want to see "what was changed," you can only use ReadHistoryModified —— But it can't get it either "Who made the change / When was it made / Previous value."
Exception
| Exception | Trigger Conditions |
|---|---|
ArgumentNullException | nodeId is null / an empty string; or values is null |
ArgumentException | values[i] is null, or it has DataValue already been released Dispose() |
OpcUaException | The call failed entirely;ex.StatusCode this is the error code returned by the server as-is. |
Partial success: Individual results are returned only Good when the overall call succeeds StatusCode; if the overall call fails, an exception is thrown,
and individual results cannot be retrieved.
Implementation Constraints
- None
CancellationToken—— Only ReadHistoryStreamAsync Include the cancellation token. - Synchronous Blocking, No variants
Async. - Session-level failures are not automatically retried。
- There are no other
HistoryUpdateTypeways to write history (no annotations, no structured updates).
Codes the server may return
The SDK does not alter the server's status codes. The following are just the codes you are most likely to see; this does not mean they are intentionally SDK returned:
| Error Code | Common Meanings |
|---|---|
BadHistoryOperationUnsupported | The server does not support writing to the history. |
BadUserAccessDenied | The server determined that the user lacks permission. |
BadNotWritable | Node is not writable |
BadNotSupported | This operation type is not supported on the server. |