Skip to main content

SetMonitoringMode

Each MonitoredItem has 3 monitoring modes:

pub enum MonitoringMode {
Disabled = 0,
Sampling = 1,
Reporting = 2,
}
ModeServer-Side SamplingServer-Side PushUses
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 sizeAPIApplicable
Subscribe to the entire seriessub.set_publishing_enabled(b)Temporary Service Suspension (Maintenance)
A batch of MIsub.set_monitoring_mode(mode, &handles)Some modules are down
Single MIsub.set_mode(handle, mode)Precise Control
Delete Completelysub.remove(handle) / drop subI don't want it anymore—ever.

Error​

StatusCodeReason
StatusCode::BAD_MONITORED_ITEM_ID_INVALIDThe handle has been removed / is no longer valid
StatusCode::BAD_SUBSCRIPTION_ID_INVALIDSubscriptions have been cleared
StatusCode::BAD_TOO_MANY_OPERATIONSToo many items in a single request

Note​

  • Disabled The 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 &self workaround (internal process RPC; does not change local settings).

Next Step​