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>
impl<Ctx: UsbContext> InstrumentHandle<Ctx>
pub fn get_max_transfer_size(&self) -> u32
Sourcepub fn set_max_transfer_size(&mut self, max_transfer_size: u32)
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}
pub fn get_term_char(&self) -> Option<u8>
Sourcepub fn set_term_char(&mut self, term_char: Option<u8>) -> TMCResult<()>
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}
pub fn get_timeout(&self) -> Duration
pub fn set_timeout(&mut self, timeout: Duration)
pub fn clear(&mut self) -> TMCResult<()>
Sourcepub fn pulse(&self) -> TMCResult<()>
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}
Sourcepub fn write_raw(&mut self, data: &[u8]) -> TMCResult<()>
pub fn write_raw(&mut self, data: &[u8]) -> TMCResult<()>
Write a command message to the instrument
Sourcepub fn read_raw(&mut self, transfer_size: Option<u32>) -> TMCResult<Vec<u8>>
pub fn read_raw(&mut self, transfer_size: Option<u32>) -> TMCResult<Vec<u8>>
Read response data from the instrument
Sourcepub fn read(&mut self, transfer_size: Option<u32>) -> TMCResult<String>
pub fn read(&mut self, transfer_size: Option<u32>) -> TMCResult<String>
Read UTF-8 response data from the instrument
Sourcepub fn write(&mut self, message: &str) -> TMCResult<()>
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}
Sourcepub fn ask(&mut self, data: &str) -> TMCResult<String>
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}
Trait Implementations§
Source§impl<Ctx: UsbContext> Drop for InstrumentHandle<Ctx>
impl<Ctx: UsbContext> Drop for InstrumentHandle<Ctx>
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> 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