Skip to main content

DataChangeFilter

Overview​

OPC UA Part 4 §7.17 DataChangeFilter: The "trigger / deadband_type / deadband_value" trio.

API​

Type / FieldCategoryReading and WritingNote
DataChangeFilter { trigger, deadband_type, deadband_value }struct—Filter
sub.add_with_filter(node_id, attr, sampling_ms, filter, callback)MethodsWriteAdd a filter MI, return Result<u32, OpcUaError>

Related Structures:

pub enum DataChangeTrigger {
Status = 0, // Changes StatusCode Only
StatusValue = 1, // StatusCode or Value (default)
StatusValueTimestamp = 2, // Any change
}

pub enum DeadbandType {
None = 0, // No dead zone
Absolute = 1, // Absolute Dead Zone
Percent = 2, // Percentage (based on EURange)
}

sub.add_with_filter​

pub fn add_with_filter<F>(
&self,
node_id: &str,
attr: AttributeId,
sampling_ms: f64,
filter: DataChangeFilter,
callback: F,
) -> Result<u32, OpcUaError>
where F: FnMut(&DataChangeEventArgs) + Send + 'static
ParametersDefaultNote
node_id—Monitored NodeId
attrAttributeId::ValueMonitored Attributes
sampling_ms-1.0 (Subscribe)Server sampling interval. 0.0 = As soon as possible
filter(Required)DataChangeFilter Pass by value, No Option<&...>
callback(Required)Data Change Callback, Upload all at once during registration

Returns u32 MonitoredItem handle.

There are no mode / queue_size / discard_oldest parameters

add_with_filter; MonitoringMode only the 5 parameters listed in the table above are accepted. / queue_size / discard_oldest These are not exposed at this entry point; they are internal cache fields of MonitoredItemSpec and must be modified by calling modify_item / set_mode. When no filter is used, use add_node / add_node_with / add_many.

Code Example​

use darra_opcua::{
Session, AttributeId,
DataChangeFilter, DataChangeTrigger, DeadbandType,
};

let mut s = Session::new("opc.tcp://localhost:4840")?;
s.connect()?;

let sub = s.create_subscription(100.0)?;

// 1) Absolute Dead Zone 0.5
let f1 = DataChangeFilter {
trigger: DataChangeTrigger::StatusValue,
deadband_type: DeadbandType::Absolute,
deadband_value: 0.5,
};
let mi1 = sub.add_with_filter("ns=2;s=Temp", AttributeId::Value, 100.0, f1, |args| {
println!("[mi={}] {:?} ({})",
args.monitored_item_handle, args.value_string, args.status);
})?;

// 2) Percentage deadband: 2%
let f2 = DataChangeFilter {
deadband_type: DeadbandType::Percent,
deadband_value: 2.0,
..Default::default()
};
let mi2 = sub.add_with_filter("ns=2;s=Flow", AttributeId::Value, 100.0, f2, |args| {
println!("[mi={}] {:?}", args.monitored_item_handle, args.value_string);
})?;

// 3) Status Only
let f3 = DataChangeFilter {
trigger: DataChangeTrigger::Status,
..Default::default()
};
let mi3 = sub.add_with_filter("ns=2;s=Comm.Status", AttributeId::Value, 200.0, f3, |args| {
println!("[mi={}] status={}", args.monitored_item_handle, args.status);
})?;
The add_many callback is passed

SDK when add is called sub.on_data_changed(...); there is no post-registration. The callback is add_node / add_node_with / add_with_filter /The last parameter, Imported all at once. Requires all subscriptions to be consolidated, using s.events.on_any。

DataChangeEventArgs See the fields DataChange Callback: The callback returns monitored_item_handle / value_string / status, Noneclient_handle and value.value.

Implementation Notes​

  • Graceful SDK degradation when Stack is not supported:
    • Still configured at the lowest level: Registration add_node_with MI; the filter is not sent to the server; all data is reported in full.
    • Cache the filter locally filter_cache; it can still be restored when reconnecting or rebuilding.
    • Push a Diagnostic Warn event (StatusCode::BAD_NOT_SUPPORTED)
  • Percent Dead Zone Depends on the Target Node's EURange Property

Best Practices​

  • For analog values, use "Absolute" as the default, such as 0.5°C
  • Use "Percent" for wide-range signals
  • Digital signals do not require filtering
  • Don't make the dead zone too large; experience: 0.1-2%

Cross-Language Comparison​

C#PythonJavaC++RustC
DataChangeFilterDataChangeFilterDataChangeFilterDataChangeFilterDataChangeFilterDarraUa_DataChangeFilter

Next Step​