05-30-2007 03:50 PM
05-30-2007 04:31 PM
05-30-2007 05:40 PM
05-30-2007 07:25 PM
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
05-30-2007 07:26 PM
05-30-2007 10:05 PM
05-31-2007 09:54 AM
05-31-2007 10:15 AM
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
05-31-2007 10:39 AM
05-31-2007 11:03 AM
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