LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding fixed and realtime data to a plot

I've just started using Labview 8 and I have been struggling with the concepts of arrays, bundles, etc.  At the start of my program I need to read a specific waveform from a file and plot the whole thing on a graph.  It then will enter a loop where one or more analog channels will be measured periodically and plotted on the same graph for comparison with the existing curve.  The whole plot is limited to 15 minutes of samples taken every n seconds as selected by the user so I don't think I want to use a stripchart.  I have tried connecting various graphs, bundles and arrays with no luck.  I am able to read the file and plot it but I can't figure out how to then to add additional data points to a second plot.  Please help! 
0 Kudos
Message 1 of 19
(2,996 Views)
Hi perge,
 
Perhaps you could post your code or at least a screen capture of the plotting part.  Offhand, all I can say is to try using the build array and wire the file waveform and the new waveform to it and then plot on a waveform graph.  The build array function is on the array palette and depending on the daq read you might have to use the build waveform function on the waveform palette.
 
regards,
drew 
0 Kudos
Message 2 of 19
(2,992 Views)
Drew,
I attached the vi.  It has a lot of other problems but the graphing is the one I have spent too much time on.  I am not sure if I made it clear that after the desired profile is plotted in full, the actual DAQ data points are to be plotted as they come in, not all together at the end.  So the plot must be built as time goes from 0 to 15 minutes.  I know what I have here doesn't work.  If I use a build array tool, will it continue to add data points to the existing arry each time through the loop?

0 Kudos
Message 3 of 19
(2,987 Views)

There are a bunch of ways to do this.  I've attached a simple vi that shows just one of the many.  It uses a for loop where you have a while loop but the concept is the same.  You should see that there is a waveform built outside the loop, that represents what you are reading from the file.  In this example, I am using a shift register with a build array inside the loop.  So for each loop iteration, the build array appends the new data to the end of the array and this makes up the measured array.  The measured array is transferred to a waveform data type and the build array again is used to plot both channels.  The measured array gets passed to the shift register on the other side of the loop so that it can be added to on the next iteration.  A shift register allows you to pass values from 1 loop iteration to the next.

Usually, I would advise against building the array in the loop since its not the most effecient at allocating memory, but in your app I don't think speed will be an issue.  Other ways to do this more efficiently would be too allocate a predetermined size array and use the shift register and replace array subset so that the array is not changing size with each loop iteration and just plotting the subset of the array that is actual data.  However, predeterming the array size when using a while loop requires deciding if you know a maximum array length or just guessing a maximum.

Just to make sure I answered your last question, the build array will only continue to add points if you wire the array to a shift register.  If you just wire an array to the loop and use the build array, the array will be the same for each iteration except for the last point.  Also, note that the inputs look different depending on if you wire a scalar and array to the build array or 2 arrays.  In my example, labview is concantenating the 2 inputs.  Meaning making longer 1D array vs making a 2D array.  A right click on the build array will show an option to concantenate.  So you could concantenate two 1D arrays to make a longer 1D array or not concatenate and make a 2D array.

Hope this helps and if it doesn't I'm sure my next reply will be more coherent since its a little late for me to be at work

drew

0 Kudos
Message 4 of 19
(2,981 Views)
yep, forgot to post the example
Message 5 of 19
(2,980 Views)
Drew,
OK, let me re-read your email and look at the example tomorrow.  I am finding the help files fairly un-helpful even though I have done a lot of DAQ software in written forms.  There seems to be too much hidden from the user here especially when it comes to the data formats.  Examples are the way to go.  Tomorrow is another day and I will carefully look this over and, hopefully, dawn will break on marblehead.
Thanks.
0 Kudos
Message 6 of 19
(2,975 Views)
Drew,
Your example does exactly what I need to do!  And it all seems so clear now.  Thanks for the help with this. 
Regards,
Phil
0 Kudos
Message 7 of 19
(2,955 Views)

I agree that when first using LabVIEW, it seems that the simplest things are the hardest to do, ie. plotting etc.  The different color wires, native LV data types, and lack of help on the simplest of topics can really be frustrating.  However, the LV examples are starting to get really thorough and you can pretty much find anything you need somewhere on the NI developer zone.  I like your idea of looking through examples, they are a great place to start.  I would also try writing your own vi's from scratch when working on a specific task like different ways of plotting data.  When I first started LV, I thought it was a little lame when it came to programatically controlling your vi's, like making graphs change based on user inputs etc, but then I found the property nodes and realized that if LV can't do it, it can't be done!

Hopefully the plotting example I posted will make sense and please post as soon as something doesn't click, I've wasted a lot of time staring blankly at code when the answer was just one simple post away.  In looking at your current code, I just wanted to add a couple of things that might make it cleaner.

1) You basically are using a state machine for the architecture of your code.  I would check out the LV state machine examples to see how to do this a little more cleanly.  Currently you have something like this, a sequence structure, and then a while loop, and then another sequence structure.  The LV state machine example will have a while loop with single case structure inside.  You use a shift register on the while loop to pass enum constants to direct the case structure to the next case.  Sketching out a state diagram before coding this up helps speed up the process.  The beauty of using this is that it is relatively easy to add more states and makes a cleaner, easier to debug code.

2) one of your states will be a menu state or user input state or whatever.  In this state of the case structure, I would use an event structure to check to see if controls on the front panel have changed.  again check out the LV example of using event structures.  The event structure is way easier to implement than your current method of polling (using a while loop to see if controls have changed value).  The event structure can handle more things on the user interface than just value changes of controls but I think that is all you will need.

3) your DAQ frame uses a regular while loop with the timing controlled by the wait ms function.  I don't know the precision you need for the sample timing but a better structure to use would be the timed loop.  This will give you better control over the sample rate and provides better timing resolution than the wait function.

4) Use local variables or a means of using the actual terminal rather than the value property node when updating controls. See this example to see the difference.  http://zone.ni.com/devzone/cda/epd/p/id/2031  The value property node will redraw the control or indicator (ie. switch to the front panel thread) every time so when doing this repetively in a loop, the speed of execution may be limited by this.  Locals and terminals don't have this problem.

drew

Message 8 of 19
(2,955 Views)
Drew,
Thanks for these comments.  I will look at cleaning up my vi.  I started just trying things to see what worked and got most of these parts working that way with a little help from examples.  I had no experience with the DAQ hardware which is RS485 so I needed to try things using Docklite to send serial commands and examine the respsonses.  After trying to do the query/parse function myself I  stumbled across the LV Instrument I/O assistant which just worked (once I figured out how to reference the com port).  So I have a hodge podge of code here that was not really structured.  It became clear that I was getting lost in the jumble every time I started adding new segments.  

Here's another question.  I would like to change the color of the plot as I go depending on a boolean from an external switch.  I looked at creating properties for the graph but did not see a plot color property.  Can that be done?
Regards,
Phil
0 Kudos
Message 9 of 19
(2,951 Views)

Sure, you can programatically change the color of a plot.  I've added an example to show this.  It uses a property node to control the color of 2 channels on a single graph.  If you look at the block diagram, note that I set active plot property first and then plot color below.  The property nodes work from top to bottom, so the first thing to specify is what plot to change color so at the top, active plot is set to 0.  Below that, I tell it what color.  To change the color of the second plot, I just repeat the previous 2 properties in the same property node.  To change the color of the plots, use the set color tool (paintbrush) to set the color of the 2 controls on the front panel and then run the vi.

Note, you might want to read the color first so that if the boolean changes back you have the original color.

hope this helps,

Drew

0 Kudos
Message 10 of 19
(2,950 Views)