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 a C++ method with clear parameters.

MethodNodeIdInput Parameters
Acknowledgei=9111(event_id: vector<uint8_t>, comment: string)
Confirmi=9113(event_id, comment)
AddCommenti=9029(event_id, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(subscription_id)
ConditionRefresh2i=12912(subscription_id, monitored_item_id)
OneShotShelvei=9211—
TimedShelvei=9213(shelving_time_ms)
Unshelvei=9215—

API​

All 10 entries are under the namespace darra::opcua::alarmFree Functions(alarm_condition.hpp), the first parameter is passed as Session&, not Session nor a member method of some ua object.

FunctionCategoryReading and WritingNote
alarm::AcknowledgeAlarmWriteUser Known
alarm::ConfirmAlarmWriteThe issue has been resolved on-site
alarm::AddCommentAlarmWriteAdd a note
alarm::EnableConditionAlarmWriteEnable
alarm::DisableConditionAlarmWriteDisable
alarm::ConditionRefreshAlarmWriteResend all currently active alarms
alarm::ConditionRefresh2AlarmWriteSpecify only MonitoredItem
alarm::OneShotShelveAlarmWriteOne-Time Blocking
alarm::TimedShelveAlarmWriteTemporary Mute
alarm::UnshelveAlarmWriteUnblock
namespace darra::opcua::alarm {

Status Acknowledge (Session& s, std::string const& condition_id,
std::vector<uint8_t> const& event_id,
std::string const& comment = "");
Status Confirm (Session& s, std::string const& condition_id,
std::vector<uint8_t> const& event_id,
std::string const& comment = "");
Status AddComment (Session& s, std::string const& condition_id,
std::vector<uint8_t> const& event_id,
std::string const& comment); // comment No default value
Status EnableCondition (Session& s, std::string const& condition_id);
Status DisableCondition(Session& s, std::string const& condition_id);
Status ConditionRefresh (Session& s, uint32_t subscription_id);
Status ConditionRefresh2(Session& s, uint32_t subscription_id, uint32_t monitored_item_id);
Status OneShotShelve (Session& s, std::string const& shelving_state_id);
Status TimedShelve (Session& s, std::string const& shelving_state_id, double duration_ms);
Status Unshelve (Session& s, std::string const& shelving_state_id);
}
ParametersDefaultNote
s—Connected Session
condition_id—Alarm Condition Examples NodeId string;Returns an empty string Status::DarraInvalidArgument
event_id—The byte stream EventId of the event (std::vector<uint8_t>), preserved without loss 0x00-0xFF
comment""Comment:AddComment No default value, must be passed
subscription_id—Subscription ID from the server's perspective
monitored_item_id—MonitoredItem Id
shelving_state_id—The ShelvingState node that triggered the alarm NodeId;Returns an empty string Status::DarraInvalidArgument
duration_ms—Duration of suspension,milliseconds;< 0 or returns NaN Status::DarraInvalidArgument

Return Value: Without exception Status,No exceptions are thrown throughout the entire process.. In case of failure, the server's original status code is included in the Status response.

Current capability gap: event callbacks cannot supply EventId / ConditionId

Acknowledge / Confirm / AddComment all require event_id, but the current event subscription callback cannot supply it: EventArrivedEventArgs has only the five fields severity / message / source_name / time / event_type, and DarraUa_Event likewise has no EventId / ConditionId field; EventFilter's SelectClause is fixed at 4 (Severity / Message / SourceName / Time) and excludes EventId / ConditionId. To call these three methods, the business side must fetch the EventId byte stream from another channel itself.

Code Example​

#include <darra/opcua/client.hpp>
#include <darra/opcua/alarm_condition.hpp>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace darra::opcua;

Session s("opc.tcp://server:4840");
s.Connect();

auto sub = s.CreateSubscription(500.0);
auto ev = s.SubscribeEvents("i=2253", &sub); // ServerObject, Reusing sub-containers

ev.on_event() = [&](EventArrivedEventArgs const& e) {
std::cout << e.severity << " " << e.source_name << ": " << e.message << "\n";
// Note: There is no " EventId /" in "e" ConditionId; see the explanation of the competency gap above.
};

// event_id The byte stream is prepared by the business side itself.
std::vector<uint8_t> event_id = /* ... */;
std::string condition_id = "ns=2;s=Alarm.Pump1";

// a. Have the server resend the currently active alert (attached to Server Object i=2253)
Status r0 = alarm::ConditionRefresh(s, /*subscription_id=*/sub.Handle());

// b. The user clicks "Confirm"
Status r1 = alarm::Acknowledge(s, condition_id, event_id, "操作员已知");
if (r1 != Status::Good)
std::cerr << "Acknowledge 失败: " << Stack::StatusName(static_cast<uint32_t>(r1)) << "\n";

// c. On-site processing
alarm::Confirm(s, condition_id, event_id, "现场已处理");

// d. Temporarily mute for 30 seconds
alarm::TimedShelve(s, condition_id + ".ShelvingState", 30000.0);

Error Handling​

Two status codes generated by the SDK itself (enum class Status):

StatusMeaning
Status::GoodSuccess
Status::DarraInvalidArgumentcondition_id / shelving_state_id is an empty string, or TimedShelve is a negative duration_ms number / NaN

All other failures returnServer Raw Status Codes,Status Enumerations are not given individual names (for example, " EventId does not match," "condition enabled," "blocked," etc., all fall into this category). If you need a name, look it up Stack::StatusName(static_cast<uint32_t>(rc)); do not write enumerations like this Status::BadEventIdUnknown, which will not compile.

Best Practices​

  • Adjust once after the initial subscription ConditionRefresh to have the server resend the current activation alarm.
  • First "Acknowledge," then "Confirm"—two steps (some alarm types support only one of these).
  • TimedShelve is duration_msmilliseconds, not seconds
  • Event callbacks are executed synchronously on the Publish thread, while restart operations are offloaded to the queue for background processing.

Cross-Language Comparison​

C#PythonJavaC++RustC
AcknowledgeacknowledgeAlarmConditionApi.acknowledgealarm::AcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmAlarmConditionApi.confirmalarm::ConfirmconfirmDarraUa_Alarm_Confirm
AddCommentadd_commentAlarmConditionApi.addCommentalarm::AddCommentadd_commentDarraUa_Alarm_AddComment
EnableConditionenable_conditionAlarmConditionApi.enableConditionalarm::EnableConditionenable_conditionDarraUa_Alarm_EnableCondition
DisableConditiondisable_conditionAlarmConditionApi.disableConditionalarm::DisableConditiondisable_conditionDarraUa_Alarm_DisableCondition
ConditionRefreshcondition_refreshAlarmConditionApi.conditionRefreshalarm::ConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh
ConditionRefresh2condition_refresh2AlarmConditionApi.conditionRefresh2alarm::ConditionRefresh2condition_refresh2DarraUa_Alarm_ConditionRefresh2
OneShotShelveone_shot_shelveAlarmConditionApi.oneShotShelvealarm::OneShotShelveone_shot_shelveDarraUa_Alarm_OneShotShelve
TimedShelvetimed_shelveAlarmConditionApi.timedShelvealarm::TimedShelvetimed_shelveDarraUa_Alarm_TimedShelve
UnshelveunshelveAlarmConditionApi.unshelvealarm::UnshelveunshelveDarraUa_Alarm_Unshelve

In C++, these ten are free functions in a namespace darra::opcua::alarm, with the first parameter being; Session& in C#, they are extension methods DarraOpcUa of, and in Java, they are static methods AlarmConditionApi of (with the first parameter being OpcUaSession). The family name in C is DarraUa_Alarm_*, No DarraUa_Condition_*.

Next Step​