Alarms and Conditions
Overview
OPC UA Part 9 defines a standard Method with a fixed NodeId on ConditionType / AlarmConditionType. The SDK wraps it as static methods on AlarmConditionApi — OpcUaSession is passed as the first parameter; every call returns an Enums.StatusCode, and failures throw no exception.
| Method | NodeId | Input Parameters |
|---|---|---|
| Acknowledge | i=9111 | (eventId: byte[], comment: String) |
| Confirm | i=9113 | (eventId, comment) |
| AddComment | i=9029 | (eventId, comment) |
| Enable | i=2803 | — |
| Disable | i=2805 | — |
| ConditionRefresh | i=3875 | (subscriptionId) |
| ConditionRefresh2 | i=12912 | (subscriptionId, monitoredItemId) |
| OneShotShelve | i=9211 | — |
| TimedShelve | i=9213 | (shelvingTimeMs) |
| Unshelve | i=9215 | — |
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| AlarmConditionApi.acknowledge(ua, conditionId, eventId, comment) | Alarm | Write | User Known |
| AlarmConditionApi.confirm(ua, conditionId, eventId, comment) | Alarm | Write | The issue has been resolved on-site |
| AlarmConditionApi.addComment(ua, conditionId, eventId, comment) | Alarm | Write | Add a note |
| AlarmConditionApi.enableCondition(ua, conditionId) | Alarm | Write | Enable |
| AlarmConditionApi.disableCondition(ua, conditionId) | Alarm | Write | Disable |
| AlarmConditionApi.conditionRefresh(ua, subscriptionId) | Alarm | Write | Reissue and Activation Alarm |
| AlarmConditionApi.conditionRefresh2(ua, subscriptionId, monitoredItemId) | Alarm | Write | Specify only MI |
| AlarmConditionApi.oneShotShelve(ua, shelvingStateId) | Alarm | Write | One-Time Blocking |
| AlarmConditionApi.timedShelve(ua, shelvingStateId, durationMs) | Alarm | Write | Temporary Mute |
| AlarmConditionApi.unshelve(ua, shelvingStateId) | Alarm | Write | Unblock |
Parameter type: ua = OpcUaSession; conditionId / shelvingStateId = String (NodeId); eventId = byte[]; comment = String; subscriptionId / monitoredItemId = int; durationMs = double.
Returns a value Enums.StatusCode; no exception is thrown on failure.
Code Example
import com.darra.opcua.*;
import javax.swing.JOptionPane;
try (OpcUaSession ua = new OpcUaSession("opc.tcp://server:4840")) {
ua.connect();
OpcUaSubscription sub = ua.createSubscription(500.0);
OpcUaEventSubscription ev = ua.subscribeEvents("i=2253");
ev.onEventArrived.add(args -> {
// An event snapshot has only 6 flat fields: severity / message / sourceName / timeFt / eventType / arrivedAtUtc
System.out.printf("[%d] %s: %s (%s)%n",
args.severity, args.sourceName, args.message, args.eventType);
// conditionId = Example of an alarm condition NodeId (String); eventId = Raw ByteString bytes for this event (byte[])
// Neither is included in the event snapshot; they are held by the higher-level alerting model—see the explanation below.
String conditionId = /* Provided by upper management */ null;
byte[] eventId = /* Provided by upper management */ null;
// a. Have the server resend the current active alert — applies to subscriptions, sends SubscriptionId
AlarmConditionApi.conditionRefresh(ua, sub.getSubscriptionId());
// b. The user clicks "Confirm" — conditionId and is retained eventId by the higher-level alarm model; see the explanation below
Enums.StatusCode rc = AlarmConditionApi.acknowledge(ua, conditionId, eventId, "操作员已知");
if (rc != Enums.StatusCode.Good)
JOptionPane.showMessageDialog(null, "Acknowledge 失败: " + rc);
// c. On-site processing
AlarmConditionApi.confirm(ua, conditionId, eventId, "现场已处理");
// d. Temporarily block for 30 seconds — shelvingStateId is a conditional ShelvingState child node
AlarmConditionApi.timedShelve(ua, conditionId + ".ShelvingState", 30_000.0);
});
}
OpcUaEventSubscription.EventArrivedEventArgs has only 6 final fields: severity (int) / message (String) / sourceName (String) / timeFt (long) / eventType (String) / arrivedAtUtc (Instant). It does not carry EventId, nor ConditionId.
The eventId (byte[]) and conditionId (String) for acknowledge / confirm / addComment must be held by the caller — either read the event's EventId field from the server, or maintain it in the upper-level alarm model.
Error Handling
AlarmConditionApi.* Fold the underlying exceptions into the return Enums.StatusCode value.Enums.StatusCode Only common codes are registered; unregistered server-side codes are merged Enums.StatusCode.fromCode(int) into Bad And the source code is not retained., Therefore, the following cases cannot be distinguished based on the return value.
| OPC UA Server-Side Code (Part 4 §7.34) | Meaning | SDK Return Value |
|---|---|---|
| Good | Success | Enums.StatusCode.Good |
| BadEventIdUnknown | EventId Mismatch | Enums.StatusCode.Bad (Source code not included) |
| BadConditionAlreadyEnabled | Enabled | Enums.StatusCode.Bad (Source code not included) |
| BadConditionAlreadyShelved | Blocked | Enums.StatusCode.Bad (Source code not included) |
The left-hand column of the table above is OPC UA Standard Server Status Codes, Since it is not an enumeration constant Enums.StatusCode of, you cannot simply copy it Enums.StatusCode.BadEventIdUnknown as shown here.
When precise differentiation is required, switch to calling the method directly ua.call(objectNodeId, methodNodeId, inputs) at the lower level and capture the read OpcUaException value ( ex.rawCode OpcUaException.rawCode retaining the server's original int code).
Best Practices
- Must Be Adjusted After Initial Subscription conditionRefresh
- First "acknowledge," then "confirm"—two steps
- TimedShelve unit ms—not seconds
- Do not synchronize ACKs in the listener; push them to the queue for background processing.
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | AlarmConditionApi.acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | AlarmConditionApi.confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| AddComment | add_comment | AlarmConditionApi.addComment | AddComment | add_comment | DarraUa_Alarm_AddComment |
| EnableCondition | enable_condition | AlarmConditionApi.enableCondition | EnableCondition | enable_condition | DarraUa_Alarm_EnableCondition |
| DisableCondition | disable_condition | AlarmConditionApi.disableCondition | DisableCondition | disable_condition | DarraUa_Alarm_DisableCondition |
| ConditionRefresh | condition_refresh | AlarmConditionApi.conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
| ConditionRefresh2 | condition_refresh2 | AlarmConditionApi.conditionRefresh2 | ConditionRefresh2 | condition_refresh2 | DarraUa_Alarm_ConditionRefresh2 |
| OneShotShelve | one_shot_shelve | AlarmConditionApi.oneShotShelve | OneShotShelve | one_shot_shelve | DarraUa_Alarm_OneShotShelve |
| TimedShelve | timed_shelve | AlarmConditionApi.timedShelve | TimedShelve | timed_shelve | DarraUa_Alarm_TimedShelve |
| Unshelve | unshelve | AlarmConditionApi.unshelve | Unshelve | unshelve | DarraUa_Alarm_Unshelve |
All ten C-side entries belong to the DarraUa_Alarm_* family, with DarraUa_SessionHandle as the first parameter: DarraUa_Alarm_Acknowledge / _Confirm / _AddComment / _EnableCondition / _DisableCondition / _ConditionRefresh / _ConditionRefresh2 / _OneShotShelve / _TimedShelve / _Unshelve. They return DarraUa_Status and throw nothing.