Skip to main content

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.

MethodNodeIdInput Parameters
Acknowledgei=9111(eventId: byte[], comment: String)
Confirmi=9113(eventId, comment)
AddCommenti=9029(eventId, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(subscriptionId)
ConditionRefresh2i=12912(subscriptionId, monitoredItemId)
OneShotShelvei=9211—
TimedShelvei=9213(shelvingTimeMs)
Unshelvei=9215—

API​

MethodsCategoryReading and WritingNote
AlarmConditionApi.acknowledge(ua, conditionId, eventId, comment)AlarmWriteUser Known
AlarmConditionApi.confirm(ua, conditionId, eventId, comment)AlarmWriteThe issue has been resolved on-site
AlarmConditionApi.addComment(ua, conditionId, eventId, comment)AlarmWriteAdd a note
AlarmConditionApi.enableCondition(ua, conditionId)AlarmWriteEnable
AlarmConditionApi.disableCondition(ua, conditionId)AlarmWriteDisable
AlarmConditionApi.conditionRefresh(ua, subscriptionId)AlarmWriteReissue and Activation Alarm
AlarmConditionApi.conditionRefresh2(ua, subscriptionId, monitoredItemId)AlarmWriteSpecify only MI
AlarmConditionApi.oneShotShelve(ua, shelvingStateId)AlarmWriteOne-Time Blocking
AlarmConditionApi.timedShelve(ua, shelvingStateId, durationMs)AlarmWriteTemporary Mute
AlarmConditionApi.unshelve(ua, shelvingStateId)AlarmWriteUnblock

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);
});
}
The event snapshot does not contain EventId / ConditionId

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)MeaningSDK Return Value
GoodSuccessEnums.StatusCode.Good
BadEventIdUnknownEventId MismatchEnums.StatusCode.Bad (Source code not included)
BadConditionAlreadyEnabledEnabledEnums.StatusCode.Bad (Source code not included)
BadConditionAlreadyShelvedBlockedEnums.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#PythonJavaC++RustC
AcknowledgeacknowledgeAlarmConditionApi.acknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmAlarmConditionApi.confirmConfirmconfirmDarraUa_Alarm_Confirm
AddCommentadd_commentAlarmConditionApi.addCommentAddCommentadd_commentDarraUa_Alarm_AddComment
EnableConditionenable_conditionAlarmConditionApi.enableConditionEnableConditionenable_conditionDarraUa_Alarm_EnableCondition
DisableConditiondisable_conditionAlarmConditionApi.disableConditionDisableConditiondisable_conditionDarraUa_Alarm_DisableCondition
ConditionRefreshcondition_refreshAlarmConditionApi.conditionRefreshConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh
ConditionRefresh2condition_refresh2AlarmConditionApi.conditionRefresh2ConditionRefresh2condition_refresh2DarraUa_Alarm_ConditionRefresh2
OneShotShelveone_shot_shelveAlarmConditionApi.oneShotShelveOneShotShelveone_shot_shelveDarraUa_Alarm_OneShotShelve
TimedShelvetimed_shelveAlarmConditionApi.timedShelveTimedShelvetimed_shelveDarraUa_Alarm_TimedShelve
UnshelveunshelveAlarmConditionApi.unshelveUnshelveunshelveDarraUa_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.

Next Step​