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.
| Method | NodeId | Input Parameters |
|---|---|---|
| Acknowledge | i=9111 | (event_id: &[u8], comment: &str) |
| Confirm | i=9113 | (event_id, comment) |
| AddComment | i=9029 | (event_id, comment) |
| Enable | i=2803 | — |
| Disable | i=2805 | — |
| ConditionRefresh | i=3875 | (sub_id) |
| ConditionRefresh2 | i=12912 | (sub_id, mi_id) |
| OneShotShelve | i=9211 | — |
| TimedShelve | i=9213 | (shelving_time_ms) |
| Unshelve | i=9215 | — |
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.acknowledge(condition_id, event_id, comment) | Alarm | Write | User Known |
| ua.confirm(condition_id, event_id, comment) | Alarm | Write | The issue has been resolved on-site. |
| ua.add_comment(condition_id, event_id, comment) | Alarm | Write | Add a note |
| ua.enable_condition(condition_id) | Alarm | Write | Enable |
| ua.disable_condition(condition_id) | Alarm | Write | Disable |
| ua.condition_refresh(sub_id) | Alarm | Write | Reissue and Activation Alarm |
| ua.condition_refresh2(sub_id, mi_id) | Alarm | Write | Specify only MI |
| ua.one_shot_shelve(shelving_state_id) | Alarm | Write | One-Time Blocking |
| ua.timed_shelve(shelving_state_id, ms) | Alarm | Write | Temporary Block |
| ua.unshelve(shelving_state_id) | Alarm | Write | Unblock |
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 Scenarios | Meaning of the Protocol Layer |
|---|---|
| Success | Status Code 0 |
| EventId Mismatch | acknowledge / confirm that the provided event_id does not match the server's records |
| The condition has been enabled | enable_condition encounters a Condition that is already enabled |
| Conditions have been hidden | timed_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_commentThe formal parameterevent_idis&[u8], not&String- Event callbacks are
FnMut(&EventArrivedEventArgs) + Send + 'static, cannot obtain a referenceSessionto, 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# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| ConditionRefresh | condition_refresh | conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_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.