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 Rust method with clear parameters.

MethodNodeIdInput Parameters
Acknowledgei=9111(event_id: &[u8], comment: &str)
Confirmi=9113(event_id, comment)
AddCommenti=9029(event_id, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(sub_id)
ConditionRefresh2i=12912(sub_id, mi_id)
OneShotShelvei=9211—
TimedShelvei=9213(shelving_time_ms)
Unshelvei=9215—

API​

MethodsCategoryReading and WritingNote
ua.acknowledge(condition_id, event_id, comment)AlarmWriteUser Known
ua.confirm(condition_id, event_id, comment)AlarmWriteThe issue has been resolved on-site.
ua.add_comment(condition_id, event_id, comment)AlarmWriteAdd a note
ua.enable_condition(condition_id)AlarmWriteEnable
ua.disable_condition(condition_id)AlarmWriteDisable
ua.condition_refresh(sub_id)AlarmWriteReissue and Activation Alarm
ua.condition_refresh2(sub_id, mi_id)AlarmWriteSpecify only MI
ua.one_shot_shelve(shelving_state_id)AlarmWriteOne-Time Blocking
ua.timed_shelve(shelving_state_id, ms)AlarmWriteTemporary Block
ua.unshelve(shelving_state_id)AlarmWriteUnblock

Returns the bare StatusCode (No Result), none of the 10 methods return an Err,Cannot be added ?, Don't panic when you fail; business-level success or failure is determined StatusCode by and rc.is_bad() evaluated using rc.is_good() /.

Code Example​

use darra_opcua::{Session, well_known_nodes};
use std::sync::{mpsc, Arc};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ua = Session::new("opc.tcp://server:4840")?;
ua.connect()?;

// Event subscriptions are attached to the session (not to the subscription); callbacks are passed in once during registration,
// No additions or replacements are allowed afterward — EventSubscription only monitored_item_handle(). is exposed.
let sub = Arc::new(ua.create_subscription(500.0)?);
let sub_id = sub.subscription_id();

let (tx, rx) = mpsc::channel();
let _ev = ua.subscribe_events(
Some(well_known_nodes::SERVER), // "i=2253"
Some(sub.clone()),
move |args| {
// EventArrivedEventArgs There are only 5 tiled fields: severity / message /
// source_name / time / event_type. EventId / ConditionId the original
// ByteString This is not exposed at this time; the business side must map it on its own.
let _ = tx.send((args.severity, args.source_name.clone().unwrap_or_default()));
},
)?;

for (sev, src) in rx {
let condition_id = format!("ns=2;s=Alarm.{}", src); // The business side's own mapping
let event_id: &[u8] = b""; // Not currently exposed; see above.

// a. Have the server resend the current activation alert (returns "none" StatusCode; not allowed `?`)
let rc = ua.condition_refresh(sub_id);
if !rc.is_good() { eprintln!("refresh 失败: {:?} (sev={})", rc, sev); }

// b. The user clicks "Confirm" — the second parameter is &[u8]
let rc = ua.acknowledge(&condition_id, event_id, "操作员已知");
if !rc.is_good() { eprintln!("Acknowledge 失败: {:?}", rc); }

// c. On-site processing
let _ = ua.confirm(&condition_id, event_id, "现场已处理");

// d. Temporarily block for 30 seconds (TimedShelve input parameter is in milliseconds f64 )
let _ = ua.timed_shelve(&format!("{}.ShelvingState", condition_id), 30_000.0);
}
Ok(())
}

Error Handling​

All 10 methods return rc.is_bad() StatusCode and do not return Err. The following failure scenarios have dedicated status codes at the protocol level, butNot in the set of SDK constants StatusCode, Do not write it in a way that can be copied verbatim StatusCode::Xxx:

Failure ScenariosMeaning of the Protocol Layer
SuccessStatus Code 0
EventId Mismatchacknowledge / confirm that the provided event_id does not match the server's records
The condition has been enabledenable_condition encounters a Condition that is already enabled
Conditions have been hiddentimed_shelve / one_shot_shelve encounters a condition that has already been shelved

Diagnostic Methods:

if rc.is_bad() {
eprintln!("raw = 0x{:08X}, name = {}", rc.raw(), darra_opcua::status_name(rc));
}

StatusCode It is a newtype pub struct StatusCode(pub u32), a constantAll Caps (StatusCode::GOOD / StatusCode::BAD / StatusCode::BAD_TIMEOUT ...), use is_good() / is_bad() / for evaluation is_uncertain(), and use for retrieving the source code raw().

Best Practices​

  • Be sure to set condition_refresh after the first subscription.
  • First "acknowledge," then "confirm"—two steps
  • The unit for TimedShelve is milliseconds (f64), not seconds.
  • acknowledge / confirm / add_comment The formal parameter event_id is &[u8], not &String
  • Event callbacks are FnMut(&EventArrivedEventArgs) + Send + 'static, cannot obtain a reference Session to, Do not send an acknowledgment synchronously in the callback — Use mpsc to push the queue; the outer thread calls it while holding the Session

Cross-Language Comparison​

C#PythonJavaC++RustC
AcknowledgeacknowledgeacknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmconfirmConfirmconfirmDarraUa_Alarm_Confirm
ConditionRefreshcondition_refreshconditionRefreshConditionRefreshcondition_refreshDarraUa_Alarm_ConditionRefresh

C's family name is DarraUa_Alarm_*, not; DarraUa_Condition_* the entry point is DarraUa_Alarm_ConditionRefresh / DarraUa_Alarm_ConditionRefresh2, and the filter class is DarraUa_Alarm_OneShotShelve / _TimedShelve / _Unshelve.

Next Step​