Struct InstrumentHandle

Source
pub struct InstrumentHandle<Ctx: UsbContext> {
    pub instrument: Instrument<Ctx>,
    pub usbtmc_capabilities: USBTMCCapabilities,
    pub usb488_capabilities: Option<USB488Capabilities>,
    pub scpi_id: Option<String>,
    /* private fields */
}

Fields§

§instrument: Instrument<Ctx>§usbtmc_capabilities: USBTMCCapabilities§usb488_capabilities: Option<USB488Capabilities>§scpi_id: Option<String>

Implementations§

Source§

impl<Ctx: UsbContext> InstrumentHandle<Ctx>

Source

pub fn get_max_transfer_size(&self) -> u32

Source

pub fn set_max_transfer_size(&mut self, max_transfer_size: u32)

Examples found in repository?
examples/u2000a.rs (line 40)
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}
Source

pub fn get_term_char(&self) -> Option<u8>

Source

pub fn set_term_char(&mut self, term_char: Option<u8>) -> TMCResult<()>

Examples found in repository?
examples/u2000a.rs (line 41)
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}
Source

pub fn get_timeout(&self) -> Duration

Source

pub fn set_timeout(&mut self, timeout: Duration)

Source

pub fn clear(&mut self) -> TMCResult<()>

Source

pub fn pulse(&self) -> TMCResult<()>

Examples found in repository?
examples/list_instruments.rs (line 22)
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}
Source

pub fn write_raw(&mut self, data: &[u8]) -> TMCResult<()>

Write a command message to the instrument

Source

pub fn read_raw(&mut self, transfer_size: Option<u32>) -> TMCResult<Vec<u8>>

Read response data from the instrument

Source

pub fn read(&mut self, transfer_size: Option<u32>) -> TMCResult<String>

Read UTF-8 response data from the instrument

Source

pub fn write(&mut self, message: &str) -> TMCResult<()>

Write a UTF-8 command message to the instrument

Examples found in repository?
examples/u2000a.rs (line 43)
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}
Source

pub fn ask(&mut self, data: &str) -> TMCResult<String>

Write a UTF-8 command message to the instrument and read a UTF-8 response

Examples found in repository?
examples/u2000a.rs (line 45)
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}
Source

pub fn ask_raw(&mut self, data: &[u8]) -> TMCResult<Vec<u8>>

Write a command message to the instrument and read a response

Trait Implementations§

Source§

impl<Ctx: UsbContext> Drop for InstrumentHandle<Ctx>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Ctx> Freeze for InstrumentHandle<Ctx>
where Ctx: Freeze,

§

impl<Ctx> RefUnwindSafe for InstrumentHandle<Ctx>
where Ctx: RefUnwindSafe,

§

impl<Ctx> Send for InstrumentHandle<Ctx>

§

impl<Ctx> Sync for InstrumentHandle<Ctx>

§

impl<Ctx> Unpin for InstrumentHandle<Ctx>
where Ctx: Unpin,

§

impl<Ctx> UnwindSafe for InstrumentHandle<Ctx>
where Ctx: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.