How Do You Do That in LabVIEW?


This section is more about programming solutions than about LabVIEW features. Common problems arise in developing many applications, and we show you some of them along with their solutions in the following pages. Some of the solutions are very simple; some are quite ingenious. By no means do all or even most programming challenges appear here; rather, these examples have been collected from a variety of sources to give you a jump start on some applications or at least food for thought.

You might take some of these problems as a challengetry to come up with a programming solution on your own first before looking at the answer!

There is an online list of LabVIEW frequently asked questions (FAQ) called the "LabVIEW FAQ" located at http://labviewfaq.org. The LabVIEW FAQ is hosted by the LabVIEW Advanced Virtual Architects (LAVA) user group, whose web site is located at http://lavag.org. See Appendix E, "Resources for LabVIEW," for more information about LAVA and the various LabVIEW resources they provide.


How Do You Acquire Data from Different Channels at Different Sampling Rates?

Things work fine when you're sampling all your data channels at the same rate. It's more challenging when one channel has to be sampled at 10 kHz, and another channel only requires sampling at 50 Hz. There's not really any magical solution to the multiple-sampling rate requirements, but you have a couple of options:

1.

If you have more than one DAQ board, try assigning the channels so each board can handle the channels with the same sampling rate.

2.

Sample everything at the highest rate, and then throw away the extra points on the lower-rate channels. One efficient way to do this is to use the Decimate 1D Array function (Programming>>Array palette).

Figure 17.27. Decimate ID Array


There are a few DAQ boards from NI that support simultaneous sampling with multiple ADC chips. In this case, you can set separate sampling rates for those channels with individual ADCs.

How Do I Clear a Chart Programmatically?

To do this, wire an empty array to the History Data attribute of a chart. The data type of this empty array is the same as the data type wired to the chart.

As a tip, don't do this when the VI starts, but instead do it when the VI exits. That way, when the VI loads, it will be ready to go and the user won't see any data from the last run at all.


There is an excellent example that illustrates this technique in examples\General\Graphs\Charts.llb\How to Clear Charts and Graphs.vi. The front panel and block diagram of this VI are shown in Figures 17.28 and 17.29, respectively.

Figure 17.28. How to Clear Charts and Graphs.vi front panel


Figure 17.29. How to Clear Charts and Graphs.vi block diagram


You can also pop up on the chart in the front panel and select Clear Chart.

How Can I Display a Waterfall Plot?

A waterfall plot is similar to a 3D plot, but places successive series of 2D graphs "stacked" along the Z-axis to show their change over time. In the LabVIEW examples, you will find "Picture Waterfall Spectrum.vi," which is shown in Figure 17.30.

Figure 17.30. Picture Waterfall Spectrum.vi front panel


This VI uses a Picture Control, which we discussed in Chapter 13, "Advanced LabVIEW Structures and Functions."

Is There a Way to Put More Than One Y Axis on a Graph for Two or More Plots?

Yes. On the graph, pop up and select Visible Items>>Scale Legend. Then resize the Scale Legend to add more Y axes. Another way to add a Y scale is to pop up on an existing Y scale and select Duplicate Scale from the shortcut menu.

My Graphs Flicker Every Time They Are Updated. It's Getting Really Annoying. Is There Any Way to Fix This?

Fortunately, yes. From the Tools menu, choose Options . . . . Select the Front Panel item. Check the box that says "Use smooth updates during drawing." This will turn off the flicker; the trade-off is more memory will be used.

How Can You Create a Toolbar-Type Feature That Will Pop Up Different Sets of Controls and Indicators on the Same Window?

This was a difficult task to accomplish in earlier versions of LabVIEW. Now, however, you can use the SubPanel control to create a "frame" in your VI's front panel. The SubPanel is in the Modern>>Containers palette. It allows you to programmatically load VIs into this frame. You simply pass the VI Reference (see Chapter 15) of the VI you want to display in the SubPanel to the SubPanel's invoke node.

Can I Access the Parallel Port in LabVIEW?

Yes. Use the VISA Read and Write functions (never mind that parallel is the opposite of serial). Just as you use port 0 for COM1, port 1 for COM2, etc., in LabVIEW for Windows, port 10 is LPT1, port 11 is LPT2, and so on. You can even send data to a printer connected to a parallel port, use VISA Write, although you may need to know the printer's special control characters. Another good use for accessing the parallel port is to do some digital I/O without a plug-in board: You get eight digital lines for free! (But a hardware buffer is recommended to protect your computer.)

Also, you can use In Port.vi and Out Port.vi (found on the Connectivity>>Port I/O palette). These VIs allows you to peek and poke at the parallel port registers.

OpenG.org also offers a portIO library that allows reading and writing to memory addresses in Windows, which offers considerable performance improvements over the VIs that ship with LabVIEW. See Appendix C, "Open Source Tools for LabVIEW: OpenG," for more information.


Why Doesn't My VISA Session Work?

Did you open VISA sessions before trying to read and write? Did you get any error messages when you opened them? Did you supply the correct session IDs to the read/write VIs? You might want to report exactly what the error message is and exactly when it is reported. Cycle instrument and PC power, then use probes or simple error handler VIs to determine where the error first appears. Try sending an example message from the instrument manual verbatim. Verify that you are terminating your messages properly. Send your message to a front panel variable with "\" codes enabled to see that you are sending exactly what you expect.

Also, try using the Instrument Assistant Express VI (which you learned about in Chapter 12, "Instrument Control in LabVIEW") to test communication with the device.

Can I Do Object-Oriented Programming in LabVIEW?

Yes. See Appendix D, "LabVIEW Object-Oriented Programming," for more information.

Can I Turn My VIs into Standalone Executables So People Can Run Them Without LabVIEW?

Yes. You need to either have the Professional version of LabVIEW or purchase the LabVIEW Application Builder add-on. Choose Build Executable . . . from the Tools menu to do this.

How Do I Monitor or Control My VIs over the Web?

Use LabVIEW's built-in web server to view or control your VIs. See Chapter 16, "Connectivity in LabVIEW," for more information.

Can LabVIEW Cook Me Dinner?

What are you hungry for? Don't assume "LabVIEW can't..." until you check out the documentation; you'll be surprised at how flexible and powerful LabVIEW is.




LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net