uldaqrs 0.2.0

Safe Rust bindings for the uldaq library (Measurement Computing / Data Translation DAQ devices)
Documentation
//! # Safe Rust bindings for the uldaq library
//!
//! This crate provides safe, ergonomic bindings to the
//! [uldaq](https://github.com/mccdaq/uldaq) library, used for interacting with
//! Measurement Computing / Data Translation DAQ devices (such as the DT9837
//! series) on Linux.
//!
//! The unsafe FFI layer lives in the [`uldaq-sys`] crate; this crate wraps it
//! in a safe API:
//!
//! - [`get_device_inventory`] enumerates the connected devices.
//! - [`DaqDevice`] is a RAII handle to a device: it is created with
//!   [`DaqDevice::create`], connected with [`DaqDevice::connect`], and
//!   automatically disconnected and released when dropped.
//! - [`DaqDevice::daq_in_scan`] / [`DaqDevice::a_out_scan`] start continuous
//!   scans into caller-provided `f64` buffers, with
//!   [`DaqDevice::daq_in_scan_status`] / [`DaqDevice::a_out_scan_status`] to
//!   poll their progress and the corresponding stop functions to end them.
//!
//! ## Device setup
//!
//! Before starting a scan, input channels are typically configured with
//! [`DaqDevice::set_ai_sensor_sensitivity`],
//! [`DaqDevice::set_ai_coupling_mode`] and
//! [`DaqDevice::set_ai_iepe_mode`].
//!
//! ## Example
//!
//! ```no_run
//! use uldaqrs::{
//!     CouplingMode, DaqDevice, DaqDeviceDescriptor, DaqInChanDescriptor, DaqInScanFlag,
//!     DaqDeviceInterface, IepeMode, Range, ScanOption, get_device_inventory,
//! };
//!
//! // 1. Find a device by name
//! let devs = get_device_inventory(DaqDeviceInterface::ANY)?;
//! let desc: DaqDeviceDescriptor = devs
//!     .iter()
//!     .find(|d| d.product_name.contains("DT9837"))
//!     .cloned()
//!     .ok_or("No DT9837 device found")?;
//!
//! // 2. Create and connect
//! let dev = DaqDevice::create(&desc)?;
//! dev.connect()?;
//!
//! // 3. Configure the input channels
//! for ch in 0..4u32 {
//!     dev.set_ai_sensor_sensitivity(ch, 1.0)?;
//!     dev.set_ai_coupling_mode(ch, CouplingMode::Ac)?;
//!     dev.set_ai_iepe_mode(ch, IepeMode::Enabled)?;
//! }
//!
//! // 4. Start a continuous scan of 4 channels, 1024 samples per channel
//! let channels = (0..4)
//!     .map(|ch| DaqInChanDescriptor::analog_se(ch, Range::Bip1Volts))
//!     .collect::<Vec<_>>();
//! let mut data = vec![0.0f64; channels.len() * 1024];
//! let actual_rate = dev.daq_in_scan(
//!     &channels,
//!     1024,
//!     48000.0,
//!     ScanOption::CONTINUOUS,
//!     DaqInScanFlag::DEFAULT,
//!     &mut data,
//! )?;
//!
//! // 5. ... poll dev.daq_in_scan_status() and process `data` ...
//!
//! dev.daq_in_scan_stop()?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Prerequisites
//!
//! This crate requires `libusb-1.0` to be installed and is currently only
//! working on Linux systems. Only tested on Linux Mint 22.1 xia.
//!
//! Install the `libusb` library and header files with:
//!
//! ```bash
//! sudo apt install libusb-1.0-0-dev
//! ```
//!
//! ## Author information
//!
//! - [J.A. de Jong (Redu-Sone B.V. / ASCEE)](mailto:j.a.dejong@ascee.nl)

mod device;
mod error;
mod types;

pub use device::{get_device_inventory, DaqDevice, DaqDeviceDescriptor};
pub use error::{check, Error, Result, UlError};
pub use types::*;