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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

syntax for DAQmxRepeatTask

Solved!
Go to solution

I want to build a limited oscilloscope for PCI-4474 with four analog inputs and analog-level trigger on one of those four analog inputs. With CVI example "Acq-IntClk-AnlgStart" I have most of the code.

Next with a start- and stop-button, I want that it repeats acquisition of 1000 samples at the analog-trigger, plots the four curves, and goes for the next trigger. The option (that I found in this forum) for DAQmxSetTrigAttribute retriggerable is (according CVI debug information) not supported for this board.

Next (probably not unique) ideais to split the example in a few functions with the use of DAQmxRegisterDoneEvent:

// create task with a.o.

 DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle));
 DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,gSampsPerChan));
 DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig(gTaskHandle,triggerSource,triggerSlope,triggerLevel));
 DAQmxErrChk (DAQmxSetTrigAttribute (gTaskHandle,DAQmx_AnlgEdge_StartTrig_Hyst,triggerHysteresis));
 DAQmxErrChk (DAQmxGetTaskAttribute(gTaskHandle,DAQmx_Task_NumChans,&gNumChannels));

// start-button with a.o.

   DAQmxErrChk (DAQmxRegisterDoneEvent(gTaskHandle,0,DoneCallback,NULL));
   DAQmxErrChk (DAQmxStartTask(gTaskHandle));

// DoneCallback which is called when task has finished the acquisition of its finite number of samples

  DAQmxErrChk (DAQmxReadAnalogF64(gTaskHandle, ... ...

  DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_DELAYED_DRAW);
  if( numRead>0 )
      for(i=0;i<gNumChannels;i++)
          PlotY(panelHandle,PANEL_GRAPH,&(gData ... ...
  RefreshGraph(panelHandle,PANEL_GRAPH);
  DAQmxErrChk (DAQmxStartTask(gTaskHandle));

This does NOT work unless I insert in this DoneCallback DAQmxStopTask before start the task. This is not what I has expected because the callback function is called because the task has finished. And this is not what I prefer, because the CVI manual reports that stopping and starting a task will reduce the performance. Therefore I have two questions:

Q: can somebody explain (or refer to a text) what the difference is between task-done and task-stopped in combination with task-start?

Q: what is the best syntax for (not yet found) DAQmxRepeatTask when re-trigger is required for synchonisation and when this special attribute is not supperted for PCI-4474?

 

Regards, Jos

 

 

 



 

 

0 Kudos
Message 1 of 3
(2,761 Views)
Solution
Accepted by JGS

Hi Jos,

 

Here's what the NI-DAQmx Help says about task done:

 

When Is A Task Done?

If the measurement or generation is finite, the task is done when you acquire or generate the final sample or when you call the Stop Task function/VI. If the measurement or generation is continuous (including on-demand timing), the task is not done until you call the Stop Task function/VI. In addition, the task is done if a fatal error is generated while performing the measurement or generation, or you abort the measurement or generation. Check for errors and warnings to verify the task completed successfully.

 

> This does NOT work unless I insert in this DoneCallback DAQmxStopTask before start the task. This is not what I has expected because the callback function is called because the task has finished.

 

The callback function is called because the task is finite and the final sample has been acquired. Acquiring the final sample doesn't automatically transition the task from the "running" state to the "committed" state, so you still have to stop the task before you can start it again. See the section of the NI-DAQmx Help entitled "Task State Model" for an explanation of the different states.

 

> And this is not what I prefer, because the CVI manual reports that stopping and starting a task will reduce the performance.

 

Yes, but in this case I think stopping is necessary. In other cases, it's not necessary. For example, you wouldn't want to stop and start the task between every sample.

 

There is a way to reduce the overhead of stopping and starting the task: commit the task by calling DAQmxTaskControl(..., DAQmx_Val_Task_Commit) up front. This way, you don't waste time uncommitting, unreserving, re-reserving, and re-committing the task every time.

 

Anyway, does the performance meet your requirements? If not, what are your performance requirements?

 

Brad

---
Brad Keryan
NI R&D
Message 2 of 3
(2,750 Views)

Thanks for the clear reply.

Yes, the performance is sufficient for today for viewing the "oscilloscope". However with information packets of typical 1 ms duration, I assume that much of the data is missing. From you answer, I will try a different approach when I need high performance.

 

0 Kudos
Message 3 of 3
(2,741 Views)