LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Select Channels from Task

I don't have a lot of experience with Daqmx but I'm developing an application that will be reading thermocouple values from 5 32 channel boards.  I created a task containing all the channels.  I would like to make it so the end-user can select the channels to read in the event that not all 160 channels are needed or if for some reason a channel fails.  I know that you can launch the DAQ assistant from LabVIEW but I'm not sure how to incorporate that into the next phase of the project which is to allow the user to select which channels to actually monitor visually on a chart.  From the channels the user selected to log and I wanted the option to chose 8 channels to watch on a chart.  I've looked at the Daqmx samples in the help but most seem geared to a single channel solution.  Does anyone have any examples or input? 

 

Thanks.

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 1 of 10
(5,694 Views)

You could use a string control and have the user type in a channel list using commas to separate the channels and a dash to indicate a range.  An example input string would be 1,3-5,10 to select channels 1,3,4,5,10.  The attached vi will expand the string with ranges to a fully comma separated string.  So this will convert 2-4 into 2,3,4.  You can use any combination of single channels and ranges.  Have your string control as the input and wire the output to the DAQmx Create Channel vi.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 10
(5,683 Views)

Thanks for the reply Tbob.  Could someone save it in LV 8.6 so I can check it out? 

 

Thanks.

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 3 of 10
(5,665 Views)

Here it is in 8.6

 

- tbob

Inventor of the WORM Global
Message 4 of 10
(5,652 Views)

Thanks for the example.  For some reason I am still unable to wrap my mind around setting this up with daqmx.  I put together a quick vi that illustrates what I would like to accomplish and maybe someone could point me in the direction of accomplishing the same thing with daqmx.  On the UI I envisioned some sort of dialog pop-up where the user would select which channels to read from and log data, this is labeled as “PXI 1 Channels to Log.”  That would be followed by another dialog to select the channels to actually graph labeled, “PXI 1 Select Channels To Graph.”  Ultimately there will be over 150 thermocouples so I need to be able to select the channels and view up to 8 or so on a graph.

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 5 of 10
(5,612 Views)

First, make the default values for your radio buttons off.  Let the user choose from the list.  Otherwise your array will be built with a bunch of channels upon the first radio button press.  Same for the other radio button structure.

 

Next, your second loop runs in parallel to the first.  It will start running as soon as the run button is pressed.  The local variables will be read before the user has a chance to choose channels.  This is not what you want.  Put a button on the front panel that the user must press when he is ready (after he has chosen the channels).  Put the second loop in the Value Change event for that button.  In fact, you don't need a loop.  You only need to write active channels to the file once.  Get rid of the loop.

 

Put a value on the timeout event (the hourglass).  This causes an event in case the user doesn't press anything.  You don't have to put any code in the timeout case.

 

Once you have your list of channels, you can create a comma separated string from the Active Channels array and feed that into the DAQmx Create Channels.  To create the string, wire the array into a For Loop with indexing enabled.  Use a shift register initialized with a blank string.  Concatenate the shift register with the indexed array value and a comma.  Feed the concat output to the shift register.  Upon exiting the loop, remove the last comma by using String Subset.

 

Do this part and we can tackle the rest later.

 

- tbob

Inventor of the WORM Global
Message 6 of 10
(5,607 Views)

Thanks for taking the time to walk me through the solution, I appreciate it.  Sorry it took me so long to respond, I don't always get all the time I need for programming.  With that hopefully I didn't butcher the solution you had in mind too much.

 

Thanks.

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 7 of 10
(5,561 Views)

You were close.  But you made beginner mistakes.  You must put the event structure inside a while loop.  Otherwise the event structure will wait until an event occurs, then when one does, the program will end.  That is why you had to set the timeout value so large,  But that is not the way to do it.  Set the timeout value small and put the event structure inside a loop.  The timeout event will fire often, but the loop will stop the program from ending until a stop button is pressed.  See my code for an example.  You could also add an event for the Stop button value change.  In this case, you would send a boolean constant True to the stop sign.

 

You don't need the stacked sequence structure.  Stay away from those, they promote bad programming practices.  All of your code fit easily in one event case, as you can see below.  Instead of having two For Loops, I combined the code into one loop.  It builds your channel array and your channel string simultaneously.  Always put the control for an event inside the event case, as shown for the Channels Selected control.  This way, the program will read the control when the event fires.  If it is outside the case, as you had it previously, the program will read it once, at the beginnng of the code, and it will never be read again.  The event will fire, but the control value is never read again.  If the control is a latch type, by not being read, the latch release never occurs.

 

I have attached the vi in 8.6.

 

19425i9ED25F5F9E3AD108

- tbob

Inventor of the WORM Global
Message 8 of 10
(5,547 Views)

You can use a 'DAQmx System' property node to get an array of Global Channels and use that to create a selection list.
(You can filter the list by casting the channels to strings and use string functions, and/or feed each channel into a property node and filter on any desired property)

 

You can create a multi-channel task by feeding an array of strings (representing channel names) into the 'Array to Spreadsheet String' function, using "%s" as the format string and "," as the delimiter, then run it through the 'Trim Whitespace.vi' function.
The resulting string can be fed into an input that takes a DAQmx task.
 

0 Kudos
Message 9 of 10
(5,535 Views)

Well I spent most of the morning looking at your example and I couldn't get it to work.  I had to change the channel names to reflect the actual "physical" location of the channel, Temperature_0 = PXI1Slot2/ai0.  One hurdle crossed, several more to go.  Thanks for your help!

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 10 of 10
(5,467 Views)