LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW cDAQ Device Automatic Selection?

Solved!
Go to solution

First off I would like to say I am in no way a developer for LabVIEW, but I am proficient with like applications and have done a little bit with it. 

 

With that being said:

 

We have a vi that runs to collect data using a NI 9215, we took that vi and converted it to an exe using application builder. When we deploy the exe on a laptop and connect the cDAQ-9171, the vi runs fine and collects the data. The problem comes when we switch the cDAQ to a new one, the NI device is looking for the last one that was installed and will not run the vi. We would have to go into DAQmx, delete the old device and refresh it, then run the vi and it works fine.

 

Is there a way we can modify the vi to automatically choose any CDAQ module instead of looking for cDAQ1 or cDAQ2....etc. Is it possible or is there more to this that i'm not seeing. We need to make it easier for technicians to not have to do alot of configuration of the computer as sometimes they are not proficient in that sense.

 

Thank you in advance.

0 Kudos
Message 1 of 9
(5,126 Views)

Try using the System and Device property nodes (on the DAQmx>Advanced>System Setup palette). The snippet below will output the device name of the first 9215 module that it sees.

 

9215 detection.png

0 Kudos
Message 2 of 9
(5,108 Views)

So this would display the device, but the user would still have to configure NI Device Monitor to look at the current device correct? I'm looking to see if there is anyway to have the vi auto select the active device or at minimum be able to select which device to use without going into the block diagram?

 

the only way I know to do it right now is to go into block diagram and physically change the channel.

 

DAQ1.jpg

0 Kudos
Message 3 of 9
(5,096 Views)

Ok, I see that you're using DAQ Assistant. In this case you can programmatically tell it which device to use with the "device name" terminal:

 

9215 detection.png

0 Kudos
Message 4 of 9
(5,086 Views)

What is the block inside that says NI9215? Im trying to find it and cannot...

0 Kudos
Message 5 of 9
(5,073 Views)

That's a case structure. Are you running LabVIEW 2015? The picture that I posted is a snippet, which means you can click on it with your mouse and drag it onto your block diagram, and it will add that code to your VI.

 

I should probably explain what the code is doing. The DevNames property is an array that contains the name of each DAQmx device that you have in your system. The For Loop executes the code inside for each element of this array, one at a time. The ProductType property is a string that describes what type of device is wired into the ActiveDev terminal. This string is wired into the selector terminal of the case structure, and I've defined a case for "NI 9215". So if the ProductType string of that particular item in the DevNames array is "NI 9215" then the code inside that case is executed, which tells the VI to stop the For Loop and send the device name for the 9215 to the output of the loop. I've also defined a Default case, which tells the loop to keep iterating through the rest of the elements in the DevNames array. If it gets to the end of the array without finding a 9215, the loop will output a blank device name.

0 Kudos
Message 6 of 9
(5,063 Views)

I am using 2014. So I did figure out the case structure, and I thank you for your explanation. I was able to re-create it but when I run it I get an error. Note I am only using channel 0 on the 9215. 

 

DAQ2.jpg

0 Kudos
Message 7 of 9
(5,055 Views)
Solution
Accepted by bradbb2005

Specifying Default in the case structure means that case will execute for any input that doesn't already have a separately defined case. Your "NI 9215" case also includes the Default in the same case. So if the first item in the device array is your chassis (cDAQ5), the code in the "NI 9215", Default case will still execute because there is no other defined case for "cDAQ5". This means the loop will stop and the "cDAQ5" device name will be sent to the output of the loop, which causes the error you are seeing because the DAQ assistant needs the entire name of the module. Your case structure needs to have two cases: one for "NI 9215" and one Default case to handle everything else that isn't a 9215:

 

Untitled.png

 

Also, by putting the property nodes and For loop inside your While loop as you've done, you're telling it to execute that code repeatedly, when you really only need to get the name of the device once. Put these items outside the while loop and only wire the device name into the loop, as I've done in my example.

 

See the attached VI.

0 Kudos
Message 8 of 9
(5,043 Views)

Thank you for all of your help I was able to get it working flawlessly. Thanks again.

0 Kudos
Message 9 of 9
(5,001 Views)