diff --git a/Cargo.lock b/Cargo.lock index 077bdf5..af16422 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1203,11 +1203,9 @@ dependencies = [ "minidom", "reqwest", "rpassword", - "rusb", "serde", "serde_json", "thiserror", - "tmc", "tokio", "tracing", "tracing-subscriber", @@ -1233,11 +1231,9 @@ dependencies = [ "minidom", "reqwest", "rpassword", - "rusb", "serde", "serde_json", "thiserror", - "tmc", "tokio", "tracing", "tracing-subscriber", @@ -1285,18 +1281,6 @@ version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" -[[package]] -name = "libusb1-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da050ade7ac4ff1ba5379af847a10a10a8e284181e060105bf8d86960ce9ce0f" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1916,16 +1900,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "rusb" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9f9ff05b63a786553a4c02943b74b34a988448671001e9a27e2f0565cc05a4" -dependencies = [ - "libc", - "libusb1-sys", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2342,16 +2316,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tmc" -version = "0.1.1" -source = "git+https://github.com/esarver/rusb-usbtmc#0ed58c406a9ec7f1c48672a74531d8cd70957ac7" -dependencies = [ - "byteorder", - "rusb", - "thiserror", -] - [[package]] name = "tokio" version = "1.40.0" @@ -2548,7 +2512,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tsp-toolkit-kic-lib" version = "0.18.2" -source = "git+https://github.com/tektronix/tsp-toolkit-kic-lib.git?tag=v0.18.2-0#ba3aa64d1740cdf3d967ae3629ff56d90e50afbd" +source = "git+https://github.com/tektronix/tsp-toolkit-kic-lib.git?tag=v0.18.2-1#7005210fcc77668dafc5a5a48b809dfe3cedb0f1" dependencies = [ "bytes", "chrono", @@ -2556,11 +2520,9 @@ dependencies = [ "phf", "reqwest", "rpassword", - "rusb", "serde", "serde_json", "thiserror", - "tmc", "tracing", "visa-rs", ] diff --git a/Cargo.toml b/Cargo.toml index 87dd60e..983291e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,14 +33,12 @@ phf = { version = "0.11.2", features = ["macros"] } regex = "1.10.3" reqwest = "0.12.0" rpassword = "7.3.1" -rusb = "0.9.3" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" thiserror = "1.0.58" -tmc = { git = "https://github.com/esarver/rusb-usbtmc" } tracing = { version = "0.1.40", features = ["async-await"] } tracing-subscriber = { version = "0.3.18", features = ["json"] } -tsp-toolkit-kic-lib = { git = "https://github.com/tektronix/tsp-toolkit-kic-lib.git", tag = "v0.18.2-0" } +tsp-toolkit-kic-lib = { git = "https://github.com/tektronix/tsp-toolkit-kic-lib.git", tag = "v0.18.2-1" } [workspace.lints.rust] warnings = "deny" diff --git a/kic-discover-visa/Cargo.toml b/kic-discover-visa/Cargo.toml index 463ce44..75809af 100644 --- a/kic-discover-visa/Cargo.toml +++ b/kic-discover-visa/Cargo.toml @@ -23,11 +23,9 @@ mdns = { workspace = true } # until https://github.com/d minidom = { workspace = true } reqwest = { workspace = true } rpassword = { workspace = true } -rusb = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } -tmc = { workspace = true } tokio = { version = "1.36.0", features = ["full"] } tracing = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/kic-discover-visa/src/instrument_discovery/mod.rs b/kic-discover-visa/src/instrument_discovery/mod.rs index 50d86e6..91760a0 100644 --- a/kic-discover-visa/src/instrument_discovery/mod.rs +++ b/kic-discover-visa/src/instrument_discovery/mod.rs @@ -6,7 +6,6 @@ use tsp_toolkit_kic_lib::{ }; use crate::ethernet::{LxiDeviceInfo, COMM_PORT}; -use crate::usbtmc::Usbtmc; use crate::visa::visa_discover; #[derive(Debug)] @@ -62,27 +61,6 @@ impl InstrumentDiscovery { Ok(discovery_results) } - /// Discover instruments over USB - /// - /// # Errors - /// If [`Usbtmc::usb_discover`] fails, and error will be returned. - pub async fn usb_discover(&self) -> anyhow::Result> { - let mut discovery_results: HashSet = HashSet::new(); - - match Usbtmc::usb_discover(self.timeout).await { - Ok(instrs) => { - for inst in instrs { - discovery_results.insert(inst); - } - } - Err(e) => { - eprintln!("Unable to discover USB devices: {e}"); //TODO add color - return Err(e); - } - } - Ok(discovery_results) - } - pub async fn visa_discover(&self) -> anyhow::Result> { visa_discover(self.timeout).await } diff --git a/kic-discover-visa/src/lib.rs b/kic-discover-visa/src/lib.rs index 7f8b06b..e6fb5fa 100644 --- a/kic-discover-visa/src/lib.rs +++ b/kic-discover-visa/src/lib.rs @@ -2,7 +2,6 @@ use std::{collections::HashSet, hash::Hash, io::Error, sync::Mutex}; pub mod ethernet; pub mod instrument_discovery; -pub mod usbtmc; pub mod visa; #[macro_use] @@ -128,6 +127,6 @@ pub fn insert_disc_device(device: &str) -> Result<(), Error> { #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, serde::Serialize, serde::Deserialize)] enum IoType { Lan, - Usb, Visa, + Usb, } diff --git a/kic-discover-visa/src/main.rs b/kic-discover-visa/src/main.rs index 7e20611..4f3b8fc 100644 --- a/kic-discover-visa/src/main.rs +++ b/kic-discover-visa/src/main.rs @@ -45,10 +45,6 @@ struct Cli { enum SubCli { /// Look for all devices connected on LAN Lan(DiscoverCmd), - - /// Look for all devices connected on USB - //Usb(DiscoverCmd), - /// Look for all devices that can be connected to via the installed VISA driver Visa(DiscoverCmd), /// Look for all devices on all interface types. @@ -264,24 +260,6 @@ async fn main() -> anyhow::Result<()> { trace!("Discovered instruments: {lan_instruments:?}"); lan_instruments } - //SubCli::Usb(args) => { - // start_logger(&args.verbose, &args.log_file, &args.log_socket)?; - // info!("Discovering USB instruments"); - // #[allow(clippy::mutable_key_type)] - // let usb_instruments = match discover_usb().await { - // Ok(i) => i, - // Err(e) => { - // error!("Error in USB discovery: {e}"); - // return Err(e); - // } - // }; - // info!("USB Discovery complete"); - // trace!("Discovered {} USB instruments", usb_instruments.len()); - // trace!("Discovered instruments: {usb_instruments:?}"); - // for instrument in usb_instruments { - // println!("{instrument}"); - // } - //} SubCli::Visa(args) => { start_logger(&args.verbose, &args.log_file, &args.log_socket)?; info!("Discovering VISA instruments"); @@ -300,22 +278,6 @@ async fn main() -> anyhow::Result<()> { } SubCli::All(args) => { start_logger(&args.verbose, &args.log_file, &args.log_socket)?; - //info!("Discovering USB instruments"); - //#[allow(clippy::mutable_key_type)] - //let usb_instruments = match discover_usb().await { - // Ok(i) => i, - // Err(e) => { - // error!("Error in USB discovery: {e}"); - // return Err(e); - // } - //}; - //info!("USB Discovery complete"); - //trace!("Discovered {} USB instruments", usb_instruments.len()); - //println!("Discovered {} USB instruments", usb_instruments.len()); - //trace!("Discovered USB instruments: {usb_instruments:?}"); - //for instrument in usb_instruments { - // println!("{instrument}"); - //} info!("Discovering VISA instruments"); #[allow(clippy::mutable_key_type)] @@ -424,11 +386,3 @@ async fn discover_visa(args: DiscoverCmd) -> anyhow::Result anyhow::Result> { -// let dur = Duration::from_secs(5); //Not used in USB -// let discover_instance = InstrumentDiscovery::new(dur); -// let instruments = discover_instance.usb_discover().await?; -// -// Ok(instruments) -//} diff --git a/kic-discover-visa/src/usbtmc/mod.rs b/kic-discover-visa/src/usbtmc/mod.rs deleted file mode 100644 index 743a10e..0000000 --- a/kic-discover-visa/src/usbtmc/mod.rs +++ /dev/null @@ -1,179 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::{collections::HashSet, hash::Hash, time::Duration}; -use tmc::{list_instruments, Instrument, InstrumentHandle, TMCError, TMCResult}; -use tsp_toolkit_kic_lib::{ - instrument::info::InstrumentInfo, interface::connection_addr::ConnectionAddr, - usbtmc::UsbtmcAddr, -}; - -use crate::{insert_disc_device, model_check, IoType}; - -pub struct Usbtmc { - device: rusb::Device, - #[allow(dead_code)] - handle: Option>, - pub unique_string: String, -} - -impl Usbtmc { - /// Construct a new [`Usbtmc`] device that holds the details of a USB - /// device. - /// - /// # Errors - /// This will return a [`TMCResult`] error if the details of the device - /// cannot be fetched from the USB subsystem. This can occur for platform - /// dependent reasons such as the device being assigned an unsupported - /// USB driver in Windows or the device not having proper udev rules created - /// in Linux. - pub fn new(device: rusb::Device) -> TMCResult { - let vendor = device.device_descriptor()?.vendor_id(); - let product = device.device_descriptor()?.product_id(); - let address = device.address(); - Ok(Self { - device, - handle: None, - unique_string: format!("{vendor:X}:{product:X}:{address}"), - }) - } - - /// Discover instruments connected via USB. - /// - /// # Errors - /// Errors can occur if - /// - [`rusb::Context`] has an error during construction - /// - [`list_instruments`] has an error - #[allow(clippy::unused_async)] // to keep API consistent - pub async fn usb_discover( - _timeout: Option, - ) -> anyhow::Result> { - let context = match rusb::Context::new() { - Ok(x) => x, - Err(e) => { - return Err(Box::new(e).into()); - } - }; - let instruments = match list_instruments(context) { - Ok(x) => x, - Err(e) => { - return Err(Box::new(e).into()); - } - }; - let mut discovered_instrs: HashSet = HashSet::new(); - - if instruments.is_empty() { - eprintln!("No instruments found"); - //return Ok(()); - } - - // We allow the unused mut here because it is only unused in release mode. - #[allow(unused_mut)] - for mut instrument in instruments { - #[cfg(debug_assertions)] - eprintln!( - "Found instrument: {}", - instrument - .read_resource_string() - .unwrap_or_else(|_| String::from("[UNKNOWN]")) - ); - let manufacturer = instrument - .read_manufacturer_string()? - .unwrap_or_else(|| String::from("NA")); - let firmware_revision = instrument - .read_device_version()? - .map_or_else(|| String::from("NA"), |version| version.to_string()); - let model = String::from(model_lut(instrument.device_desc.product_id())); - let serial_number = instrument - .read_serial_number()? - .unwrap_or_else(|| String::from("NA")) - .clone(); - - let tmc_instr: Result = instrument.try_into(); - - //ToDo: test versatest when it's discoverable - let res = model_check(model.as_str()); - if manufacturer.to_ascii_lowercase().contains("keithley") && res.0 { - if let Ok(mut instr) = tmc_instr { - let usb_info = UsbDeviceInfo { - io_type: IoType::Usb, - instr_address: instr.unique_string.clone(), - manufacturer, - model, - serial_number, - firmware_revision, - instr_categ: res.1.to_string(), - }; - if let Ok(out_str) = serde_json::to_string(&usb_info) { - insert_disc_device(out_str.as_str())?; - } - let usbtmc_addr = UsbtmcAddr { - device: instr.device, - model: usb_info.model.clone(), - serial: usb_info.serial_number.clone(), - }; - let disc_usb_inst = InstrumentInfo { - vendor: Some(usb_info.manufacturer), - model: Some(usb_info.model), - serial_number: Some(usb_info.serial_number.clone()), - firmware_rev: Some(usb_info.firmware_revision), - address: Some(ConnectionAddr::Usbtmc(usbtmc_addr.clone())), - }; - discovered_instrs.insert(disc_usb_inst); - } - } - } - Ok(discovered_instrs) - } -} - -impl TryFrom> for Usbtmc { - type Error = TMCError; - - fn try_from(value: Instrument) -> Result { - Self::new(value.device) - } -} - -const fn model_lut(pid: u16) -> &'static str { - match pid { - 0x3706 => "3706", - 0xCA7C => "4210-CVU-ACU", - 0x707A => "707A", - 0x707B => "707B", - 0x2100 => "2100", - 0x2110 => "2110", - 0x3390 => "3390", - 0x488B => "K-USB-488B", - 0x2450 => "2450", - 0x2460 => "2460", - 0x2461 => "2461", - 0x1642 => "2461-SYS", - 0x2470 => "2470", - 0x2601 => "2601", - 0x26F1 => "2601B-PULSE", - 0x2602 => "2602B", - 0x2604 => "2604B", - 0x2611 => "2611B", - 0x2612 => "2612B", - 0x2614 => "2614B", - 0x2634 => "2634B", - 0x2635 => "2635B", - 0x2636 => "2636B", - 0x426C => "4200A-CVIV", - 0x6500 => "DMM6500", - 0x6510 => "DAQ6510", - 0x7500 => "DMM7500", - 0x7512 => "DMM7512", - _ => "UNKNOWN", - } -} - -#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, Serialize, Deserialize)] -pub struct UsbDeviceInfo { - io_type: IoType, - instr_address: String, - manufacturer: String, - model: String, - serial_number: String, - firmware_revision: String, - instr_categ: String, -} diff --git a/kic-discover/Cargo.toml b/kic-discover/Cargo.toml index 618cac3..25e3678 100644 --- a/kic-discover/Cargo.toml +++ b/kic-discover/Cargo.toml @@ -23,11 +23,9 @@ mdns = { workspace = true } # until https://github.com/d minidom = { workspace = true } reqwest = { workspace = true } rpassword = { workspace = true } -rusb = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } -tmc = { workspace = true } tokio = { version = "1.36.0", features = ["full"] } tracing = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/kic-discover/src/instrument_discovery/mod.rs b/kic-discover/src/instrument_discovery/mod.rs index 0cdc3cb..7198ed0 100644 --- a/kic-discover/src/instrument_discovery/mod.rs +++ b/kic-discover/src/instrument_discovery/mod.rs @@ -6,7 +6,6 @@ use tsp_toolkit_kic_lib::{ }; use crate::ethernet::{LxiDeviceInfo, COMM_PORT}; -use crate::usbtmc::Usbtmc; #[derive(Debug)] pub struct InstrumentDiscovery { @@ -21,25 +20,6 @@ impl InstrumentDiscovery { } } - // pub async fn discover(&self) -> anyhow::Result> - // where - // T: Discover, - // { - // let mut discovery_results: HashSet = HashSet::new(); - // match T::discover(self.timeout).await { - // Ok(instrs) => { - // for inst in instrs { - // discovery_results.insert(inst); - // } - // } - // Err(e) => { - // eprintln!("Unable to discover LXI devices: {e}"); //TODO add color - // return Err(e); - // } - // }; - // Ok(discovery_results) - // } - /// Discover instruments on the network. /// /// # Errors @@ -60,27 +40,6 @@ impl InstrumentDiscovery { }; Ok(discovery_results) } - - /// Discover instruments over USB - /// - /// # Errors - /// If [`Usbtmc::usb_discover`] fails, and error will be returned. - pub async fn usb_discover(&self) -> anyhow::Result> { - let mut discovery_results: HashSet = HashSet::new(); - - match Usbtmc::usb_discover(self.timeout).await { - Ok(instrs) => { - for inst in instrs { - discovery_results.insert(inst); - } - } - Err(e) => { - eprintln!("Unable to discover USB devices: {e}"); //TODO add color - return Err(e); - } - } - Ok(discovery_results) - } } impl From for InstrumentInfo { diff --git a/kic-discover/src/lib.rs b/kic-discover/src/lib.rs index bd4d176..f0f4ddd 100644 --- a/kic-discover/src/lib.rs +++ b/kic-discover/src/lib.rs @@ -2,7 +2,6 @@ use std::{collections::HashSet, hash::Hash, io::Error, sync::Mutex}; pub mod ethernet; pub mod instrument_discovery; -pub mod usbtmc; #[macro_use] extern crate lazy_static; @@ -127,5 +126,4 @@ pub fn insert_disc_device(device: &str) -> Result<(), Error> { #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, serde::Serialize, serde::Deserialize)] enum IoType { Lan, - Usb, } diff --git a/kic-discover/src/main.rs b/kic-discover/src/main.rs index 3830035..3c98a2d 100644 --- a/kic-discover/src/main.rs +++ b/kic-discover/src/main.rs @@ -48,8 +48,6 @@ struct Cli { enum SubCli { /// Look for all devices connected on LAN Lan(DiscoverCmd), - /// Look for all devices connected on USB - //Usb(DiscoverCmd), /// Look for all devices on all interface types. All(DiscoverCmd), } @@ -291,43 +289,8 @@ async fn main() -> anyhow::Result<()> { trace!("Discovered instruments: {lan_instruments:?}"); lan_instruments } - //SubCli::Usb(args) => { - // start_logger(&args.verbose, &args.log_file, &args.log_socket)?; - // info!("Discovering USB instruments"); - // #[allow(clippy::mutable_key_type)] - // let usb_instruments = match discover_usb().await { - // Ok(i) => i, - // Err(e) => { - // error!("Error in USB discovery: {e}"); - // return Err(e); - // } - // }; - // info!("USB Discovery complete"); - // trace!("Discovered {} USB instruments", usb_instruments.len()); - // trace!("Discovered instruments: {usb_instruments:?}"); - // for instrument in usb_instruments { - // println!("{instrument}"); - // } - //} SubCli::All(args) => { start_logger(&args.verbose, &args.log_file, &args.log_socket)?; - //info!("Discovering USB instruments"); - //#[allow(clippy::mutable_key_type)] - //let usb_instruments = match discover_usb().await { - // Ok(i) => i, - // Err(e) => { - // error!("Error in USB discovery: {e}"); - // return Err(e); - // } - //}; - //info!("USB Discovery complete"); - //trace!("Discovered {} USB instruments", usb_instruments.len()); - //println!("Discovered {} USB instruments", usb_instruments.len()); - //trace!("Discovered USB instruments: {usb_instruments:?}"); - //for instrument in usb_instruments { - // println!("{instrument}"); - //} - info!("Discovering LAN instruments"); #[allow(clippy::mutable_key_type)] let lan_instruments = match discover_lan(args.clone()).await { @@ -414,11 +377,3 @@ async fn discover_lan(args: DiscoverCmd) -> anyhow::Result anyhow::Result> { -// let dur = Duration::from_secs(5); //Not used in USB -// let discover_instance = InstrumentDiscovery::new(dur); -// let instruments = discover_instance.usb_discover().await?; -// -// Ok(instruments) -//} diff --git a/kic-discover/src/usbtmc/mod.rs b/kic-discover/src/usbtmc/mod.rs deleted file mode 100644 index 743a10e..0000000 --- a/kic-discover/src/usbtmc/mod.rs +++ /dev/null @@ -1,179 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::{collections::HashSet, hash::Hash, time::Duration}; -use tmc::{list_instruments, Instrument, InstrumentHandle, TMCError, TMCResult}; -use tsp_toolkit_kic_lib::{ - instrument::info::InstrumentInfo, interface::connection_addr::ConnectionAddr, - usbtmc::UsbtmcAddr, -}; - -use crate::{insert_disc_device, model_check, IoType}; - -pub struct Usbtmc { - device: rusb::Device, - #[allow(dead_code)] - handle: Option>, - pub unique_string: String, -} - -impl Usbtmc { - /// Construct a new [`Usbtmc`] device that holds the details of a USB - /// device. - /// - /// # Errors - /// This will return a [`TMCResult`] error if the details of the device - /// cannot be fetched from the USB subsystem. This can occur for platform - /// dependent reasons such as the device being assigned an unsupported - /// USB driver in Windows or the device not having proper udev rules created - /// in Linux. - pub fn new(device: rusb::Device) -> TMCResult { - let vendor = device.device_descriptor()?.vendor_id(); - let product = device.device_descriptor()?.product_id(); - let address = device.address(); - Ok(Self { - device, - handle: None, - unique_string: format!("{vendor:X}:{product:X}:{address}"), - }) - } - - /// Discover instruments connected via USB. - /// - /// # Errors - /// Errors can occur if - /// - [`rusb::Context`] has an error during construction - /// - [`list_instruments`] has an error - #[allow(clippy::unused_async)] // to keep API consistent - pub async fn usb_discover( - _timeout: Option, - ) -> anyhow::Result> { - let context = match rusb::Context::new() { - Ok(x) => x, - Err(e) => { - return Err(Box::new(e).into()); - } - }; - let instruments = match list_instruments(context) { - Ok(x) => x, - Err(e) => { - return Err(Box::new(e).into()); - } - }; - let mut discovered_instrs: HashSet = HashSet::new(); - - if instruments.is_empty() { - eprintln!("No instruments found"); - //return Ok(()); - } - - // We allow the unused mut here because it is only unused in release mode. - #[allow(unused_mut)] - for mut instrument in instruments { - #[cfg(debug_assertions)] - eprintln!( - "Found instrument: {}", - instrument - .read_resource_string() - .unwrap_or_else(|_| String::from("[UNKNOWN]")) - ); - let manufacturer = instrument - .read_manufacturer_string()? - .unwrap_or_else(|| String::from("NA")); - let firmware_revision = instrument - .read_device_version()? - .map_or_else(|| String::from("NA"), |version| version.to_string()); - let model = String::from(model_lut(instrument.device_desc.product_id())); - let serial_number = instrument - .read_serial_number()? - .unwrap_or_else(|| String::from("NA")) - .clone(); - - let tmc_instr: Result = instrument.try_into(); - - //ToDo: test versatest when it's discoverable - let res = model_check(model.as_str()); - if manufacturer.to_ascii_lowercase().contains("keithley") && res.0 { - if let Ok(mut instr) = tmc_instr { - let usb_info = UsbDeviceInfo { - io_type: IoType::Usb, - instr_address: instr.unique_string.clone(), - manufacturer, - model, - serial_number, - firmware_revision, - instr_categ: res.1.to_string(), - }; - if let Ok(out_str) = serde_json::to_string(&usb_info) { - insert_disc_device(out_str.as_str())?; - } - let usbtmc_addr = UsbtmcAddr { - device: instr.device, - model: usb_info.model.clone(), - serial: usb_info.serial_number.clone(), - }; - let disc_usb_inst = InstrumentInfo { - vendor: Some(usb_info.manufacturer), - model: Some(usb_info.model), - serial_number: Some(usb_info.serial_number.clone()), - firmware_rev: Some(usb_info.firmware_revision), - address: Some(ConnectionAddr::Usbtmc(usbtmc_addr.clone())), - }; - discovered_instrs.insert(disc_usb_inst); - } - } - } - Ok(discovered_instrs) - } -} - -impl TryFrom> for Usbtmc { - type Error = TMCError; - - fn try_from(value: Instrument) -> Result { - Self::new(value.device) - } -} - -const fn model_lut(pid: u16) -> &'static str { - match pid { - 0x3706 => "3706", - 0xCA7C => "4210-CVU-ACU", - 0x707A => "707A", - 0x707B => "707B", - 0x2100 => "2100", - 0x2110 => "2110", - 0x3390 => "3390", - 0x488B => "K-USB-488B", - 0x2450 => "2450", - 0x2460 => "2460", - 0x2461 => "2461", - 0x1642 => "2461-SYS", - 0x2470 => "2470", - 0x2601 => "2601", - 0x26F1 => "2601B-PULSE", - 0x2602 => "2602B", - 0x2604 => "2604B", - 0x2611 => "2611B", - 0x2612 => "2612B", - 0x2614 => "2614B", - 0x2634 => "2634B", - 0x2635 => "2635B", - 0x2636 => "2636B", - 0x426C => "4200A-CVIV", - 0x6500 => "DMM6500", - 0x6510 => "DAQ6510", - 0x7500 => "DMM7500", - 0x7512 => "DMM7512", - _ => "UNKNOWN", - } -} - -#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, Serialize, Deserialize)] -pub struct UsbDeviceInfo { - io_type: IoType, - instr_address: String, - manufacturer: String, - model: String, - serial_number: String, - firmware_revision: String, - instr_categ: String, -} diff --git a/kic-visa/src/main.rs b/kic-visa/src/main.rs index 6ec1df5..40d7184 100644 --- a/kic-visa/src/main.rs +++ b/kic-visa/src/main.rs @@ -36,11 +36,7 @@ use tracing::{debug, error, info, instrument, level_filters::LevelFilter, trace, use tracing_subscriber::{layer::SubscriberExt, Layer, Registry}; use tsp_toolkit_kic_lib::{ - instrument::Instrument, - interface::async_stream::AsyncStream, - protocol::Protocol, - usbtmc::{self, UsbtmcAddr}, - Interface, + instrument::Instrument, interface::async_stream::AsyncStream, protocol::Protocol, Interface, }; #[derive(Debug, Subcommand)] @@ -98,23 +94,13 @@ fn add_connection_subcommands( .required(true), ); - //TODO(Fix async USB): let mut usb = Command::new("usb") - // .about("Perform the given action over a USBTMC connection") - // .arg( - // Arg::new("addr") - // .help("The instrument address in the form of, for example, `USB:2461:012345` where the second part is the product id, and the third part is the serial number.") - // .required(true) - // .value_parser(value_parser!(UsbtmcAddr)), - // ); - for arg in additional_args { lan = lan.arg(arg.clone()); visa = visa.arg(arg.clone()); - //TODO(Fix async USB): usb = usb.arg(arg.clone()); } - command.subcommand(lan).subcommand(visa) //TODO(Fix async USB): .subcommand(usb) + command.subcommand(lan).subcommand(visa) } #[must_use] @@ -461,7 +447,6 @@ fn main() -> anyhow::Result<()> { #[derive(Debug)] enum ConnectionType { Lan(SocketAddr), - Usb(UsbtmcAddr), Visa(String), } @@ -491,16 +476,6 @@ impl ConnectionType { Ok(Self::Visa(visa_string)) } - Some(("usb", sub_matches)) => { - let usb_addr: UsbtmcAddr = sub_matches - .get_one::("addr") - .ok_or_else(|| KicError::ArgParseError { - details: "no USB address provided".to_string(), - })? - .clone(); - - Ok(Self::Usb(usb_addr)) - } Some((ct, _sub_matches)) => { println!(); Err(KicError::ArgParseError { @@ -520,9 +495,6 @@ fn connect_sync_instrument(t: ConnectionType) -> anyhow::Result { (Box::new(TcpStream::connect(addr)?) as Box).into() } - ConnectionType::Usb(addr) => { - (Box::new(usbtmc::Stream::try_from(addr)?) as Box).into() - } ConnectionType::Visa(r) => Protocol::try_from_visa(r)?, }; trace!("Synchronously connected to interface"); @@ -542,11 +514,6 @@ fn connect_async_instrument(t: ConnectionType) -> anyhow::Result)?)), - ConnectionType::Usb(addr) => { - tsp_toolkit_kic_lib::protocol::Protocol::Raw(Box::new(AsyncStream::try_from( - Arc::new(usbtmc::Stream::try_from(addr)?) as Arc, - )?)) - } ConnectionType::Visa(r) => Protocol::try_from_visa(r)?, }; @@ -930,7 +897,6 @@ fn terminate(args: &ArgMatches) -> anyhow::Result<()> { return Err(e.into()); } } - ConnectionType::Usb(_) => {} ConnectionType::Visa(_) => {} } diff --git a/kic/src/main.rs b/kic/src/main.rs index 28510ac..a56b84a 100644 --- a/kic/src/main.rs +++ b/kic/src/main.rs @@ -34,11 +34,7 @@ use tracing::{debug, error, info, instrument, level_filters::LevelFilter, trace, use tracing_subscriber::{layer::SubscriberExt, Layer, Registry}; use tsp_toolkit_kic_lib::{ - instrument::Instrument, - interface::async_stream::AsyncStream, - protocol::Protocol, - usbtmc::{self, UsbtmcAddr}, - Interface, + instrument::Instrument, interface::async_stream::AsyncStream, protocol::Protocol, Interface, }; #[derive(Debug, Subcommand)] @@ -88,21 +84,11 @@ fn add_connection_subcommands( .value_parser(value_parser!(IpAddr)), ); - //TODO(Fix async USB): let mut usb = Command::new("usb") - // .about("Perform the given action over a USBTMC connection") - // .arg( - // Arg::new("addr") - // .help("The instrument address in the form of, for example, `USB:2461:012345` where the second part is the product id, and the third part is the serial number.") - // .required(true) - // .value_parser(value_parser!(UsbtmcAddr)), - // ); - for arg in additional_args { lan = lan.arg(arg.clone()); - //TODO(Fix async USB): usb = usb.arg(arg.clone()); } - command.subcommand(lan) //TODO(Fix async USB): .subcommand(usb) + command.subcommand(lan) } #[must_use] @@ -469,7 +455,6 @@ fn main() -> anyhow::Result<()> { #[derive(Debug)] enum ConnectionType { Lan(SocketAddr), - Usb(UsbtmcAddr), } impl ConnectionType { @@ -489,16 +474,6 @@ impl ConnectionType { Ok(Self::Lan(socket_addr)) } - Some(("usb", sub_matches)) => { - let usb_addr: UsbtmcAddr = sub_matches - .get_one::("addr") - .ok_or_else(|| KicError::ArgParseError { - details: "no USB address provided".to_string(), - })? - .clone(); - - Ok(Self::Usb(usb_addr)) - } Some((ct, _sub_matches)) => { println!(); Err(KicError::ArgParseError { @@ -518,9 +493,6 @@ fn connect_sync_instrument(t: ConnectionType) -> anyhow::Result { (Box::new(TcpStream::connect(addr)?) as Box).into() } - ConnectionType::Usb(addr) => { - (Box::new(usbtmc::Stream::try_from(addr)?) as Box).into() - } }; trace!("Synchronously connected to interface"); @@ -539,11 +511,6 @@ fn connect_async_instrument(t: ConnectionType) -> anyhow::Result)?)), - ConnectionType::Usb(addr) => { - tsp_toolkit_kic_lib::protocol::Protocol::Raw(Box::new(AsyncStream::try_from( - Arc::new(usbtmc::Stream::try_from(addr)?) as Arc, - )?)) - } }; trace!("Asynchronously connected to interface"); @@ -926,7 +893,6 @@ fn terminate(args: &ArgMatches) -> anyhow::Result<()> { return Err(e.into()); } } - ConnectionType::Usb(_) => {} } info!("Operations terminated"); diff --git a/tests/typescript/config.ts b/tests/typescript/config.ts index 6e4d525..2d44910 100644 --- a/tests/typescript/config.ts +++ b/tests/typescript/config.ts @@ -66,7 +66,6 @@ export enum TrebInstrumentModel { } export enum ConnectionType { - USB = "USB", LAN = "LAN", VISA = "VISA", }