Trait nicompiler_backend::device::BaseDevice
source · pub trait BaseDevice {
Show 35 methods
// Required methods
fn channels(&self) -> &HashMap<String, Channel>;
fn name(&self) -> &str;
fn task_type(&self) -> TaskType;
fn samp_rate(&self) -> f64;
fn samp_clk_src(&self) -> Option<&str>;
fn trig_line(&self) -> Option<&str>;
fn export_trig(&self) -> Option<bool>;
fn ref_clk_line(&self) -> Option<&str>;
fn export_ref_clk(&self) -> Option<bool>;
fn ref_clk_rate(&self) -> Option<f64>;
fn channels_(&mut self) -> &mut HashMap<String, Channel>;
fn samp_clk_src_(&mut self) -> &mut Option<String>;
fn trig_line_(&mut self) -> &mut Option<String>;
fn export_trig_(&mut self) -> &mut Option<bool>;
fn ref_clk_line_(&mut self) -> &mut Option<String>;
fn export_ref_clk_(&mut self) -> &mut Option<bool>;
fn ref_clk_rate_(&mut self) -> &mut Option<f64>;
// Provided methods
fn cfg_samp_clk_src(&mut self, src: &str) { ... }
fn cfg_trig(&mut self, trig_line: &str, export_trig: bool) { ... }
fn cfg_ref_clk(
&mut self,
ref_clk_line: &str,
ref_clk_rate: f64,
export_ref_clk: bool
) { ... }
fn editable_channels(&self) -> Vec<&Channel> { ... }
fn editable_channels_(&mut self) -> Vec<&mut Channel> { ... }
fn add_channel(&mut self, name: &str) { ... }
fn is_compiled(&self) -> bool { ... }
fn is_edited(&self) -> bool { ... }
fn is_fresh_compiled(&self) -> bool { ... }
fn clear_edit_cache(&mut self) { ... }
fn clear_compile_cache(&mut self) { ... }
fn compile(&mut self, stop_pos: usize) { ... }
fn compiled_channels(
&self,
require_streamable: bool,
require_editable: bool
) -> Vec<&Channel> { ... }
fn compiled_stop_time(&self) -> f64 { ... }
fn edit_stop_time(&self) -> f64 { ... }
fn fill_signal_nsamps(
&self,
start_pos: usize,
end_pos: usize,
nsamps: usize,
buffer: &mut Array2<f64>,
require_streamable: bool,
require_editable: bool
) { ... }
fn calc_signal_nsamps(
&self,
start_pos: usize,
end_pos: usize,
nsamps: usize,
require_streamable: bool,
require_editable: bool
) -> Array2<f64> { ... }
fn unique_port_numbers(&self) -> Vec<usize> { ... }
}
Expand description
The BaseDevice
trait defines the fundamental operations and attributes of a National Instruments (NI) device.
This trait abstracts the common functionalities that an NI device should possess, regardless of its specific hardware details or task type. Implementers of this trait will have access to core functionalities like channel management, device status checks, signal compilation, and more.
Typical Use
A type implementing BaseDevice
is primarily used to interact with the associated NI hardware, manage its channels, and perform operations like signal generation, editing, and compilation.
Trait Methods and Their Functionality:
-
Field methods: These provide direct access to the properties of a device, such as its channels, physical name, sampling rate, and various configuration parameters.
-
Synchronization configuration: Customize the synchronization behavior of devices via
BaseDevice::cfg_trig
,BaseDevice::cfg_ref_clk
,BaseDevice::cfg_samp_clk_src
. SeeDevice
for more details. -
Channel management: Methods like
BaseDevice::editable_channels
,BaseDevice::editable_channels_
, andBaseDevice::add_channel
allow for the retrieval and manipulation of channels associated with the device. -
Device status checks: Methods like
BaseDevice::is_compiled
,BaseDevice::is_edited
, andBaseDevice::is_fresh_compiled
enable checking the compilation and editing status of the device’s channels. -
Cache operations: The methods
BaseDevice::clear_edit_cache
andBaseDevice::clear_compile_cache
are used to clear the edit and compile caches of the device’s channels, respectively. -
Compilation: The
BaseDevice::compile
method takes care of the signal compilation process for the device’s channels. For Digital Output (DO) channels, it provides additional functionality to merge line channels into port channels. -
Signal generation: The
BaseDevice::fill_signal_nsamps
andBaseDevice::calc_signal_nsamps
methods are central to signal generation, allowing for the sampling of float-point values from compiled instructions based on various criteria. -
Utility functions: Methods like
BaseDevice::unique_port_numbers
offer utility functionalities specific to certain task types, aiding in operations like identifying unique ports in Digital Output (DO) devices.
Implementing BaseDevice
:
When creating a new type that represents an NI device, implementing this trait ensures that the type has all the necessary methods and behaviors typical of NI devices. Implementers can then extend or override these methods as necessary to provide device-specific behavior or optimizations.
Required Methods§
fn channels(&self) -> &HashMap<String, Channel>
fn name(&self) -> &str
fn task_type(&self) -> TaskType
fn samp_rate(&self) -> f64
fn samp_clk_src(&self) -> Option<&str>
fn trig_line(&self) -> Option<&str>
fn export_trig(&self) -> Option<bool>
fn ref_clk_line(&self) -> Option<&str>
fn export_ref_clk(&self) -> Option<bool>
fn ref_clk_rate(&self) -> Option<f64>
fn channels_(&mut self) -> &mut HashMap<String, Channel>
fn samp_clk_src_(&mut self) -> &mut Option<String>
fn trig_line_(&mut self) -> &mut Option<String>
fn export_trig_(&mut self) -> &mut Option<bool>
fn ref_clk_line_(&mut self) -> &mut Option<String>
fn export_ref_clk_(&mut self) -> &mut Option<bool>
fn ref_clk_rate_(&mut self) -> &mut Option<f64>
Provided Methods§
sourcefn cfg_samp_clk_src(&mut self, src: &str)
fn cfg_samp_clk_src(&mut self, src: &str)
Configures the sample clock source for the device.
This method sets the samp_clk_src
field of the device to the provided source string.
Arguments
src
- The name of the sample clock source.
sourcefn cfg_trig(&mut self, trig_line: &str, export_trig: bool)
fn cfg_trig(&mut self, trig_line: &str, export_trig: bool)
Configures the trigger settings for the device.
Depending on the value of export_trig
, this method either:
- Exports the device task’s start trigger to
trig_line
(ifexport_trig
istrue
), or - Imports the device task’s start trigger from
trig_line
(ifexport_trig
isfalse
).
Arguments
trig_line
- The trigger line identifier.export_trig
- A boolean that determines whether to export or import the trigger.
sourcefn cfg_ref_clk(
&mut self,
ref_clk_line: &str,
ref_clk_rate: f64,
export_ref_clk: bool
)
fn cfg_ref_clk( &mut self, ref_clk_line: &str, ref_clk_rate: f64, export_ref_clk: bool )
Configures the reference clock settings for the device.
If export_ref_clk
is set to true
, this method:
- Exports the device’s 10MHz on-board reference clock to
ref_clk_line
, - Asserts that
ref_clk_rate
is set to 1e7 (10MHz).
If export_ref_clk
is set to false
, this method:
- Sets the device’s reference clock to the designated line and rate provided by the arguments.
Arguments
ref_clk_line
- The line or channel to import or export the device’s reference clock.ref_clk_rate
- The rate of the reference clock in Hz.export_ref_clk
- A boolean that determines whether to export (iftrue
) or import (iffalse
) the reference clock.
sourcefn editable_channels(&self) -> Vec<&Channel>
fn editable_channels(&self) -> Vec<&Channel>
Returns a vector of references to editable channels
sourcefn editable_channels_(&mut self) -> Vec<&mut Channel>
fn editable_channels_(&mut self) -> Vec<&mut Channel>
Returns a vector of mutable references to editable channels
sourcefn add_channel(&mut self, name: &str)
fn add_channel(&mut self, name: &str)
Adds a new channel to the device.
This base method validates the provided name
based on the device’s task_type
to ensure it adheres to the expected naming convention for the respective task type.
Naming Conventions:
- For
TaskType::AO
: Channels should be named following the pattern “ao(number)” (e.g., “ao0”, “ao1”). - For
TaskType::DO
: Channels should be named following the pattern “port(number)/line(number)” (e.g., “port0/line1”).
Panics
- If the provided
name
does not adhere to the expected naming convention for the associated task type. - If a channel with the same
name
already exists within the device.
Arguments
name
: Name of the channel as seen by the NI driver, which must adhere to the naming conventions detailed above.
sourcefn is_compiled(&self) -> bool
fn is_compiled(&self) -> bool
A device is compiled if any of its editable channels are compiled.
Also see BaseChannel::is_compiled
sourcefn is_edited(&self) -> bool
fn is_edited(&self) -> bool
A device is marked edited if any of its editable channels are edited.
Also see BaseChannel::is_edited
sourcefn is_fresh_compiled(&self) -> bool
fn is_fresh_compiled(&self) -> bool
A device is marked fresh-compiled if all if its editable channels are freshly compiled.
Also see BaseChannel::is_fresh_compiled
sourcefn clear_edit_cache(&mut self)
fn clear_edit_cache(&mut self)
Clears the edit-cache fields for all editable channels.
Also see BaseChannel::clear_edit_cache
sourcefn clear_compile_cache(&mut self)
fn clear_compile_cache(&mut self)
Clears the compile-cache fields for all editable channels.
Also see BaseChannel::clear_compile_cache
sourcefn compile(&mut self, stop_pos: usize)
fn compile(&mut self, stop_pos: usize)
Compiles all editable channels to produce a continuous instruction stream.
The method starts by compiling each individual editable channel to obtain a continuous
stream of instructions (also seeBaseChannel::compile
).
If the device type is TaskType::DO
(Digital Output), an additional
processing step is performed. All the line channels belonging to the same port are merged
into a single, streamable port channel that is non-editable. This aggregated port channel
contains constant instructions whose integer values are determined by the combined state
of all the lines of the corresponding port. Specifically, the n
th bit of the integer
value of the instruction corresponds to the boolean state of the n
th line.
Port Channel Aggregation
Each instruction inside the aggregated port channel is a constant instruction. The value of
this instruction is an integer, where its n
th bit represents the boolean state of the
n
th line. This way, the combined state of all lines in a port is efficiently represented
by a single integer value, allowing for streamlined execution and efficient data transfer.
Arguments
stop_pos
: The stop position used to compile the channels.
sourcefn compiled_channels(
&self,
require_streamable: bool,
require_editable: bool
) -> Vec<&Channel>
fn compiled_channels( &self, require_streamable: bool, require_editable: bool ) -> Vec<&Channel>
Returns a vector of compiled channels based on the given criteria.
Filters the device’s channels based on their compiled state and optional properties such as streamability and editability.
Arguments
require_streamable
: Iftrue
, only compiled channels marked as streamable will be included in the result.require_editable
: Iftrue
, only compiled channels marked as editable will be included in the result.
Returns
A Vec
containing references to the channels that match the provided criteria.
sourcefn compiled_stop_time(&self) -> f64
fn compiled_stop_time(&self) -> f64
Calculates the maximum stop time among all compiled channels.
Iterates over all the compiled channels in the device, regardless of their streamability or
editability, and determines the maximum stop time.
See BaseChannel::compiled_stop_time
for more information.
Returns
A f64
representing the maximum stop time (in seconds) across all compiled channels.
sourcefn edit_stop_time(&self) -> f64
fn edit_stop_time(&self) -> f64
Calculates the maximum stop time among all editable channels.
Iterates over all the editable channels in the device and determines the maximum stop time.
See BaseChannel::edit_stop_time
for more information.
Returns
A f64
representing the maximum stop time (in seconds) across all editable channels.
sourcefn fill_signal_nsamps(
&self,
start_pos: usize,
end_pos: usize,
nsamps: usize,
buffer: &mut Array2<f64>,
require_streamable: bool,
require_editable: bool
)
fn fill_signal_nsamps( &self, start_pos: usize, end_pos: usize, nsamps: usize, buffer: &mut Array2<f64>, require_streamable: bool, require_editable: bool )
Generates a signal by sampling float-point values from compiled instructions.
This method fills a given buffer with signal values based on the compiled instructions of the device’s channels. Depending on the requirements, it can either generate signals intended for actual driver writing or for debugging editing intentions.
Arguments
start_pos
: The starting position in the sequence of compiled instructions.end_pos
: The ending position in the sequence of compiled instructions.nsamps
: The number of samples to generate.buffer
: A mutable reference to a 2D array. The first axis corresponds to the channel index and the second axis corresponds to the sample index.require_streamable
: Iftrue
, only signals from channels marked as streamable will be generated.require_editable
: Iftrue
, signals will be generated according to editing intentions for debugging purposes.
Panics
This method will panic if:
- The first dimension of the buffer does not match the number of channels that fulfill the provided requirements.
- The second dimension of the buffer does not match the provided
nsamps
value.
TODO Notes
The generation of signals from channels can be parallelized for performance improvements.
sourcefn calc_signal_nsamps(
&self,
start_pos: usize,
end_pos: usize,
nsamps: usize,
require_streamable: bool,
require_editable: bool
) -> Array2<f64>
fn calc_signal_nsamps( &self, start_pos: usize, end_pos: usize, nsamps: usize, require_streamable: bool, require_editable: bool ) -> Array2<f64>
Computes and returns the signal values for specified channels in a device.
This method calculates the signal values by sampling float-point values from compiled instructions of the device’s channels. Depending on the requirements, the signal can be either intended for actual driver writing or for debugging editing intentions. For AO (Analog Output) devices, the returned buffer will contain time data.
Arguments
start_pos
: The starting position in the sequence of compiled instructions.end_pos
: The ending position in the sequence of compiled instructions.nsamps
: The number of samples to generate.require_streamable
: Iftrue
, only signals from channels marked as streamable will be generated.require_editable
: Iftrue
, signals will be generated according to editing intentions for debugging purposes.
Returns
A 2D array with the computed signal values. The first axis corresponds to the channel index and the second axis corresponds to the sample index.
Panics
This method will panic if:
- There are no channels that fulfill the provided requirements.
- The device’s task type is not AO (Analog Output) when initializing the buffer with time data.
sourcefn unique_port_numbers(&self) -> Vec<usize>
fn unique_port_numbers(&self) -> Vec<usize>
Retrieves a list of unique port numbers from the device’s channels.
This utility function is primarily used with DO (Digital Output) devices to identify and operate on unique ports. It scans through the compiled channels of the device, filtering for those that are editable, and extracts the unique port numbers associated with them.
Returns
A vector of unique port numbers identified in the device’s channels.
Panics
The method will panic if it’s invoked on a device that is not of task type DO.