Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Mutithreading

Hi,

 

Is the NiDAQ software threadsafe? I have created a task handle in one thread but when I try to use it in another thread it complains that the handle is invalid.

 

Is there a way round this?

 

Thanks

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

NI-DAQmx is both thread-safe and capable of multithreading.

Traditional NI-DAQ is thread-safe, but is not capable of multithreading as every call blocks every other call.

NI-DAQmx Base is not thread-safe.

 

What application development environment are you using? (LabVIEW, C# in Visual Studio 2008, etc)

 

Does your application deterministically guarantee that the task will be created before the handle is used elsewhere?

 

Regards,

Seth B.
Principal Test Engineer | National Instruments
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 2 of 3
(2,907 Views)

Hi,

 

Thanks for the reply. I am using VC++ 6.0.

 

 

I create the task in the main thread, then set up a windows multimedia timer (which of course works in another thread) to do stuff with the task handle. I have assumed that the task it fully created and ready upon return from DAQmxStartTask(). It is after this call that I set up the timer.

 

The code is similar to this (edited)

if(DAQmxCreateTask("", &anaTaskHandle) < 0) { DebugOut("Error:Failed to create analogue input task\n"); return FALSE; } DebugOut("Info:Analog input task created for PCI6220\n"); if(DAQmxCreateAIVoltageChan(anaTaskHandle, "Dev1/ai0:7", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL) < 0) { DebugOut("Error creating analog input channels\n"); } DAQmxStartTask(anaTaskHandle); // Set up the digital outputs if(DAQmxCreateTask("", &digTaskHandle) < 0) { DebugOut("Error:Failed to create digital output task\n"); } DebugOut("Info:Digital output task created for PCI6220\n"); if(DAQmxCreateDOChan(digTaskHandle, "Dev1/port0:1", "", DAQmx_Val_ChanForAllLines) < 0) { DebugOut("Error creating digital output channels\n"); return FALSE; } DAQmxStartTask(digTaskHandle); // Start the task running bool bTimerStatus = StartTimer(1); DebugOut("Timer resolution is %d\n", wTimerRes); DebugOut("Info:InitialiseHardware() succeeded\n");

 

 

 

I get the same invalid handle error each time the timer fires.

 

I hope this helps, I am a newbie to NiDAQmx.

 

Thanks

 

Tony

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