Skip to main content

Crate uldaqrs

Crate uldaqrs 

Source
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:

§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§

AOutScanFlag
Flags for ulAOutScan.
DaqDevice
A handle to a DAQ device.
DaqDeviceDescriptor
A descriptor of a DAQ device, as returned by the device inventory.
DaqDeviceInterface
The physical connection interface of a DAQ device.
DaqInChanDescriptor
A single input channel descriptor, used with DaqDevice::daq_in_scan.
DaqInScanFlag
Flags for ulDaqInScan.
ScanOption
Scan options, passed to the scan functions. Bits can be combined.
TransferStatus
Information about the progress of a scan operation.
UlError
A raw error code returned by the uldaq library.

Enums§

AiConfigItem
AI configuration items that can be set with DaqDevice::set_ai_config.
AiConfigItemDbl
AI configuration items with a f64 value, set with DaqDevice::set_ai_config_dbl.
CouplingMode
Analog input coupling mode.
DaqInChanType
The type of input channel used with ulDaqInScan.
Error
Errors that can occur when interacting with the uldaq library.
IepeMode
IEPE (constant current) excitation mode.
Range
Analog input / output range.
ScanStatus
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 Result alias for the safe bindings.