07-18-2016 04:06 PM
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.
Solved! Go to Solution.
07-20-2016 11:26 AM
here there is a document, just in case you haven't review it yet: http://www.ni.com/product-documentation/2835/en/
07-20-2016 12:21 PM
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.