SetMonitoringMode
Each MonitoredItem has 3 monitoring modes:
pub enum MonitoringMode {
Disabled = 0,
Sampling = 1,
Reporting = 2,
}
| Mode | Server-Side Sampling | Server-Side Push | Uses |
|---|---|---|---|
| Disabled (0) | × | × | Fully stopped (neither sampling nor push) |
| Sampling (1) | ✓ | × | Sample but Do Not Push (Log History / Dead Zone Calculation) |
| Reporting (2, Default) | ✓ | ✓ | Operating Normally |
Prerequisite Reading
- To cancel your entire subscription (rather than individual issues MI), see below
set_publishing_enabled. - To modify the sampling parameters, see Modify.
Batch Cut
pub fn Subscription::set_monitoring_mode(
&self,
mode: MonitoringMode,
mi_handles: &[u32],
) -> Result<Vec<StatusCode>, OpcUaError>;
use darra_opcua::MonitoringMode;
// Temporarily suspend all data collection (e.g., during equipment maintenance)
let all_handles: Vec<u32> = vec![h1, h2, h3, h4];
let statuses = sub.set_monitoring_mode(MonitoringMode::Disabled, &all_handles)?;
for (h, st) in all_handles.iter().zip(statuses.iter()) {
if !st.is_good() { eprintln!("MI {} stop failed: {}", h, st); }
}
Single MI Cut
pub fn Subscription::set_mode(
&self,
monitored_item_handle: u32,
mode: MonitoringMode,
) -> Result<StatusCode, OpcUaError>;
sub.set_mode(h, MonitoringMode::Disabled)?; // Pause a certain MI
sub.set_mode(h, MonitoringMode::Reporting)?; // Restore
Enable or Disable the Entire Subscription (set_publishing_enabled)
If you want to cancel the entire subscription (rather than individual issues MI), use set_publishing_enabled:
pub fn Subscription::set_publishing_enabled(&self, enabled: bool) -> StatusCode;
sub.set_publishing_enabled(false); // Pause all subscription notifications
// ... During maintenance ...
sub.set_publishing_enabled(true); // Restore
Comparison of Three Particle Sizes
| Particle size | API | Applicable |
|---|---|---|
| Subscribe to the entire series | sub.set_publishing_enabled(b) | Temporary Service Suspension (Maintenance) |
| A batch of MI | sub.set_monitoring_mode(mode, &handles) | Some modules are down |
| Single MI | sub.set_mode(handle, mode) | Precise Control |
| Delete Completely | sub.remove(handle) / drop sub | I don't want it anymore—ever. |
Error
| StatusCode | Reason |
|---|---|
StatusCode::BAD_MONITORED_ITEM_ID_INVALID | The handle has been removed / is no longer valid |
StatusCode::BAD_SUBSCRIPTION_ID_INVALID | Subscriptions have been cleared |
StatusCode::BAD_TOO_MANY_OPERATIONS | Too many items in a single request |
Note
DisabledThe pattern still consumes server resources (the subscription entries themselves), but it does not sample or push data.- To completely free up space, use
sub.remove(h)to delete this MI - Mode switching is a
&selfworkaround (internal process RPC; does not change local settings).