Skip to main content

instrument/
lib.rs

1//! High-level instrument discovery and typed IVI-inspired classes.
2//!
3//! # Quick start (mock, no VISA)
4//!
5//! ```no_run
6//! use instrument::prelude::*;
7//!
8//! let fixture = ScriptedFixture::builder()
9//!     .idn("Acme", "DMM1", "SN1", "1.0")
10//!     .kinds([InstrumentKind::Dmm])
11//!     .on_query(":MEAS:VOLT:DC?", "1.0")
12//!     .build();
13//! let catalog = DeviceCatalog::from_fixture("mock://dmm", fixture)?;
14//! # Ok::<(), instrument::Error>(())
15//! ```
16//!
17//! # Quick start (hardware)
18//!
19//! Requires the `visa` feature (enabled by default).
20//!
21//! ```ignore
22//! use instrument::prelude::*;
23//! let catalog = Discovery::visa()?.scan()?;
24//! ```
25//!
26//! # Quick start (async mock, `tokio` feature)
27//!
28//! ```ignore
29//! use instrument::prelude::*;
30//!
31//! #[tokio::main]
32//! async fn main() -> Result<()> {
33//!     let fixture = ScriptedFixture::builder()
34//!         .idn("Acme", "DMM1", "SN1", "1.0")
35//!         .kinds([InstrumentKind::Dmm])
36//!         .on_query(":MEAS:VOLT:DC?", "1.0")
37//!         .build();
38//!     let catalog = AsyncDeviceCatalog::from_fixture("mock://dmm", fixture).await?;
39//!     let mut dmm = catalog.open_dmm("mock://dmm").await?;
40//!     println!("{} V", dmm.measure_voltage_dc(None).await?);
41//!     Ok(())
42//! }
43//! ```
44//!
45//! See the [user guide](https://josh-hemphill.github.io/instrument-components/),
46//! [getting started](https://josh-hemphill.github.io/instrument-components/getting-started/),
47//! and [async guide](https://josh-hemphill.github.io/instrument-components/rust/async/).
48
49pub mod catalog;
50pub mod device;
51pub mod discovery;
52pub mod mock_backend;
53pub mod prelude;
54
55#[cfg(feature = "tokio")]
56pub mod async_catalog;
57#[cfg(feature = "tokio")]
58pub mod async_device;
59#[cfg(feature = "tokio")]
60pub mod async_discovery;
61
62pub mod classes {
63    pub mod counter;
64    pub mod dc_psu;
65    pub(crate) mod dialect_io;
66    pub mod dmm;
67    pub mod fgen;
68    pub mod power_meter;
69    pub mod scope;
70    pub mod spectrum_analyzer;
71    pub mod switch;
72
73    #[cfg(feature = "tokio")]
74    pub mod async_counter;
75    #[cfg(feature = "tokio")]
76    pub mod async_dc_psu;
77    #[cfg(feature = "tokio")]
78    pub mod async_dmm;
79    #[cfg(feature = "tokio")]
80    pub mod async_fgen;
81    #[cfg(feature = "tokio")]
82    pub mod async_power_meter;
83    #[cfg(feature = "tokio")]
84    pub mod async_scope;
85    #[cfg(feature = "tokio")]
86    pub mod async_spectrum_analyzer;
87    #[cfg(feature = "tokio")]
88    pub mod async_switch;
89
90    pub use counter::Counter;
91    pub use dc_psu::DcPowerSupply;
92    pub use dmm::Dmm;
93    pub use fgen::{FunctionGenerator, Waveform};
94    pub use power_meter::{PowerMeter, PowerUnit};
95    pub use scope::{Oscilloscope, VoltageTrace};
96    pub use spectrum_analyzer::SpectrumAnalyzer;
97    pub use switch::Switch;
98
99    #[cfg(feature = "tokio")]
100    pub use async_counter::AsyncCounter;
101    #[cfg(feature = "tokio")]
102    pub use async_dc_psu::AsyncDcPowerSupply;
103    #[cfg(feature = "tokio")]
104    pub use async_dmm::AsyncDmm;
105    #[cfg(feature = "tokio")]
106    pub use async_fgen::AsyncFunctionGenerator;
107    #[cfg(feature = "tokio")]
108    pub use async_power_meter::AsyncPowerMeter;
109    #[cfg(feature = "tokio")]
110    pub use async_scope::AsyncOscilloscope;
111    #[cfg(feature = "tokio")]
112    pub use async_spectrum_analyzer::AsyncSpectrumAnalyzer;
113    #[cfg(feature = "tokio")]
114    pub use async_switch::AsyncSwitch;
115}
116
117pub use catalog::DeviceCatalog;
118pub use device::DeviceRef;
119pub use discovery::Discovery;
120pub use instrument_core::{
121    self, AccessMode, CommsEvent, CommsEventKind, CommsObserver, ConnectOptions, DeviceHealth,
122    DeviceId, Diagnostics, DiscoveredDevice, Error, Idn, InstrumentKind, InstrumentSession,
123    MockTransport, ProbePolicy, ResourceAddress, Result, ScpiSession, ScriptedFixture, SessionPool,
124    Transport, TransportIdentity,
125};
126
127#[cfg(feature = "tokio")]
128pub use async_catalog::AsyncDeviceCatalog;
129#[cfg(feature = "tokio")]
130pub use async_device::AsyncDeviceRef;
131#[cfg(feature = "tokio")]
132pub use async_discovery::AsyncDiscovery;
133
134#[cfg(feature = "tokio")]
135pub use instrument_core::{
136    AsyncInstrumentSession, AsyncScpiSession, AsyncSessionOpener, AsyncSessionPool, AsyncTransport,
137    DynAsyncTransport,
138};
139
140#[cfg(all(feature = "visa", feature = "tokio"))]
141pub use instrument_visa::{InstrumentTokioAdapter, VisaAsyncSessionOpener, VisaAsyncTransport};
142
143#[cfg(feature = "visa")]
144pub use instrument_visa::{SharedRm, VisaEnumerator, VisaSessionOpener};