There are examples that do exactly what you are explaining that get installed with the NI-DAQ driver. Depending on the API (LabVIEW, C, etc.) you are using and the version of the driver (NI-DAQmx, Traditional NI-DAQ), the examples will be called different things and found in different places.
Basically, you want to find an example that does Analog Input With Reference Triggering. If you are using LabVIEW, then launch the Example Finder and look for an example called Acq&Graph Voltage-Int Clk-Dig Ref.vi (if you're using DAQmx) or Acquire N Scans Digital Trig.vi (if you're using Traditional NI-DAQ).
Jared A