Struct visa_device_handler::visa_module::SafeDeviceMap

source ·
pub struct SafeDeviceMap { /* private fields */ }
Expand description

The SafeDeviceMap provides a lock safe way to store The resource manager and all the sessions in one place.
SafeDeviceMap uses Arc and Mutex wrapped around rm and map to provide a safe way to interact with them.

§Params

@lib -> The main visa library, its just to create all kind of calls.
@rm -> u32 session number, will hold the sessions and open new ones.
@map -> HashMap<String,Device> instance, stores all the instruments by thier device name (Human readable string).

#Panic As the program panics, the rm will be droped so the connections should be freed as well.
But just to be safe allways call SafeDeviceMap::disconnect_device or SafeDeviceMap::clear_map when finished.
I will try too look more into it and update it in the future.

§Examples

let sdm_result:SafeDeviceMap = SafeDeviceMap::init(None);
match sdm_result {
    Ok(mapper) => {
        mapper.connect_device("address_01".to_string());
        let data = mapper.query_from_device("name_01".to_string(),"cool funcation with args").unwrap();
        println!("got {} from the device",data);
        mapper.disconnect_device("name_01".to_string());
    }
    Err(e) => {/*print codes or anything */}
}

To get a SafeDeviceMap call SafeDeviceMap::init().

Implementations§

source§

impl SafeDeviceMap

source

pub fn init(file_path: Option<&str>) -> Result<SafeDeviceMap, String>

Call this to get the SafeDeviceMap.
It will generate a DefaultRM ,create a new HasMap and save the library instance.

This Method MUST be called.

source

pub fn connect_device(&self, address: String) -> Result<(), String>

Call this to insert a new device to the HashMap.

@address -> type String, the address of the device you wish to add to the map.
Before a device is entered to the map it will open a connection too.

Returns -> error String if failed to insert or void if success.

source

pub fn disconnect_device(&self, name: String) -> Result<Device, String>

Call this to remove a device from the map. Note, the removed device data will be returned.

@name -> Device name to get removed.

Return -> The removed Device on success or error string on fail.

source

pub fn write_to_device(&self, name: String, msg: &str) -> Result<(), String>

Call this to write message to the device.

@name -> Device name send the message to.
@msg -> The message to send, a concated str of function name and its args.

Returns -> Void on success string if error.

source

pub fn read_from_device(&self, name: String) -> Result<String, String>

Call this to read message from the device buffer.
Note, the buffer will be cleared after a read!

@name -> Device name you wish to read its buffer.

Returns -> The read string if success error string if failed.

source

pub fn query_from_device( &self, name: String, msg: &str, ) -> Result<String, String>

Call this to write and read message from the device buffer.
Note! the buffer will be cleared after a read!
This calls behaves like write and then read.

@name -> Device name to interact with.
@msg -> Message to send to the device (the write message).

Returns -> The read string if success error string if failed.

source

pub fn get_first_device(&self) -> Result<(), String>

This function will find the first device the rm can finds.

Returns -> The first Device.

source

pub fn find_all_devices(&self) -> Result<Vec<Device>, String>

This function will find all the devices connected with USB to the PC.

Returns -> A Vec of Device with USB connections.

source

pub fn clear_map(&self) -> Result<(), String>

This function clears the mapping of the devices.
It will close all the connections and drop all the Devices.

source

pub fn get_all_mapped_devices(&self) -> Result<Vec<Device>, String>

This function returns to the user all the active Device that the SafeDeviceMap have access to.

Returns -> A Vec of Device currently in use.

Trait Implementations§

source§

impl Drop for SafeDeviceMap

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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>,

§

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>,

§

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.