Configuring a Stop Trigger using NI-DAQmx for LabVIEW

Updated Nov 13, 2023

Reported In


  • LabVIEW


  • NI-DAQmx

Issue Details

I have an NI DAQ device, and I want to use NI-DAQmx with support for LabVIEW to send a signal to the device telling it when to start and stop acquiring data. How can I do this?


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 Trigger

Reference 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.

Additional Information

Acquiring Continuously with a Reference Trigger
By default, DAQmx will pick a buffer size exactly big enough to fit the total number of samples to read (e.g. the buffer will be size 42 in the example described above). 

In order for the DAQmx application to be able to pull continuous samples from the buffer while waiting for the reference trigger, two other modifications are necessary:
  1. Use DAQmx Configure Input Buffer to manually change the buffer size of the DAQmx application after configuring the timing properties. 
  2. Set the property DAQmx Read»Relative To to modify the read position. By default, this property is set to First Pretrigger Sample when using a reference trigger. By setting it to Current Read Position, DAQmx Read will read samples that are being put into the buffer after the start trigger occurs, just . If this is not changed, the DAQmx Read will wait until the reference trigger is received before it was can retrieve samples from the buffer.
  3. Set the property Analog Input»General Properties»Advanced»Data Transfer and Memory»DataTransfer Request Condition Property to Onboard Memory Not Empty. This is to ensure that data is transferred directly to the buffer as long as it is available inside the device onboard memory.