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: 

DAQmx : configure continuous digital acquisition with start and stop trigger

We have a NI9184 chassis with a NI9234 module and NI9421 DI module. We would like to use digital trigger to start and stop data acquisition and measure analog acceleration data.

 

We used the process described in this link. We are using the C API provided by NIdaqmx.

Below is our Python code(C-API) which is replicating the VI given in link mentioned above.

 

1. Create an analog input channel to measure acceleration data

DAQmxCreateAIAccelChan(taskHandle, "cDAQ9184-1B20914Mod4/ai1","",
                                   DAQmx_Val_Cfg_Default,-50.0, 50.0,
                                   DAQmx_Val_AccelUnit_g, 100.0,
                                   DAQmx_Val_mVoltsPerG,
                                   DAQmx_Val_Internal,0.0021,
                                   None)

2. Set the sample clock rate at 51200 samples/second and finite samples per channel to be 5120

DAQmxCfgSampClkTiming(taskHandle,"",51200.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,5120)

3. Set the buffer size to be 10 times the number of samples per channel, i.e., 51200

DAQmxCfgInputBuffer(taskHandle, 51200)

4a. Configure the start trigger to start filling the buffer after receiving a digital edge on PFI 0

DAQmxCfgDigEdgeStartTrig(taskHandle,"/cDAQ9184-1B20914Mod2/PFI0", DAQmx_Val_Rising)

4b. Configure the reference trigger (stop trigger) to stop filling the buffer (plus the number of post-trigger samples which in our case is 5120-2 = 5118) after receiving a digital edge on PFI 1

DAQmxCfgDigEdgeRefTrig (taskHandle,"/cDAQ9184-1B20914Mod2/PFI1", DAQmx_Val_Rising,2)


5. Set the buffer read position to "Current Read Position"

DAQmxSetReadRelativeTo(taskHandle, DAQmx_Val_CurrReadPos)


6. Start the acquisition

DAQmxStartTask(taskHandle)


7a. Read until the stop trigger is received. If task is done (stop trigger has been received) then compare the number of samples left in the buffer with the number of samples to read.

7b. If the number of samples in buffer is greater than 0, continue to read. If buffer is empty and task is done, loop will be stopped.

taskComplete = bool32() #boolean for storing if the task is completed
avail = uint32() # integer variable for storing available samples per channel in buffer
data = numpy.zeros(5120) # data array into which analog data will be written after it is read
readDI = int32()
readBytes = int32()
tot = [] # an empty list in which data from each call to read function is appended
while True:
   print 'Started Reading From Buffer'
   DAQmxReadAnalog64(taskHandle, 5120, -1, DAQmx_Val_GroupByChannel, data, 5120, byref(readDI), byref(readBytes), None)
   DAQmxGetTaskComplete(taskHandle, byref(taskComplete))
   if taskComplete.value:
      print "Stop Trigger Received: Task Stopped"
      flag=0
      DAQmxGetReadAvailSampPerChan(taskHandle,byref(avail))
      while avail > 0:
          DAQmxReadAnalog64(taskHandle, 5120, -1, DAQmx_Val_GroupByChannel, data, 5120, byref(readDI), byref(readBytes), None)
          tot.append(data)
          DAQmxGetReadAvailSampPerChan(taskHandle,byref(avail))
      break
   tot.append(dataDI)

 

 

8. Clear the task and check for errors

if taskHandle:
# DAQmx Stop Code
DAQmxStopTask(taskHandle)
DAQmxClearTask(taskHandle)


However, when we run the above script, we get the following error:
"Finite acquisition or generation has been stopped before the requested number of samples were acquired or generated in function DAQmxStopTask"

 

Could you please explain why we are getting the above error. Also kindly advise if we are doing something incorrect in the procedure described above and the necessary corrective action.

0 Kudos
Message 1 of 2
(3,043 Views)

Hi Kampan,

 

Are you sending in the stop trigger on the PFI line before all the samples have been received? To me, the error sounds like you are stopping the acquisition (sending the stop trigger) before acquiring samples, is this a possibility? Are you sending anything into PFI1?

 

Thanks,

Will.i.am10

0 Kudos
Message 2 of 2
(2,981 Views)