Custom Controls and Indicators


Q1:

What do all the VI front panels shown in the following figure have in common?

A1:

They all use custom LabVIEW controls! And look darn cool, too (see Figure 17.9).

Figure 17.9. Custom LabVIEW controls in front panels.Top-left and bottom two images courtesy of Dave Ritter, http://www.bettervi.com


In Chapter 13, "Advanced LabVIEW Structures and Functions," we learned about type definitions, a kind of custom control. Type definitions usually focus on the underlying data type, but with custom controls, you can also customize the appearance of the control.

You can customize controls and indicators to make them better suited for your application while displaying a more impressive graphical interface. In the previous examples, you might want to display the temperature stages at various points in a process to represent the real-world scenario. Or you might want to turn on and off a valve by clicking on a valve picture control above.

You can save a custom control or indicator ("control" from here on, for simplicity) in a directory or LLB file, just as you do with VIs and globals. LabVIEW uses the ".ctl" file extension for custom control files. You can use the saved control in other VIs, as well as in the one in which it was created. It's possible to even create a master copy of the control if you need to use it in many places in the same VI by saving the control as a type definition. When you make changes to a type definition, LabVIEW automatically updates all the VIs that use it! That's a huge time saver and an absolute necessity for large LabVIEW projects.

You may also want to place a frequently-used custom control in the Controls palette. Do this by selecting Tools>>Advanced>>Edit Palette Set from the menu, or just put it in the ./user.lib/ directory, and it will appear in the User Controls palette the next time you restart LabVIEW.

OK, so how do you create a custom control? We'll start with a very simple example.

Activity 17-1: Custom Controls

Usually, you will want to import pictures for your custom control, so first of all have your picture files available, maybe along with a graphics program. LabVIEW doesn't have any sort of picture editor. When you create a custom control, you always base it on the form of an existing control, such as a Boolean LED or a Numeric Slide control. In this activity, we'll create a custom Boolean that looks like a valve that is open or closed.

1.

Place a Flat Square Button control (available on the Classic>>Classic Boolean palette) on a front panel, and select it (see Figure 17.10).

Figure 17.10. Classic Boolean palette


For this activity, we are using a Classic (2D) button because it only has one "part"a part is an individual item that you can edit in the Customize mode of the Control Editor dialog. Because our valve only has one part, this choice makes sense. Modern (3D) buttons have multiple "parts," each of which may be replaced with an image using the process detailed in this activity.

2.

Launch the Control Editor by selecting Customize Control . . . from the Edit menu (or select Advanced>>Customize . . . from the control's pop-up menu).

3.

The Control Editor window will show the Boolean.

4.

In Edit mode, the Control window works just like the front panel. You can pop up on the control to manipulate its settingsthings like scale, precision, etc. (see Figure 17.11).

Figure 17.11. The Control Editor being changed to Customize Mode


5.

In Customize mode, which you access by clicking on the tool button, you can resize, color, and replace the various picture components of the control (see Figure 17.12).

Figure 17.12. The Control Editor being changed to Edit Mode


6.

In Customize mode, pop up on the Boolean and select Import Picture from File . . . and select the picture file of a closed valve or use the one provided on the CD (named closed.png). as shown in Figure 17.13.

Figure 17.13. Your Boolean control after importing closed.png


7.

Repeat step 6 for the TRUE case of the Boolean, using a different valve picture (see Figure 17.14). The TRUE (open) valve picture is also on the CD (open.png).



Figure 17.14. Your Boolean control shown in both the FALSE and TRUE states after importing open.png


The valve image files included on the CD are of the PNG format and have been configured to have a transparent background. This allows you to use your valve button on the front panel of VIs that have any coloryou will not see the background of the valve image. This is a very cool LabVIEW feature!

8.

Save the custom control by selecting Save from the File menu. LabVIEW uses the ".ctl" file extension for custom controls.

9.

The front panel shown in Figure 17.15 is found in the examples of the full version of LabVIEW (examples\apps\controlmix.llb\Control Mixer Process.vi). This front panel uses the same Boolean controls you just created, as well as some others.

Figure 17.15. Control Mixer Process.vi front panel


An important concept to understand is that you cannot change the behavior of a control; you can only modify its appearance. This also means that generally you can't change the way a control displays its data (a custom control based on a slide will always have something that slides in one dimension, for example). Despite these limitations, you can produce some fancy graphical interfaces, especially if you're artistically inclined and willing to experiment.

If you want to create a master copy of your control so that all the VIs that contain it are automatically updated when you make a change to the master copy, select Type Def. from the ring on the Control Editor's toolbar (see Figure 17.16).

Figure 17.16. Configuring Valve.ctl to be a Type Definition


A type definition forces the control data type to be the same everywhere it is used, but different copies of the type definition can have their own name, color, size, and so on. This is useful because only the master copy can be modified in behavior, thus preventing accidental changes. A strict type definition forces almost everything about the control to be identical everywhere it is used.

Finally we'll mention one very powerful type of customized control: the XControl. XControls in LabVIEW let you not only create custom interfaces, but let you embed custom behaviors by writing LabVIEW code for the XControl. For example, you could create an XControl that is like a CD Player interface. Among other things, you could define that the "stop" button works whenever the "play" button is active and pressed, and that the "play" button resets the "stop" button.

XControls are beyond the scope of this book but for more information, check out the LabVIEW examples and documentation on this very nifty feature.




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