Skip to main content

Monitor

Struct Monitor 

Source
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

Source

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();
Source

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()?;
Source

pub fn is_running(&self) -> bool

Check if the monitor is currently running

§Returns

true if the monitor is active and receiving updates, false otherwise.

§Example
monitor.start();
assert!(monitor.is_running());
Source

pub fn has_update(&self) -> bool

Check if there are updates available without blocking

§Returns

true if updates are available, false otherwise.

§Example
if monitor.has_update() {
    let value = monitor.try_get_update()?;
    println!("Update available: {:?}", value);
}
Source

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),
}
Source

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");
}
Source

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 available
  • Ok(None) if the queue is empty
  • Err(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;
        }
    }
}
Source

pub fn is_connected(&self) -> bool

Check if the monitor is connected to the PV

§Returns

true if connected to the PV, false otherwise.

§Example
if monitor.is_connected() {
    println!("Connected to PV");
} else {
    println!("Not connected");
}
Source

pub fn name(&self) -> String

Get the name of the PV being monitored

§Returns

The PV name as a string.

§Example
println!("Monitoring PV: {}", monitor.name());

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.