Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of DAQmxClearTask

Hello,

 

I am using the PCI6111 and DAQmx 9.4. Development environment is the native Visual C++ 2010.

The issue occurs with running the following routines. In this article, I simplized each routine.

 

HRESULT FftDevice::Initialize()
{
	Int32 iStatus;
	uInt32 pattern;
	
// Create a new DAQ task iStatus = DAQmxCreateTask("", &inTaskHandle); iStatus = DAQmxCreateTask("", &outTaskHandle); iStatus = DAQmxCreateTask("", &counterTaskHandle); return PNMD_NO_ERROR; } HRESULT FftDevice::Reset() { Int32 iStatus = 0; if (iStatus = DAQmxResetDevice(m_devName)) { if(iStatus != PNMD_NO_ERROR) return iStatus; } char ctr0InternalOutput[128]; char rtsi0[128]; sprintf(ctr0InternalOutput, "/%s/Ctr0InternalOutput", m_devName); sprintf(rtsi0, "/%s/RTSI0", m_devName); iStatus = DAQmxConnectTerms(ctr0InternalOutput, rtsi0, DAQmx_Val_DoNotInvertPolarity); return PNMD_NO_ERROR; } HRESULT FftDevice::InternalClear() { Int32 iStatus = 0; if (m_deviceNumber != 0) { iStatus = DAQmxClearTask(inTaskHandle); iStatus = DAQmxClearTask(outTaskHandle); iStatus = DAQmxClearTask(counterTaskHandle); } return PNMD_NO_ERROR; } HRESULT FftDevice::Setup(BOOL ACcoupled) { Int32 iStatus = 0; char ai0[128]; sprintf(ai0, "%s/ai0", m_devName); DAQmxClearTask(inTaskHandle); DAQmxCreateTask("", &inTaskHandle); //set the coupling if(ACcoupled) iStatus = DAQmxSetAICoupling(inTaskHandle, ai0, DAQmx_Val_AC); else iStatus = DAQmxSetAICoupling(inTaskHandle, ai0, DAQmx_Val_DC); DAQmxClearTask(inTaskHandle); m_ACCoupled = ACcoupled; return PNMD_NO_ERROR; }

 

  • Initialize() runs at the startup of the system.
  • Reset() runs triggered by the reset event, such as *RST in IEEE488.
  • InternalClear() runs triggered by the status clear event, such as *CLS in IEEE488.
  • Setup() runs when the acquisition process starts, such as INIT command.

As seen above, three task handles are used, for the analog input, the analog output and the counter.

When I run Initialize() -> Reset() -> Setup() and get a trace by NI IO Trace, the trace shows as follows:

 

1.  DAQmxGetSysDevNames ("Dev1", 1024)
2.  DAQmxGetDevProductType ("Dev1", "PCI-6111", 128)
3.  DAQmxCreateTask ("", 0x6DEE9E40)
4.  DAQmxCreateTask ("", 0x6DEE9F20)
5.  DAQmxCreateTask ("", 0x6DEEA000)
6.  DAQmxResetDevice ("Dev1")
7.  DAQmxConnectTerms ("/Dev1/Ctr0InternalOutput", "/Dev1/RTSI0", 0)
8.  DAQmxClearTask (0x6DEE9E40)
9.  DAQmxCreateTask ("", 0x6DEE9E40)
10.  DAQmxSetAICoupling (0x6DEE9E40, "Dev1/ai0", DAQmx_Val_DC)
11.  DAQmxClearTask (0x6DEE9E40)

 It is seen that the pointer to inTaskHandle is 0x6DEE9E40, 0x6DEE9F20 for outTaskHandle, and 0x6DEEA000 for counterTaskHandle.

This is expected behavior.

 

However, when InternalClear() is inserted, i.e., run Initialize() -> Reset() -> InternalClear() -> Setup(), the NI IO Trace shows as follows:

 

1.  DAQmxGetSysDevNames ("Dev1", 1024)
2.  DAQmxGetDevProductType ("Dev1", "PCI-6111", 128)
3.  DAQmxCreateTask ("", 0x6DEE9E40)
4.  DAQmxCreateTask ("", 0x6DEE9F20)
5.  DAQmxCreateTask ("", 0x6DEEA000)
6.  DAQmxResetDevice ("Dev1")
7.  DAQmxConnectTerms ("/Dev1/Ctr0InternalOutput", "/Dev1/RTSI0", 0)
8.  DAQmxClearTask (0x6DEE9E40)
9.  DAQmxClearTask (0x6DEE9F20)
10.  DAQmxClearTask (0x6DEEA000)
11.  DAQmxClearTask (0x6DEE9E40)
12.  DAQmxCreateTask ("", 0x6DEEA000)
13.  DAQmxSetAICoupling (0x6DEEA000, "Dev1/ai0", DAQmx_Val_DC)
14.  DAQmxClearTask (0x6DEEA000)

 In this trace, lines 8-10 corresponds with InternalClear(). Then, line 12 is DAQmxTaskHandle("", &inTaskHandle) in Setup(). But its pointer is changed that of the counterTaskHandle. This causes an aquisition error.

 

I know duplicated DAQmxCreateTask for the same task causes an error, but duplicated DAQmxClearTask for the same task returns the status of OK.

I thought DAQmxClearTask clears the task, but does not release the allocated memory itself (actually in my code the pointer for the task handle is fixed except above).

 

Do I misunderstand the detailed DAQmxClearTask...?

Does anyone know what causes different result in the above two processes?

Should not I use DAQmxClearTask for the status clear such as *CLS?

 

What I know is "something should be wrong, but what?"

 

Thanks,

Neppie

 

0 Kudos
Message 1 of 1
(3,719 Views)