Skip to content

Commit

Permalink
Add VISA to connection information (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
esarver authored Sep 5, 2024
1 parent 2c6f0be commit 46ca0c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{num::ParseIntError, string::FromUtf8Error};

use thiserror::Error;

use crate::instrument::info::ConnectionAddr;
use crate::interface::connection_addr::ConnectionAddr;

/// Define errors that originate from this crate
#[derive(Error, Debug)]
Expand Down
31 changes: 2 additions & 29 deletions src/instrument/info.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
//! Define the trait and datatypes necessary to describe an instrument.
use minidom::Element;

use crate::{error::Result, usbtmc::UsbtmcAddr, InstrumentError};
use crate::{error::Result, InstrumentError};
use std::{
fmt::Display,
io::{Read, Write},
net::SocketAddr,
time::Duration,
};

/// A generic connection address that covers all the different connection types.
/// Each device interface type will also have a [`TryFrom`] impl that converts from
/// this enum to itself. [`From`] is **not** implemented because the conversion could
/// fail.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConnectionAddr {
/// A LAN connection is created with a [`SocketAddr`], which includes an [`IpAddr`] and
/// a port for the connection.
Lan(SocketAddr),

/// A USBTMC connection is created with a [`UsbtmcAddr`].
Usbtmc(UsbtmcAddr),
//Add other device interface types here
Unknown,
}

impl Display for ConnectionAddr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Lan(lan_info) => lan_info.to_string(),
Self::Usbtmc(usb_info) => usb_info.to_string(),
Self::Unknown => "<UNKNOWN>".to_string(),
};
write!(f, "{s}")
}
}
use crate::interface::connection_addr::ConnectionAddr;

/// The information about an instrument.
#[allow(clippy::module_name_repetitions)]
Expand Down
12 changes: 12 additions & 0 deletions src/interface/connection_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::net::SocketAddr;

use crate::interface::usbtmc::UsbtmcAddr;

#[cfg(feature = "visa")]
use visa_rs::VisaString;

/// A generic connection address that covers all the different connection types.
/// Each device interface type will also have a [`TryFrom`] impl that converts from
/// this enum to itself. [`From`] is **not** implemented because the conversion could
Expand All @@ -16,6 +19,11 @@ pub enum ConnectionAddr {

/// A USBTMC connection is created with a [`UsbtmcAddr`].
Usbtmc(UsbtmcAddr),

#[cfg(feature = "visa")]
/// A VISA resource string
Visa(VisaString),

//Add other device interface types here
Unknown,
}
Expand All @@ -25,6 +33,10 @@ impl Display for ConnectionAddr {
let s = match self {
Self::Lan(lan_info) => lan_info.to_string(),
Self::Usbtmc(usb_info) => usb_info.to_string(),

#[cfg(feature = "visa")]
Self::Visa(visa_info) => visa_info.to_string(),

Self::Unknown => "<UNKNOWN>".to_string(),
};
write!(f, "{s}")
Expand Down
2 changes: 1 addition & 1 deletion src/model/versatest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Instrument {
}

fn is_versatest(model: impl AsRef<str>) -> bool {
["VERSATEST-600", "TSPop", "TSP"].contains(&model.as_ref())
["MP5103", "VERSATEST-300", "VERSATEST-600", "TSPop", "TSP"].contains(&model.as_ref())
}

//Implement device_interface::Interface since it is a subset of instrument::Instrument trait.
Expand Down

0 comments on commit 46ca0c9

Please sign in to comment.