pub trait StreamableDevice:
BaseDevice
+ Sync
+ Send {
// Provided methods
fn stream_task(
&self,
sem: &Arc<Semaphore>,
num_devices: usize,
stream_buftime: f64,
nreps: usize,
) { ... }
fn cfg_task_channels(&self, task: &NiTask) { ... }
fn cfg_clk_sync(&self, task: &NiTask, seq_len: &usize) { ... }
}
Expand description
The StreamableDevice
trait extends the nicompiler_backend::BaseDevice
trait of nicompiler_backend::Device
to provide additional functionality for streaming tasks.
Provided Methods§
Sourcefn stream_task(
&self,
sem: &Arc<Semaphore>,
num_devices: usize,
stream_buftime: f64,
nreps: usize,
)
fn stream_task( &self, sem: &Arc<Semaphore>, num_devices: usize, stream_buftime: f64, nreps: usize, )
Streams an instruction signal to the specified NI-DAQ device.
This method is responsible for streaming an instruction signal to a National Instruments (NI) DAQ device
represented by self
. It sets up a new NI-DAQmx task, configures synchronization methods and buffer,
writes the initial chunk of the sequence into the driver buffer, and starts the task, causing the device
to output the signal.
§Parameters
sem
: A semaphore used to synchronize the start triggers between multiple devices. Ensures that threads for secondary devices always start listening for triggers before the primary device starts and exports its start trigger.num_devices
: The total number of NI-DAQ devices involved in the streaming process.stream_buftime
: Duration (in milliseconds) specifying the length of the streaming buffer.nreps
: Number of repetitions for streaming the sequence. Streaming a sequence multiple times in a single call usingnreps
is more efficient than multiple separate calls.
§Behavior
- Asserts that the device has been compiled using
is_compiled
. - Initializes a new
NiTask
and configures the device channels. - Configures the buffer, writing method, clock, and synchronization.
- Writes the initial chunk of the sequence into the driver buffer.
- Starts the task, causing the device to output the signal.
- Continuously streams chunks of the sequence to the device until the entire sequence has been streamed.
- If
nreps
> 1, the sequence is streamed the specified number of times.
The method uses a TickTimer
to measure the time taken for various operations, which can be helpful for
performance analysis.
§Safety and Synchronization
The method uses a semaphore (sem
) to ensure synchronization between multiple devices. Specifically, it ensures
that secondary devices start listening for triggers before the primary device starts and exports its start trigger.
§Note
The method relies on various helper functions and methods, such as is_compiled
, cfg_task_channels
, and
calc_signal_nsamps
, to achieve its functionality. Ensure that all dependencies are correctly set up and
that the device has been properly compiled before calling this method.
Sourcefn cfg_task_channels(&self, task: &NiTask)
fn cfg_task_channels(&self, task: &NiTask)
Helper function that configures the task channels for the device.
This method is a helper utility designed to configure the task channels based on the device’s task_type
.
It invokes the corresponding DAQmx driver method to set up the channels, ensuring they are correctly initialized
for subsequent operations. This method is invoked by StreamableDevice::stream_task
.
§Parameters
task
: A reference to theNiTask
instance representing the task to be configured.
§Behavior
Depending on the device’s task_type
, the method will:
- For
TaskType::AO
: Iterate through the compiled, streamable channels and invoke thecreate_ao_chan
method for each channel. - For
TaskType::DO
: Iterate through the compiled, streamable channels and invoke thecreate_do_chan
method for each channel.
The channel names are constructed using the format /{device_name}/{channel_name}
.
Sourcefn cfg_clk_sync(&self, task: &NiTask, seq_len: &usize)
fn cfg_clk_sync(&self, task: &NiTask, seq_len: &usize)
Configures the synchronization and clock behavior for the device.
This method sets up the synchronization behavior of the device, ensuring that its operation is correctly
coordinated with other devices or tasks. It configures the sample clock, start trigger, and reference clocking.
This method is invoked by StreamableDevice::stream_task
.
Refer to nicompiler_backend::Device
for a detailed explanation of synchronization mechanisms and their importance.
§Parameters
task
: A reference to theNiTask
instance representing the task to be synchronized.seq_len
: A reference to the length of the sequence for which synchronization is required.
§Behavior
- Configures the sample clock using the provided
samp_clk_src
andsamp_rate
. - If the device has a trigger line, it configures the start trigger. Primary devices will export the start trigger, while secondary devices will configure their tasks to expect the start trigger.
- Configures reference clocking based on the device’s
ref_clk_line
. Devices that import the reference clock will configure it accordingly, while others will export the signal.