From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering with NI USB-6210 and NI-DAQmx in Ansi C/C++

Solved!
Go to solution

Hello,

 

We need to read an analog signal every time there is a trigger signal, but cannot figure out how to get the trigger to work. Here is the code we have come up with so far:

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

...
DAQmxErrChk(DAQmxCreateAIVoltageChan(analogInputTaskHandle, "Dev1/ai0", "AI0", DAQmx_Val_Diff, -10, 10, DAQmx_Val_Volts, NULL));


int32 numSampsPerChan = 20;
uInt64 sampsPerChan = numSampsPerChan;
float64 timeout = 0; //Time in seconds to wait for function to read channel -> 0 try to read once; -1 wait infinitely;
bool32 fillMode = DAQmx_Val_GroupByChannel; // Non-interleaved reading of channel
const uInt32 arraySizeInSamples = 20; // Number of samples which are read
float64 analogValuesFromDevice[arraySizeInSamples];
int32 sampsPerChanRead;
bool32 *reserved = NULL;

 

char startTrigger[256] = "/Dev1/PFI0";
int startEdge = DAQmx_Val_Rising; // rising edge

DAQmxErrChk(DAQmxCfgSampClkTiming(analogInputTaskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 10));

DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(analogInputTaskHandle, startTrigger, startEdge));

 

DAQmxErrChk(DAQmxStartTask(analogInputTaskHandle));

DAQmxErrChk(DAQmxReadAnalogF64(analogInputTaskHandle, numSampsPerChan, timeout, fillMode, analogValuesFromDevice, arraySizeInSamples, &sampsPerChanRead, reserved));

DAQmxErrChk(DAQmxStopTask(analogInputTaskHandle));

// Deallocates memory for the task
DAQmxErrChk(DAQmxClearTask(analogInputTaskHandle));

...

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

This is the error message we receive.

 

DAQmx Error: Reading relative to the reference trigger or relative to the start
of pretrigger samples position before the acquisition is complete.

Wait for the acquisition to complete before reading, or increase your read timeo
ut. Also, make sure the hardware is set up and wired correctly, the signal for
the reference trigger is correct, and that the reference trigger occurs while th
e device is acquiring data.
Property: DAQmx_Read_RelativeTo
Corresponding Value: DAQmx_Val_FirstPretrigSamp


Task Name: ReadAnalogInput

Status Code: -200281

 

Could you tell us how to wait for the acquistion to complete or increase our read timeout? We think those are the problems we are encountering.

 

Thank you for all of your help.

0 Kudos
Message 1 of 3
(3,321 Views)

here there is a document, just in case you haven't review it yet: http://www.ni.com/product-documentation/2835/en/

0 Kudos
Message 2 of 3
(3,294 Views)
Solution
Accepted by topic author mathisma1

Update:

 

We are no longer using a trigger, so this is resolved.

 

We believe we were originally getting the error because we weren't using a TTL signal.

0 Kudos
Message 3 of 3
(3,289 Views)