pub struct Instrument<Ctx: UsbContext> {
pub device: Device<Ctx>,
pub device_desc: DeviceDescriptor,
pub config_desc: ConfigDescriptor,
pub endpoints: TMCInterface,
/* private fields */
}
Expand description
Information about an instrument detected on the USB bus.
Use list_instruments to find all connected instruments. Use Instrument::open to get an InstrumentHandle which can be used to communicate with the instrument.
Fields§
§device: Device<Ctx>
§device_desc: DeviceDescriptor
§config_desc: ConfigDescriptor
§endpoints: TMCInterface
Implementations§
Source§impl<Ctx: UsbContext> Instrument<Ctx>
impl<Ctx: UsbContext> Instrument<Ctx>
Sourcepub fn read_resource_string(&mut self) -> TMCResult<String>
pub fn read_resource_string(&mut self) -> TMCResult<String>
Get the device’s resource string; this may involve connecting to it in order to read its serial number.
Examples found in repository?
examples/list_instruments.rs (line 16)
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 23)
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}
Sourcepub fn open(self) -> TMCResult<InstrumentHandle<Ctx>>
pub fn open(self) -> TMCResult<InstrumentHandle<Ctx>>
Examples found in repository?
examples/list_instruments.rs (line 18)
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 25)
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}
Trait Implementations§
Auto Trait Implementations§
impl<Ctx> Freeze for Instrument<Ctx>where
Ctx: Freeze,
impl<Ctx> RefUnwindSafe for Instrument<Ctx>where
Ctx: RefUnwindSafe,
impl<Ctx> Send for Instrument<Ctx>
impl<Ctx> Sync for Instrument<Ctx>
impl<Ctx> Unpin for Instrument<Ctx>where
Ctx: Unpin,
impl<Ctx> UnwindSafe for Instrument<Ctx>where
Ctx: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more