diff --git a/kic-discover-visa/src/visa.rs b/kic-discover-visa/src/visa.rs index e6293ba..4edc77d 100644 --- a/kic-discover-visa/src/visa.rs +++ b/kic-discover-visa/src/visa.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, ffi::CString, time::Duration}; use async_std::fs::write; use serde::{Deserialize, Serialize}; -use tracing::trace; +use tracing::{error, trace}; use tsp_toolkit_kic_lib::{ instrument::info::{get_info, InstrumentInfo}, interface::connection_addr::ConnectionAddr, @@ -15,7 +15,10 @@ use crate::{insert_disc_device, model_check, IoType}; pub async fn visa_discover(timeout: Option) -> anyhow::Result> { let mut discovered_instruments: HashSet = HashSet::new(); - let rm = visa_rs::DefaultRM::new()?; + let Ok(rm) = visa_rs::DefaultRM::new() else { + error!("Unable to get VISA Default Resource Manager"); + return Ok(discovered_instruments); + }; let instruments = match rm.find_res_list(&CString::new("?*")?.into()) { Ok(x) => x, Err(e) => { @@ -26,27 +29,23 @@ pub async fn visa_discover(timeout: Option) -> anyhow::Result c, - Err(_) => { - trace!("Resource {i} no longer available, skipping."); - continue; - } + let Ok(mut connected) = rm.open(&i, AccessMode::NO_LOCK, visa_rs::TIMEOUT_IMMEDIATE) else { + trace!("Resource {i} no longer available, skipping."); + continue; }; trace!("Getting info from {connected:?}"); - let mut info = match get_info(&mut connected) { - Ok(i) => i, - Err(_) => { - trace!("Unable to write to {i}, skipping"); - drop(connected); - continue; - } + let Ok(mut info) = get_info(&mut connected) else { + trace!("Unable to write to {i}, skipping"); + drop(connected); + continue; }; info.address = Some(ConnectionAddr::Visa(i.clone())); trace!("Got info: {info:?}");