Solution
DAQmx does not provide a direct way to generate a stop trigger; however, by using a reference trigger and modifying the read position, you can create the equivalent of a stop trigger in LabVIEW.
To accomplish this, you will need to set up a finite acquisition that is configured to acquire N samples before and after a reference trigger. This is useful because, in order to provide pre-trigger samples for a reference trigger, the DAQmx task will be continually acquiring data while it waits for the reference trigger. This continually-acquired data can still be read using DAQmx Read, even though it is not explicitly part of the configured acquisition.
See the snippet below as an example of how to implement a reference trigger as a stop trigger:
Figure 1: DAQmx Application using Start and Stop Triggers in LabVIEW
Note: The image above is a LabVIEW snippet, which includes LabVIEW 2018 code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
In the example above, an analog input task is created with DAQmx and configured to use two triggers: a start digital edge trigger, and a reference digital edge trigger. The start trigger determines when the task will begin acquiring samples in preparation for the reference trigger, and the reference trigger determines when the task will send the finite number of pre-trigger and post-trigger samples originally requested before stopping the task.
The start and reference triggers can be set up to arrive on the same PFI line if desired, because the DAQmx driver will not wait for the reference trigger until after the start trigger has occurred.
Configuring a Reference TriggerReference triggers require an additional input parameter called
pretrigger samples per channel:
Figure 2: Pretrigger Samples Parameter in LabVIEW
The number of pretrigger samples defines how many of the total samples acquired during the finite acquisition are from before the reference trigger occurred. The rest of the samples in the acquisition are considered
post-trigger samples.
Implicitly, the number of post-trigger samples is equal to:
Post-Trigger Samples =
samples per channel (DAQmx Timing input) -
pretrigger samples per channel (DAQmx Trigger input)
For example, to configure a task that will acquire the minimum number of pretrigger samples (2), followed by 40 post-trigger samples, you would use 42 for samples per channel as an input for DAQmx Timing, and 2 as pretrigger samples per channel on the DAQmx Reference Trigger. The final output of the finite acquisition would look like so:
Figure 3: Visualization of Final DAQmx Read Output with a Reference Trigger
Note: When setting up the timing of the task, there must be at least 2 pre-trigger and 2 post-trigger samples for the reference trigger. Consequently, you will still receive at least two samples after the reference trigger has occurred even if using a reference trigger as a stop trigger -- however, these can be thrown away in post-processing if they are not desired.