LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using "DAQmxGetDeviceAttribute" in multithreaded application

Hello,
 
I want to read the type of DAQ devices connected to my PC. There are three test pinbeds in my tester, so I am using three threads. I am checking two devices in each thread, using "DAQmxGetDeviceAttribute". Then I am showing the result for user. The results are not showed correctly. E.g. when I have only one USB-6501 connected to the system, my result shows two devices.
I have attached my "main" function and my "InitDevicesThreaded" function.
Do someone know, where the rub is?
 
-Glidko-
0 Kudos
Message 1 of 2
(2,874 Views)
Hello Glidko,

I glanced at your code and noticed what seems to be the cause of your problem:

You call DAQmxGetDeviceAttribute() and then you test the string value (buffer) that it returns. Twice.
If the first DAQmxGetDeviceAttribute() call succeeds but the second one doesn't, the buffer is NOT changed and you will be comparing the same string again, thus detecting a second phantom device.

Whenever you are making calls into CVI library functions, you should always check the return value. In this case, it would be -200220 (DAQmxErrorInvalidDeviceID).

Feel free to use some predefined DAQmx constans (such as DAQmxSuccess) or macros, e.g. DAQmxFailed().

Hope this helps.
LDP
0 Kudos
Message 2 of 2
(2,854 Views)