LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid repeated code

Solved!
Go to solution

I'm working on a datalogger project which may require 14 or more DAQmx channels to be displayed simultaneously. I thought of putting all the channels on the same graph and using the check boxes in the legend to show/hide each of them. Unfortunately, the person I work for requires that each channel have its own graph on the front panel. The obvious way to do this would be to just make one graph and then copy the code until there are enough, but this seems sloppy and would be a huge pain to maintain.

 

So my question is, how could I give each of 14 or more channels their own graph while also avoiding having to write the code more than once?

0 Kudos
Message 1 of 13
(2,923 Views)
Solution
Accepted by topic author duwaar

You can use a Waveform Chart instead of a Graph and stack the plots so that they will all show up on individual Y-axes with a shared X-axis. Place your chart on the front panel, expend the legend to show 14 plots, and then right click the middle of the chart and select "Stack Plots". Will look something like the attached image.

Message 2 of 13
(2,903 Views)

Previously, the application used one graph to display several live traces (definitely 14, possibly up to 20) which could be turned on and off with the checkboxes on the graph legend. Now, my client wants to be able to see each trace simultaneously on its own chart.

 

It seems like it could be easiest to do this with the waveform chart, but I have some problems with it:

  • It doesn't appear to be able to show more than nine separate traces on individual charts.
  • It doesn't take an array of waveforms. I'm collecting data with the DAQmx Read VI, which puts out an array of waveforms. I can convert this to an array of clusters of scalars, no problem, but I loose the timestamps.
  • I'm working with a large application that is already set up for a single graph. I would rather not have to rebuild the entire display portion of the program from scratch if I can help it.

Another solution, if a hacky one, seems to be putting waveform graphs into clusters in an array. I found a way to do this (http://www.ni.com/example/28024/en/), but I can't figure out a way to programatically modify (zoom, scroll, auto range, etc.) all the graphs conveniently. The only way I have found is to manually create property nodes for each graph from the control panel.

 

Any help would be appreciated.

0 Kudos
Message 3 of 13
(2,856 Views)

Hi duwaar,

 

It seems like it could be easiest to do this with the waveform chart, but I have some problems with it:

It doesn't appear to be able to show more than nine separate traces on individual charts.

It would help to see your VI.

My crystal ball says: "Nine is a magic number! You use a "Convert array to cluster" function in your code - and you didn't read the help for that function carefully!"

Check it's settings!

 

It doesn't take an array of waveforms. I'm collecting data with the DAQmx Read VI, which puts out an array of waveforms. I can convert this to an array of clusters of scalars, no problem, but I loose the timestamps.

Yes. Charts are limited when compared to graphs…

 

I'm working with a large application that is already set up for a single graph. I would rather not have to rebuild the entire display portion of the program from scratch if I can help it.

Well, when your customer request a different UI then you need to create that different UI. Or argue with the customer about not changing the UI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 13
(2,819 Views)

Ok, I see why only nine plots were showing up. Unfortunately, I don't see any way to programmatically alter the number of elements depending on how many channels are being used, which would be nice. It looks like I would just have to hard-code that number into the program. The main problem with using charts, however, is the reduced capabilities when compared to graphs, but I will keep the chart option as a last resort. 

 

Getting back to the other part of my question, I have attached the relevant VI's. The files "main.vi", "scale graph.vi", and "append waveform array.vi" are what I have. Like I said, this displays everything in the same graph window, which is not acceptable. The last VI, "dynamicstackplots.vi" is what I want to do, but I also need a way to control the plots programmatically with property nodes. Is there any way to do this nicely?

0 Kudos
Message 5 of 13
(2,798 Views)
Solution
Accepted by topic author duwaar

It looks like there is no way to programmatically change the number of stacked plots that appear, it can only be set while the VI is in edit mode unfortunately.

 

I can't open the dynamicallystackedplots.vi since I only have LabVIEW 2017 installed, but assuming it is the same as the example in the link you provided you can get a reference to one of the graphs as shown in the attached image. Changing any property for one of the array elements will be reflected in the rest of them as well. 

Message 6 of 13
(2,769 Views)

If that works, it sounds like exactly what I need, but I don't see the picture you say you attached.

0 Kudos
Message 7 of 13
(2,762 Views)

Another option is to create a VI whose task is to display one channel on one graph. If you make this VI re-entrant and open this VI by reference, you can open up as many as are required, so each channel can be displayed in its own graph window.  You can use User events to send each channel's data to the appropriate graph window (send the appropriate VI reference and data as the User Event data).  It should allow you to avoid duplication and then each graph is a stand-alone fully-featured graph and they can choose how many they want to display and at what size.

0 Kudos
Message 8 of 13
(2,750 Views)

Should be attached now.

0 Kudos
Message 9 of 13
(2,683 Views)

I feel like I'm getting close. I have this setup (see attached) which is showing me data but only in the selected scope; I have to manually click on a slot in the array on the front panel and then only the graph in that one slot will show the correct data. Am I not using the waveform graph property node correctly? I don't know. I'm stuck on this one.

0 Kudos
Message 10 of 13
(2,647 Views)