Expand description
§Safe Rust bindings for the uldaq library
This crate provides safe, ergonomic bindings to the 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_inventoryenumerates the connected devices.DaqDeviceis a RAII handle to a device: it is created withDaqDevice::create, connected withDaqDevice::connect, and automatically disconnected and released when dropped.DaqDevice::daq_in_scan/DaqDevice::a_out_scanstart continuous scans into caller-providedf64buffers, withDaqDevice::daq_in_scan_status/DaqDevice::a_out_scan_statusto 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
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()?;§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:
sudo apt install libusb-1.0-0-dev§Author information
Structs§
- AOut
Scan Flag - Flags for
ulAOutScan. - DaqDevice
- A handle to a DAQ device.
- DaqDevice
Descriptor - A descriptor of a DAQ device, as returned by the device inventory.
- DaqDevice
Interface - The physical connection interface of a DAQ device.
- DaqIn
Chan Descriptor - A single input channel descriptor, used with
DaqDevice::daq_in_scan. - DaqIn
Scan Flag - Flags for
ulDaqInScan. - Scan
Option - Scan options, passed to the scan functions. Bits can be combined.
- Transfer
Status - Information about the progress of a scan operation.
- UlError
- A raw error code returned by the uldaq library.
Enums§
- AiConfig
Item - AI configuration items that can be set with
DaqDevice::set_ai_config. - AiConfig
Item Dbl - AI configuration items with a
f64value, set withDaqDevice::set_ai_config_dbl. - Coupling
Mode - Analog input coupling mode.
- DaqIn
Chan Type - The type of input channel used with
ulDaqInScan. - Error
- Errors that can occur when interacting with the uldaq library.
- Iepe
Mode - IEPE (constant current) excitation mode.
- Range
- Analog input / output range.
- Scan
Status - The status of a scan operation.
Functions§
- check
- Convert a raw return code from a UL function into a
Result. - get_
device_ inventory - Enumerate the DAQ devices connected to the system that match
interface.
Type Aliases§
- Result
- Convenience
Resultalias for the safe bindings.