pub struct Monitor { /* private fields */ }Expand description
RPC (Remote Procedure Call) builder for EPICS servers
Provides a fluent interface for building and executing RPC calls. RPC allows calling server-side functions with typed arguments.
§Example
let mut rpc = ctx.rpc("my:service").expect("RPC creation failed");
// Add arguments of different types
rpc.arg_string("command", "initialize");
rpc.arg_double("threshold", 3.14);
rpc.arg_int32("count", 100);
rpc.arg_bool("enabled", true);
// Execute synchronously
let result = rpc.execute(5.0).expect("RPC execution failed");
println!("RPC result: {}", result);Monitor represents a subscription to value changes for a process variable.
Monitors allow you to receive notifications when a PV’s value changes, providing an efficient way to track real-time updates without polling.
§Example
use pvxs_sys::Context;
let mut ctx = Context::from_env()?;
let mut monitor = ctx.monitor("MY:PV")?;
monitor.start();
// Wait for updates
loop {
if let Some(value) = monitor.try_get_update()? {
println!("PV updated: {}", value);
}
std::thread::sleep(std::time::Duration::from_millis(100));
}Implementations§
Source§impl Monitor
impl Monitor
Sourcepub fn start(&mut self) -> Result<()>
pub fn start(&mut self) -> Result<()>
Start monitoring for value changes
This begins the subscription and the monitor will start receiving updates.
§Example
monitor.start();Sourcepub fn stop(&mut self) -> Result<()>
pub fn stop(&mut self) -> Result<()>
Stop monitoring for value changes
This ends the subscription and no more updates will be received.
§Example
monitor.stop()?;Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Sourcepub fn has_update(&self) -> bool
pub fn has_update(&self) -> bool
Sourcepub fn get_update(&mut self, timeout: f64) -> Result<Value>
pub fn get_update(&mut self, timeout: f64) -> Result<Value>
Get the next update, blocking with a timeout
This method will wait for an update to arrive, up to the specified timeout.
§Arguments
timeout- Maximum time to wait in seconds
§Returns
A Value if an update was received within the timeout, or an error.
§Example
match monitor.get_update(5.0) {
Ok(value) => println!("Update received: {}", value),
Err(e) => println!("No update within 5 seconds: {}", e),
}Sourcepub fn try_get_update(&mut self) -> Result<Option<Value>>
pub fn try_get_update(&mut self) -> Result<Option<Value>>
Try to get the next update without blocking
This method returns immediately, either with an update if one is available,
or None if no update is ready.
§Returns
Some(Value) if an update is available, None otherwise.
§Example
if let Some(value) = monitor.try_get_update()? {
println!("Update: {}", value);
} else {
println!("No update available");
}Sourcepub fn pop(&mut self) -> Result<Option<Value>, MonitorEvent>
pub fn pop(&mut self) -> Result<Option<Value>, MonitorEvent>
Pop the next update from the subscription queue (PVXS-style)
This follows the PVXS pattern where pop() returns a Value if available,
or returns Err with MonitorEvent for connection/disconnection events.
§Returns
Ok(Some(Value))if an update is availableOk(None)if the queue is emptyErr(MonitorEvent::Connected)if connection exception (when connect_exception(true), i.e. maskConnected(false))Err(MonitorEvent::Disconnected)if disconnection exception (when disconnect_exception(true), i.e. maskDisconnected(false))Err(MonitorEvent::Finished)if finished exception (when disconnect_exception(true), i.e. maskDisconnected(false))
Note: The mask configuration controls whether exceptions are suppressed or thrown:
- connect_exception(true) -> maskConnected(false) -> exceptions are thrown as MonitorEvent::Connected
- connect_exception(false) -> maskConnected(true) -> exceptions are suppressed/masked out
§Example
loop {
match monitor.pop() {
Ok(Some(value)) => println!("Update: {}", value),
Ok(None) => break, // Queue empty
Err(e) if e.to_string().contains("connected") => {
println!("Connection event");
break;
}
Err(e) => {
println!("Other error: {}", e);
break;
}
}
}