4 releases
Uses new Rust 2024
new 0.2.1 | Apr 19, 2025 |
---|---|
0.2.0 | Apr 17, 2025 |
0.1.2 | Apr 16, 2025 |
0.1.0 | Apr 15, 2025 |
#11 in #instrument
304 downloads per month
125KB
3K
SLoC
linux-gpib-rs
Low-level wrapper for Linux GPIB.
Documentation for the functions comes from Linux GPIB Reference. At the moment, only the 'Traditional' API Functions are wrapped.
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
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
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.
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(())
}
Dependencies
~0.2–8MB
~66K SLoC