pub fn list_instruments<Ctx: UsbContext>(
context: Ctx,
) -> TMCResult<Vec<Instrument<Ctx>>>Expand description
List detected USBTMC devices
Examples found in repository?
examples/list_instruments.rs (line 10)
6fn main() -> Result<(), Box<dyn Error>> {
7 let context = rusb::Context::new()?;
8
9 let timer = Instant::now();
10 let instruments = list_instruments(context)?;
11
12 if instruments.len() == 0 {
13 println!("no instruments found");
14 } else {
15 for mut instrument in instruments {
16 println!("Found instrument: {}", instrument.read_resource_string()?);
17
18 let handle = instrument.open()?;
19 println!(" USBTMC: {:?}", handle.usbtmc_capabilities);
20 println!(" USB488: {:?}", handle.usb488_capabilities);
21 println!(" SCPI ID: {:?}", handle.scpi_id);
22 println!(" PULSE result: {:?}", handle.pulse());
23 }
24 }
25
26 println!("Time elapsed: {:?}", timer.elapsed());
27 Ok(())
28}More examples
examples/u2000a.rs (line 13)
11fn main() -> Result<(), Box<dyn Error>> {
12 let context = rusb::Context::new()?;
13 let instruments = list_instruments(context)?;
14
15 if instruments.len() == 0 {
16 println!("no instruments found");
17 return Ok(());
18 }
19
20 let mut power_sensor = None;
21
22 for mut instrument in instruments {
23 println!("Found instrument: {}", instrument.read_resource_string()?);
24
25 let handle = instrument.open()?;
26 if let Some(id) = &handle.scpi_id {
27 if id.starts_with("Keysight Technologies,U2000A") {
28 println!("Found power sensor: {}", id);
29 power_sensor = Some(handle);
30 break;
31 } else {
32 println!("This is not the instrument I'm looking for: {}", id);
33 }
34 } else {
35 println!("Sensor does not seem to support SCPI");
36 }
37 }
38
39 if let Some(mut handle) = power_sensor {
40 handle.set_max_transfer_size(1024);
41 handle.set_term_char(Some(b'\n'))?;
42
43 handle.write(&format!("SENS1:FREQ {}\n", FREQ_HZ as u64))?;
44 loop {
45 let power_str = handle.ask("FETCH1?")?;
46 let power = power_str.trim().parse::<f64>()?;
47 println!("{:2.3} dBm", power);
48 }
49 } else {
50 println!("Sorry, didn't find a U2000A sensor");
51 Ok(())
52 }
53}