Skip to main content

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):

MethodNodeIdInput Parameters
Acknowledgei=9111(eventId: ByteString, comment: LocalizedText)
Confirmi=9113(eventId: ByteString, comment: LocalizedText)
AddCommenti=9029(eventId: ByteString, comment: LocalizedText)
Enablei=2803None
Disablei=2805None
ConditionRefreshi=3875(subscriptionId: IntegerId)
ConditionRefresh2i=12912(subscriptionId, monitoredItemId)
OneShotShelvei=9211None
TimedShelvei=9213(shelvingTime: Duration ms)
Unshelvei=9215None

API​

MethodsCategoryReading and WritingNote
ua.Acknowledge(conditionId, eventId, comment = "")AlarmWriteUser Known
ua.Confirm(conditionId, eventId, comment = "")AlarmWriteThe issue has been resolved on-site
ua.AddComment(conditionId, eventId, comment)AlarmWriteAdd a note (comment Required, no default value)
ua.EnableCondition(conditionId)AlarmWriteEnable
ua.DisableCondition(conditionId)AlarmWriteDisable
ua.ConditionRefresh(subscriptionId)AlarmWriteHave the server resend all currently active alarms
ua.ConditionRefresh2(subscriptionId, monitoredItemId)AlarmWriteReplacement only MI for the specified item
ua.OneShotShelve(shelvingStateId)AlarmWriteOne-time blocking (automatically restored upon next activation)
ua.TimedShelve(shelvingStateId, durationMs)AlarmWriteTemporarily mute for N milliseconds
ua.Unshelve(shelvingStateId)AlarmWriteUnblock

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:

ParametersTypeNote
conditionIdstringExample 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
eventIdbyte[]The EventId (ByteString); null in this call also directly returns BadInvalidArgument
commentstringLocalizedText Text; Acknowledge / Confirm Default: empty string, AddComment Required
subscriptionId / monitoredItemIduintPart 4 IntegerId
shelvingStateIdstringThe "ShelvingState" child node on a conditional instance NodeId (typically "{conditionId}.ShelvingState")
durationMsdoubleDuration 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");
note

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).

StatusCodeMeaning
Good (0x00000000)Success
BadEventIdUnknownEventId Does not match the current condition
BadConditionAlreadyEnabledEnabled
BadConditionAlreadyDisabledDisabled
BadConditionAlreadyShelvedBlocked
BadConditionNotShelvedNot shelved; cannot unshelve
These names are not included 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.
  • Acknowledge After that Confirm — 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 limit 30_000.0; the server is typically subject to this constraint MaxTimeShelved, and exceeding it will result in a response BadShelvingTimeOutOfRange
  • 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.
  • eventId Press 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 push ConcurrentQueue queue; processed by a background thread

Cross-Language Comparison​

C#PythonJavaC++RustC
AcknowledgeacknowledgeacknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmconfirmConfirmconfirmDarraUa_Alarm_Confirm
ConditionRefreshcondition_refreshconditionRefreshConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh
TimedShelvetimed_shelvetimedShelveTimedShelvetimed_shelveDarraUa_Alarm_TimedShelve

Next Step​