Alarms and Conditions (Acknowledge / Confirm / Refresh / Shelve)
Overview
OPC UA Part 9 (Alarms & Conditions) defines a standard Method with a fixed NodeId on ConditionType / AlarmConditionType. The SDK provides C# methods with clear parameter names (all of them members of DarraOpcUa), so the upper-level alarm panel does not have to assemble the Variant[] inputs by hand.
Fixed NodeId (Part 9 / Part 5 Standard Namespace 0):
| Method | NodeId | Input Parameters |
|---|---|---|
| Acknowledge | i=9111 | (eventId: ByteString, comment: LocalizedText) |
| Confirm | i=9113 | (eventId: ByteString, comment: LocalizedText) |
| AddComment | i=9029 | (eventId: ByteString, comment: LocalizedText) |
| Enable | i=2803 | None |
| Disable | i=2805 | None |
| ConditionRefresh | i=3875 | (subscriptionId: IntegerId) |
| ConditionRefresh2 | i=12912 | (subscriptionId, monitoredItemId) |
| OneShotShelve | i=9211 | None |
| TimedShelve | i=9213 | (shelvingTime: Duration ms) |
| Unshelve | i=9215 | None |
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.Acknowledge(conditionId, eventId, comment = "") | Alarm | Write | User Known |
| ua.Confirm(conditionId, eventId, comment = "") | Alarm | Write | The issue has been resolved on-site |
| ua.AddComment(conditionId, eventId, comment) | Alarm | Write | Add a note (comment Required, no default value) |
| ua.EnableCondition(conditionId) | Alarm | Write | Enable |
| ua.DisableCondition(conditionId) | Alarm | Write | Disable |
| ua.ConditionRefresh(subscriptionId) | Alarm | Write | Have the server resend all currently active alarms |
| ua.ConditionRefresh2(subscriptionId, monitoredItemId) | Alarm | Write | Replacement only MI for the specified item |
| ua.OneShotShelve(shelvingStateId) | Alarm | Write | One-time blocking (automatically restored upon next activation) |
| ua.TimedShelve(shelvingStateId, durationMs) | Alarm | Write | Temporarily mute for N milliseconds |
| ua.Unshelve(shelvingStateId) | Alarm | Write | Unblock |
Authentic Signatures (All are members DarraOpcUa of ):
public StatusCode Acknowledge(string conditionId, byte[] eventId, string comment = "");
public StatusCode Confirm(string conditionId, byte[] eventId, string comment = "");
public StatusCode AddComment(string conditionId, byte[] eventId, string comment);
public StatusCode EnableCondition(string conditionId);
public StatusCode DisableCondition(string conditionId);
public StatusCode ConditionRefresh(uint subscriptionId);
public StatusCode ConditionRefresh2(uint subscriptionId, uint monitoredItemId);
public StatusCode OneShotShelve(string shelvingStateId);
public StatusCode TimedShelve(string shelvingStateId, double durationMs);
public StatusCode Unshelve(string shelvingStateId);
Parameters:
| Parameters | Type | Note |
|---|---|---|
| conditionId | string | Example of an alarm condition NodeId: If the argument is null or an empty string, return "raw" ( 0x80AB0000 BadInvalidArgument) directly; do not trigger an alert. RPC |
| eventId | byte[] | The EventId (ByteString); null in this call also directly returns BadInvalidArgument |
| comment | string | LocalizedText Text; Acknowledge / Confirm Default: empty string, AddComment Required |
| subscriptionId / monitoredItemId | uint | Part 4 IntegerId |
| shelvingStateId | string | The "ShelvingState" child node on a conditional instance NodeId (typically "{conditionId}.ShelvingState") |
| durationMs | double | Duration of suspension, milliseconds; NaN or, if the number is negative, return "BadInvalidArgument" directly |
Returns StatusCode, Failure Do not throw exceptions (Exceptions thrown during the call OpcUaException are collapsed into the return StatusCode value), and the calling level handles the retry automatically.
Code Example
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://server:4840");
ua.Connect();
// 1) Subscribe to alert events (nodeId the default is Server=i=2253; I'm specifying it explicitly here)
using var sub = ua.CreateSubscription(500);
using var ev = ua.SubscribeEvents("i=2253", sub);
ev.EventArrived += (s, e) =>
{
// The callback returns only 5 fields: Severity / Message / SourceName / Time / EventType
// (Time is DateTime?; if the server does not provide a time, it is null)
Console.WriteLine($"[{e.Time:HH:mm:ss}] sev={e.Severity} {e.SourceName}: {e.Message} ({e.EventType})");
};
// a. Have the server resend all currently active alerts (when the dashboard is opened for the first time)
var rc = ua.ConditionRefresh(sub.SubscriptionId);
Console.WriteLine(rc == StatusCode.Good ? "ConditionRefresh OK" : $"ConditionRefresh 失败: {rc}");
// 2) Alarm Handling — conditionId / eventId / Retrieved from the server-side conditional instance model shelvingStateId by the upper layer,
// Currently, these three IDs are EventArrivedEventArgs not exposed.
static void HandleAlarm(DarraOpcUa ua, string conditionId, byte[] eventId, string shelvingStateId)
{
// b. The user clicks "Confirm"
var rc1 = ua.Acknowledge(conditionId, eventId, "操作员已知");
Console.WriteLine(rc1 == StatusCode.Good ? "已确认" : $"Acknowledge 失败: {rc1}");
// c. After completing the on-site processing, click "Confirm Completion"
ua.Confirm(conditionId, eventId, "现场已处理");
// d. Temporarily mute for 30 seconds (30_000 milliseconds)
ua.TimedShelve(shelvingStateId, 30_000.0);
// e. Add a comment (does not affect the Ack/Confirm status)
ua.AddComment(conditionId, eventId, "等待夜班巡检");
}
// 3) Enable/Disable an Entire Condition (During Maintenance)
ua.DisableCondition("ns=2;s=Tank.HighLevel");
// ... After maintenance
ua.EnableCondition("ns=2;s=Tank.HighLevel");
Acknowledge / Confirm / AddComment The required conditionId parameters are not eventId exposed through the event callback; instead, they are provided by the upper layer based on its own criteria, along with the instance NodeId and event ID.
Error Handling
The following are the names of status codes that the server may return for these methods (OPC UA as defined by the standard).
| StatusCode | Meaning |
|---|---|
| Good (0x00000000) | Success |
| BadEventIdUnknown | EventId Does not match the current condition |
| BadConditionAlreadyEnabled | Enabled |
| BadConditionAlreadyDisabled | Disabled |
| BadConditionAlreadyShelved | Blocked |
| BadConditionNotShelved | Not shelved; cannot unshelve |
StatusCode in C#'s enumeration.C#'s enumeration is defined only StatusCode for common codes such as, etc BadHistoryOperationUnsupported .; the codes listed in the table above are specific to Part 9.None The corresponding enumeration member. When returned by the server, it isPass-through as-is The value StatusCode of can only be greater than the value of:
// Fill in the gaps in the enumeration using `uint` constants
const uint SC_BadInvalidArgument = 0x80AB0000u;
if ((uint)rc == SC_BadInvalidArgument) { /* The input parameter was null and was blocked locally; it wasn't sent. RPC */ }
The values of these two raw codes: BadInvalidArgument = 0x80AB0000 (conditionId / eventId / returns immediately shelvingStateId if empty; does not send RPC),BadInternalError = 0x80020000.
Best Practices
- Must Be Adjusted After Initial Subscription
ConditionRefresh— Otherwise, you'll only receive new events and won't see old, active alarms. AcknowledgeAfter thatConfirm— Two-step process; do not skip the "Confirm" step. Some condition types support only one of the two steps.- The unit for TimedShelve is milliseconds, and the formal parameters are
double— 30-second limit30_000.0; the server is typically subject to this constraintMaxTimeShelved, and exceeding it will result in a responseBadShelvingTimeOutOfRange - The locale for comments is set to
"en"— Always specify"en"as the locale when sending; Chinese text will be labeled as "en" locale; the text itself is transmitted in UTF-8. eventIdPress ISO-8859-1 to continue —byte[]Mapped byte-by-byte to the string ISO-8859-1 for transmission; no UTF-8 multibyte expansion is performed; servers that strictly validate argument types may reject the input.- Do not synchronize Ack in
EventArrived. — Use a pushConcurrentQueuequeue; processed by a background thread
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| ConditionRefresh | condition_refresh | conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
| TimedShelve | timed_shelve | timedShelve | TimedShelve | timed_shelve | DarraUa_Alarm_TimedShelve |