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
impl Context
Sourcepub fn from_env() -> Result<Self>
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 addressesEPICS_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");Sourcepub fn get(&mut self, pv_name: &str, timeout: f64) -> Result<Value>
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 variabletimeout- 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);Sourcepub fn put_double(
&mut self,
pv_name: &str,
value: f64,
timeout: f64,
) -> Result<()>
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 variablevalue- The value to writetimeout- 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");Sourcepub fn put_int32(
&mut self,
pv_name: &str,
value: i32,
timeout: f64,
) -> Result<()>
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 variablevalue- The value to writetimeout- 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");Sourcepub fn put_string(
&mut self,
pv_name: &str,
value: &str,
timeout: f64,
) -> Result<()>
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 variablevalue- The value to writetimeout- 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");Sourcepub fn put_enum(
&mut self,
pv_name: &str,
value: i16,
timeout: f64,
) -> Result<()>
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 variablevalue- The enum value to writetimeout- 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");Sourcepub fn put_double_array(
&mut self,
pv_name: &str,
value: Vec<f64>,
timeout: f64,
) -> Result<()>
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 variablevalue- The array of values to writetimeout- 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");Sourcepub fn put_int32_array(
&mut self,
pv_name: &str,
value: Vec<i32>,
timeout: f64,
) -> Result<()>
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 variablevalue- The array of values to writetimeout- 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");Sourcepub fn put_string_array(
&mut self,
pv_name: &str,
value: Vec<String>,
timeout: f64,
) -> Result<()>
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 variablevalue- The array of string values to writetimeout- 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");Sourcepub fn info(&mut self, pv_name: &str, timeout: f64) -> Result<Value>
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 variabletimeout- Maximum time to wait in seconds
§Example
let info = ctx.info("my:pv:name", 5.0).expect("INFO failed");
println!("PV structure: {}", info);Sourcepub fn rpc(&mut self, pv_name: &str) -> Result<Rpc>
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");Sourcepub fn monitor(&mut self, pv_name: &str) -> Result<Monitor>
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();Sourcepub fn monitor_builder(&mut self, pv_name: &str) -> Result<MonitorBuilder>
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");