Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

A PVXS client context for performing PVAccess operations

The Context is the main entry point for interacting with PVAccess. It manages network connections and provides methods for GET, PUT, and other PV operations.

§Thread Safety

Context is Send and Sync, and can be safely shared between threads.

Implementations§

Source§

impl Context

Source

pub fn from_env() -> Result<Self>

Create a new Context configured from environment variables

Reads configuration from EPICS_PVA_* environment variables:

  • EPICS_PVA_ADDR_LIST: List of server addresses
  • EPICS_PVA_AUTO_ADDR_LIST: Auto-discover servers (default: YES)
  • EPICS_PVA_BROADCAST_PORT: UDP broadcast port (default: 5076)
§Errors

Returns an error if the context cannot be created.

§Example
use pvxs_sys::Context;

let ctx = Context::from_env().expect("Failed to create context");
Source

pub fn get(&mut self, pv_name: &str, timeout: f64) -> Result<Value>

Perform a synchronous GET operation

Retrieves the current value of a process variable.

§Arguments
  • pv_name - The name of the process variable
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist
  • The operation times out
  • A network error occurs
§Example
let value = ctx.get("my:pv:name", 5.0).expect("GET failed");
println!("Value: {}", value);
Source

pub fn put_double( &mut self, pv_name: &str, value: f64, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with a double value

Sets the “value” field of a process variable to a double.

§Arguments
  • pv_name - The name of the process variable
  • value - The value to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_double("my:pv:double", 42.0, 5.0).expect("PUT failed");
Source

pub fn put_int32( &mut self, pv_name: &str, value: i32, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with an int32 value

Sets the “value” field of a process variable to an int32.

§Arguments
  • pv_name - The name of the process variable
  • value - The value to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_int32("my:pv:int", 42, 5.0).expect("PUT failed");
Source

pub fn put_string( &mut self, pv_name: &str, value: &str, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with a string value

Sets the “value” field of a process variable to a string.

§Arguments
  • pv_name - The name of the process variable
  • value - The value to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_string("my:pv:string", "Hello, EPICS!", 5.0).expect("PUT failed");
Source

pub fn put_enum( &mut self, pv_name: &str, value: i16, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with an enum value

Sets the “value” field of a process variable to an enum (i16).

§Arguments
  • pv_name - The name of the process variable
  • value - The enum value to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value is not a valid enum choice
§Example
ctx.put_enum("my:pv:enum", 2, 5.0).expect("PUT failed");
Source

pub fn put_double_array( &mut self, pv_name: &str, value: Vec<f64>, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with a double array

Sets the “value” field of a process variable to an array of doubles.

§Arguments
  • pv_name - The name of the process variable
  • value - The array of values to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_double_array("my:pv:array", vec![1.0, 2.0, 3.0], 5.0).expect("PUT failed");
Source

pub fn put_int32_array( &mut self, pv_name: &str, value: Vec<i32>, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with an int32 array

Sets the “value” field of a process variable to an array of int32s.

§Arguments
  • pv_name - The name of the process variable
  • value - The array of values to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_int32_array("my:pv:array", vec![10, 20, 30], 5.0).expect("PUT failed");
Source

pub fn put_string_array( &mut self, pv_name: &str, value: Vec<String>, timeout: f64, ) -> Result<()>

Perform a synchronous PUT operation with a string array

Sets the “value” field of a process variable to an array of strings.

§Arguments
  • pv_name - The name of the process variable
  • value - The array of string values to write
  • timeout - Maximum time to wait in seconds
§Errors

Returns an error if:

  • The PV doesn’t exist or is read-only
  • The operation times out
  • The value type doesn’t match
§Example
ctx.put_string_array("my:pv:array", vec!["one".to_string(), "two".to_string()], 5.0).expect("PUT failed");
Source

pub fn info(&mut self, pv_name: &str, timeout: f64) -> Result<Value>

Get type information about a process variable

Retrieves the structure definition without fetching data. Useful for discovering the schema of a PV.

§Arguments
  • pv_name - The name of the process variable
  • timeout - Maximum time to wait in seconds
§Example
let info = ctx.info("my:pv:name", 5.0).expect("INFO failed");
println!("PV structure: {}", info);
Source

pub fn rpc(&mut self, pv_name: &str) -> Result<Rpc>

Create an RPC (Remote Procedure Call) builder

Creates a builder for performing RPC operations on EPICS servers. RPC allows calling server-side functions with arguments.

§Arguments
  • pv_name - The name of the RPC service/endpoint
§Example
let mut rpc = ctx.rpc("my:service").expect("RPC creation failed");
rpc.arg_string("command", "start");
rpc.arg_double("value", 42.0);
let result = rpc.execute(5.0).expect("RPC execution failed");
Source

pub fn monitor(&mut self, pv_name: &str) -> Result<Monitor>

Create a monitor for a process variable

Monitors allow you to subscribe to value changes and receive notifications when a PV updates, providing an efficient alternative to polling.

§Arguments
  • pv_name - Name of the process variable to monitor
§Returns

A Monitor instance that can be used to receive value updates.

§Example
let mut monitor = ctx.monitor("TEST:PV_Double").expect("Monitor creation failed");

monitor.start();

// Check for updates
if let Some(value) = monitor.try_get_update().expect("Monitor check failed") {
    println!("PV updated: {}", value);
}

monitor.stop();
Source

pub fn monitor_builder(&mut self, pv_name: &str) -> Result<MonitorBuilder>

Create a MonitorBuilder for advanced monitor configuration

Returns a builder that allows configuring event masks and callbacks before creating the monitor subscription.

§Arguments
  • pv_name - Name of the process variable to monitor
§Returns

A MonitorBuilder instance for configuring the monitor.

§Example
use pvxs_sys::Context;

let mut ctx = Context::from_env().expect("Context creation failed");
let monitor = ctx.monitor_builder("TEST:PV_Double")?
    .connect_exception(true)      // Throw connection exceptions
    .disconnect_exception(true)   // Throw disconnection exceptions
    .exec()
    .expect("Monitor creation failed");

Trait Implementations§

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.