Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Data Acquisition using Digital Start Stop Trigger #41

Open
Vik27 opened this issue Jan 29, 2017 · 0 comments
Open

Continuous Data Acquisition using Digital Start Stop Trigger #41

Vik27 opened this issue Jan 29, 2017 · 0 comments

Comments

@Vik27
Copy link

Vik27 commented Jan 29, 2017

We need help regarding using this package for continuous data acquisition using NI cDAQ chassis.

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 at the 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)
  4. Set the buffer read position to "Current Read Position"
    DAQmxSetReadRelativeTo(taskHandle, DAQmx_Val_CurrReadPos)
  5. 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 errorsif 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant