Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VISA to connection information #20

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading