Replace NI-DAQmx Physical Channel Drop Down Menu With Check Boxes for LabVIEW and LabVIEW NXG

Updated Oct 21, 2020

Environment

Software

  • LabVIEW
  • LabVIEW NXG

Driver

  • NI-DAQmx

I want to limit which channels on my DAQ device that my end user can select from. One idea I had was to replace the NI-DAQmx Physical Channels drop down menu with a list of check boxes which I can configure to allow the end user to only have access to certain channels. 

Example Summary

The attached examples of LabVIEW 2018 and LabVIEW NXG 4.0 show how to:
  • Programmatically get the DAQ module names using DAQmx System and Device property nodes. 
  • Create the check boxes, with either all the channels or with one channel deleted, using clusters. 
  • Get the index position of the check box channels you selected. 
  • Use the index position to programmatically select the correct channel from the DAQmx System and Device property nodes
  • Combine these selected channels together and pass into the DAQmx Create Channel.vi. 

A) Programmatically get DAQ Channel Names
 

  1. Place the DAQmx System and DAQmx Device property nodes on the Block Diagram. Put a For Loop around the DAQmx Device property node and wire the DevNames output from the DAQmx System property node to the ActiveDev input of the DAQmx Device property node. Keep the auto indexed tunnel (Enable Indexing).
  2. Resize the DAQmx Device property node to select the required DAQ I/O Type, i.e. AI.PhysicalChans or DO.Lines, and wire to the output of the For Loop. Right click on the tunnel and change the Tunnel Mode to Conditional

    1. Resize the DAQmx Device property node and add a ProductType output. Create a condition using the product name and wire to the boolean input on the conditional terminal. i.e. If the product type equals the NI-9238, then output the  AI.PhysicalChans.

  3. The output of the For Loop with the conditional terminal will be an array, either a 1D or 2D depending on the number of DAQ hardware product types you configured. If its a 2D array, you need to manipulate the array into a 1D array. 

    1. In the examples, there are 2 NI-9238 so a 2D has been created, with one module per row. Use the Index Array functions to extract each row from the 2D array, and the Build Array set to Concatenate Inputs to build into a 1D array. 

  4. Wire to the input of a For Loop and Disable Indexing tunnels.


B) Create Check Boxes

In parallel to Section A, we need to create the check boxes.

  1. Create a cluster which contains boolean buttons or check boxes. This can either be on the Front Panel or Block Diagram. It should have the same number of channels or less than the module you are configuring it for. 

  2. Wire the cluster to a Cluster to Array on the Block Diagram.

  3. If you are keeping all the channels, more to step 4. Otherwise, go to step 3.1. 

    1. If you want to remove (or hide) a channel from the user, delete the channel from the cluster. For example, a NI-9238 has 4 channels and if I don't want my user to select ai1, delete this from the cluster. 

    2. Wire the output of the Cluster to Array to a Insert into Array

    3. Wire a numeric constant to the index of the  Insert into Array and write the value of the index of the channel you want to hide. For example, if you removed ai1, use a value of 1 in the constant. Wire a False constant to new element input. 

      1. We do this because we want to ensure the array has the same number of elements as the channels for the module. 

    4. Wire the output of the Insert into Array into a Build Array set to Concatenate Inputs

    5. Repeat these steps for all the modules you need. 

  4. Create a For Loop. Pass the output of the Build Array into the For Loop, and Enable Indexing

    1. In the For Loop, wire the index counter to the output. Right click on the tunnel and change the Tunnel Mode to Conditional. 

    2. Wire the input (the output from the build array) to the condition on the Conditional Tunnel

    3. This will create a 1D array of the index positions check boxes (DAQ channels) you selected so that you can extract the same index position from the 1D array outputted from Section A. 

  5. Wire the output of the For Loop in step 4 to the input of the For Loop created at the end of Section A. Enable Indexing on the input. 



C) Combine A) and B) to Create the Input to the DAQmx Create Virtual Channel

This section combines the channels together to wire into one DAQmx Create Virtual Channel. Further manipulation will be needed to separate for multiple DAQmx Create Virtual Channels.

  1. There should be a For Loop with the inputs to the loop being the 1D physical channel array from Section A (with the auto index disabled) and index position from Section B (auto indexing enabled). 

  2. In the For Loop, create a Index Array function, with the input to the Index Array being the 1D array of DAQ physical channels and the index input being from the index position input. 

    1. Wire the output of the Index Array to a Type Cast function, which has a string constant connected to the Type input. 

    2. Wire the output of the Type Cast to the output of the For Loop and change the Tunnel Mode to Indexing. The output should be a 1D array. 

    3. This will allow us to extract the DAQ channels based on the index position, which in turn is based on the user selection. 

  3. Create a DAQmx Flatten Channel String.vi  and wire the output of the For Loop to the input. This will combine the elements in the 1D array into the correct format for a DAQmx Physical Channel.

  4. Create a Type Cast with a Physical Channel constant wired to the Type input. 

  5. Wire the output of the DAQmx Flatten Channel String.vi to the input of the Type Cast

  6. The output of the Type Cast can be wired to the DAQmx Create Virtual Channel.vi and you can continue with you DAQ application. 

 

The figure below shows the Front Panels of LabVIEW and LabVIEW NXG with the check boxes for only 3 of the 4 channels for the DAQ module. This means that the user can only select from those 3 and cannot read/write data from the missing channel. 

 

LabVIEW 2018 Example

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

LabVIEW NXG 4.0

Note: This image is a LabVIEW NXG snippet, which includes LabVIEW NXG code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW NXG diagram.