1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//!
//! Wrapper for Linux GPIB.
//!
//! Documentation for the functions comes from [Linux GPIB Reference](https://linux-gpib.sourceforge.io/doc_html/reference.html).
//!
//! ## Requirements
//!
//! This crate needs to link to an installed linux-gpib user library. It will look for `gpib/ib.h` in either `/usr/include` or `/usr/local/include`,
//! and for `libgpib.so` in either `/usr/lib` or `/usr/local/lib`.
//!
//!
//! ## Example
//!
//! Add dependencies below to `Cargo.toml`
//!
//! ```toml
//! linux-gpib-rs = { version = "0.2", features = ["async-tokio"] }
//! ```
//!
//! Codes below will connect to the instrument on `GPIB0::1::INSTR` and print out its `*IDN?` response.
//!
//! **Synchronous example with Multidevice API**
//!
//! ```rust
//! use linux_gpib_rs::instrument::Board;
//! use linux_gpib_rs::types::IbSendEOI;
//! use std::error::Error;
//!
//! fn main() -> Result<(), Box<dyn Error>> {
//! let board = Board::with_board_number(0);
//! let instruments = board.find_listeners()?;
//! board.send_list(&instruments, b"*IDN?\n", IbSendEOI::default())?;
//! for instr in instruments {
//! let iden = instr.receive()?;
//! println!("{:>20} {}", instr.visa_string(), iden.trim());
//! }
//! Ok(())
//! }
//! ```
//!
//! **Asynchronous example**
//!
//! Same thing with asynchronous API.
//!
//! ```rust
//! use linux_gpib_rs::instrument::{Parameters, Board};
//! use linux_gpib_rs::error::GpibError;
//! use tokio::task::JoinSet;
//! use std::error::Error;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! let board = Board::with_board_number(0);
//! let instruments = board.find_listeners()?;
//! let mut set = JoinSet::<Result<(String, String), GpibError>>::new();
//! for instr in instruments {
//! let handle = instr.open(Parameters::default())?;
//! let visa_string = instr.visa_string();
//! set.spawn(async move {
//! let iden = handle.query("*IDN?\n").await?;
//! Ok((visa_string, iden))
//! });
//! }
//! while let Some(Ok(val)) = set.join_next().await {
//! if let Ok((visa_string, iden)) = val {
//! println!("{:>20} {}", visa_string, iden.trim());
//! }
//! }
//! Ok(())
//! }
//! ```