11-04-2011 02:35 PM - edited 11-04-2011 02:37 PM
Hi all
I have an unexpected behaviour using a USB-6212 card.
The sample code demonstrates that when I execute in sequence two DAQmx analog input tasks, the first one hardware timed, the second one software timed, it happens that the first data readings are all wrong and have the same value for all channels.
The task code is the following:
GetCtrlVal(panelHandle, PANEL_HW, &Switch); if (Switch) { // // First Task: read 10 rows of values with hardware timing // DAQmxCreateTask("", &htAI); DAQmxCreateAIVoltageChan (htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, ""); DAQmxCfgSampClkTiming(htAI,"", SAMPLE_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000); DAQmxRegisterEveryNSamplesEvent (htAI, DAQmx_Val_Acquired_Into_Buffer, SAMPLE_RATE, 0, RefreshCB, NULL); DAQmxStartTask(htAI); Delay(1.0); DAQmxStopTask(htAI); DAQmxClearTask(htAI); } // // Second Task:read 10 rows of values with software timing // DAQmxCreateTask("", &htAI); DAQmxCreateAIVoltageChan(htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, ""); DAQmxStartTask(htAI); for (i=1; i<=10; i++) { DAQmxReadAnalogF64(htAI, 1.0, 10.0, DAQmx_Val_GroupByChannel, AcqVoltRow, HW_AI_CHANNELS, &read, 0); SetTableCellRangeVals (panelHandle,PANEL_SOFT, MakeRect(i, 1, 1, HW_AI_CHANNELS), AcqVoltRow, VAL_ROW_MAJOR); Delay(0.1); } DAQmxStopTask(htAI); DAQmxClearTask(htAI);
An image is better than thousand word: the analog inputs were connected to a resistor network to have known values.
The upper table contains the hardware timed acquisitions, the lower one the software timed readings.... as you can see the first row is all of 0.13 values, totally wrong
If the software timed acquistion task is executed without the previous one (in my demo this can be obtained by the switch in upper right corner), readings are correct!
Is there something I'm doing wrong?
I've also tried running the program on USB-6009, but it seems to works correctly.
[LabWindows/CVI 2010 SP1 - NI-DAQmx driver 9.4 - Windows 7 x64]
Solved! Go to Solution.
11-10-2011 11:22 AM
I have further details on the problem, and now I could best describe it as an incorrect state left somewhere (may be in DAQmx, may be on USB-6212 card) when a running analog acquisition task is stopped.
If the task is stopped as presented in the previous message code, by calling DAQmxStopTask() or even with DAQmxClearTask(), there is some "leftover" that prevents the first on-demand acquisition of a new task to be successful.
If the task is aborted by a call to DAQmxTaskControl (htAI, DAQmx_Val_Task_Abort); all works as expected.
The updated task code is here:
if (Switch) { // // First Task: read 10 rows of values with hardware timing // DAQmxCreateTask("", &htAI); DAQmxCreateAIVoltageChan (htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, ""); DAQmxCfgSampClkTiming(htAI,"", SAMPLE_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000); DAQmxRegisterEveryNSamplesEvent (htAI, DAQmx_Val_Acquired_Into_Buffer, SAMPLE_RATE, 0, RefreshCB, NULL); DAQmxStartTask(htAI); Delay(1.0); DAQmxTaskControl (htAI, DAQmx_Val_Task_Abort); ///// in place of DAQmxStopTask() DAQmxClearTask(htAI); } // // Second Task:read 10 rows of values with software timing // DAQmxCreateTask("", &htAI); DAQmxCreateAIVoltageChan(htAI, MX_DEV_AI, "", DAQmx_Val_NRSE, -10.0, 10.0, DAQmx_Val_Volts, ""); DAQmxStartTask(htAI); for (i=1; i<=10; i++) { DAQmxReadAnalogF64(htAI, 1.0, 10.0, DAQmx_Val_GroupByChannel, AcqVoltRow, HW_AI_CHANNELS, &read, 0); SetTableCellRangeVals (panelHandle,PANEL_SOFT, MakeRect(i, 1, 1, HW_AI_CHANNELS), AcqVoltRow, VAL_ROW_MAJOR); Delay(0.1); } DAQmxStopTask(htAI); DAQmxClearTask(htAI)
04-06-2012 06:08 AM
This problem has been corrected by NI-DAQmx 9.5
324044 NI USB-621x on-demand AI task returns incorrect data after clearing a buffered AI task