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.
| Method | NodeId | Input Parameters |
|---|---|---|
| Acknowledge | i=9111 | (event_id: vector<uint8_t>, comment: string) |
| Confirm | i=9113 | (event_id, comment) |
| AddComment | i=9029 | (event_id, comment) |
| Enable | i=2803 | — |
| Disable | i=2805 | — |
| ConditionRefresh | i=3875 | (subscription_id) |
| ConditionRefresh2 | i=12912 | (subscription_id, monitored_item_id) |
| OneShotShelve | i=9211 | — |
| TimedShelve | i=9213 | (shelving_time_ms) |
| Unshelve | i=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.
| Function | Category | Reading and Writing | Note |
|---|---|---|---|
| alarm::Acknowledge | Alarm | Write | User Known |
| alarm::Confirm | Alarm | Write | The issue has been resolved on-site |
| alarm::AddComment | Alarm | Write | Add a note |
| alarm::EnableCondition | Alarm | Write | Enable |
| alarm::DisableCondition | Alarm | Write | Disable |
| alarm::ConditionRefresh | Alarm | Write | Resend all currently active alarms |
| alarm::ConditionRefresh2 | Alarm | Write | Specify only MonitoredItem |
| alarm::OneShotShelve | Alarm | Write | One-Time Blocking |
| alarm::TimedShelve | Alarm | Write | Temporary Mute |
| alarm::Unshelve | Alarm | Write | Unblock |
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);
}
| Parameters | Default | Note |
|---|---|---|
| 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.
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):
| Status | Meaning |
|---|---|
Status::Good | Success |
Status::DarraInvalidArgument | condition_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
ConditionRefreshto have the server resend the current activation alarm. - First "Acknowledge," then "Confirm"—two steps (some alarm types support only one of these).
TimedShelveisduration_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# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | AlarmConditionApi.acknowledge | alarm::Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | AlarmConditionApi.confirm | alarm::Confirm | confirm | DarraUa_Alarm_Confirm |
| AddComment | add_comment | AlarmConditionApi.addComment | alarm::AddComment | add_comment | DarraUa_Alarm_AddComment |
| EnableCondition | enable_condition | AlarmConditionApi.enableCondition | alarm::EnableCondition | enable_condition | DarraUa_Alarm_EnableCondition |
| DisableCondition | disable_condition | AlarmConditionApi.disableCondition | alarm::DisableCondition | disable_condition | DarraUa_Alarm_DisableCondition |
| ConditionRefresh | condition_refresh | AlarmConditionApi.conditionRefresh | alarm::ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
| ConditionRefresh2 | condition_refresh2 | AlarmConditionApi.conditionRefresh2 | alarm::ConditionRefresh2 | condition_refresh2 | DarraUa_Alarm_ConditionRefresh2 |
| OneShotShelve | one_shot_shelve | AlarmConditionApi.oneShotShelve | alarm::OneShotShelve | one_shot_shelve | DarraUa_Alarm_OneShotShelve |
| TimedShelve | timed_shelve | AlarmConditionApi.timedShelve | alarm::TimedShelve | timed_shelve | DarraUa_Alarm_TimedShelve |
| Unshelve | unshelve | AlarmConditionApi.unshelve | alarm::Unshelve | unshelve | DarraUa_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_*.