Basic Controls and Indicators and the Fun Stuff They Do


We're now going to talk a bit about the goodies contained in palettes of the Controls palette. LabVIEW has four types of "simple" controls and indicators: numeric, Boolean, string, and paths. You will also encounter a few more complex data types such as arrays, clusters, tables, charts, and graphs that we will expand on later.

The Controls palette is visible only when the front panel window is active, NOT when the block diagram is up. You can drive yourself crazy looking for it if you don't keep this in mind.


When you need to enter numeric or text values into any controls or indicators, you can use the Operating or Labeling tool. New or changed text is not registered until you press the <enter> key on the numeric keypad, click the enter button on the Toolbar, or click outside the object to terminate the editing session.

Hitting the <enter> key (Windows and Linux) or <return> key (Mac OS X) on the alphanumeric keyboard (NOT the one on the numeric keypad) enters a carriage return and does NOT register your change (unless you've configured your system otherwise, by checking the End text entry with Enter key option in the LabVIEW Options window, under the Environment options category). You must use the <enter> key on the numeric keypad to enter text to LabVIEW. If you must use the alphanumeric keyboard, hit <ctrl-enter> (Windows), <alt-enter> (Linux), or <option-return> (Mac OS X) to enter text.


Numeric Controls and Indicators

Numeric controls allow you to enter numeric values into your VIs; numeric indicators display numeric values you wish to see. LabVIEW has many types of numeric objects: knobs, slides, tanks, thermometers, and, of course, the simple digital display. To use numerics, select them from the Modern>>Numeric subpalette of the Controls palette (see Figure 4.17). All numerics can be either controls or indicators, although each type defaults to one or the other. For example, a thermometer defaults to an indicator because you will most likely use it as one. By contrast, a knob appears on the front panel as a control because knobs are usually input devices.

Figure 4.17. Modern>>Numeric subpalette of the Controls palette


Representation

The appearance of numeric terminals on the block diagram depends on the representation of the data. The different representations provide alternative methods of storing data, to help use memory more effectively. Different numeric representations may use a different number of bytes of memory to store data, or may view data as signed (having the capacity for negative values) or unsigned (having only zero or positive values). Block diagram terminals are blue for integer data and orange for floating-point data (integer data has no digits to the right of the decimal point). The terminals contain a few letters describing the data type, such as "DBL" for double-precision floating-point data.

The numeric data representations available in LabVIEW are shown in Table 4.1, along with their size in bytes and a picture of a digital control terminal with that representation in the View As Icon setting (which is available from the terminal's pop-up menu) selected and not selected.

Table 4.1. Numeric Representations

Representation

Abbreviation

Terminal (Icon)

Terminal

Size (bytes)

byte

I8

1

unsigned byte

U8

1

word

I16

2

unsigned word

U16

2

long

I32

4

unsigned long

U32

4

quad

I64

8

unsigned quad

U64

8

single precision

SGL

4

double precision

DBL

8

extended precision

EXT

10[a]/12[b]/16[c]

complex single

CSG

8

complex double

CDB

16

complex extended

CXT

20[a]/24[b]/32[c]


[a] Windows

[b] Mac OS X

[c] Linux

You can change the representation of numeric constants, controls, and indicators by popping up on the object and selecting Representation>>. Remember, you pop up on a numeric control or indicator by right-mouse-clicking. You can then choose from the palette shown in Figure 4.18.

Figure 4.18. The Representation pop-up submenu of numeric datatypes


If you are concerned about memory requirements, you will want to use the smallest representation that will hold your data without losing information, especially if you are using larger structures like arrays. Adapt To Source automatically assigns the representation of the source data to your indicatora good habit to get into. LabVIEW also contains functions that convert one data type to another, which will be covered in detail in Chapter 9, "Exploring Strings and File I/O," and in Chapter 14, "Advanced LabVIEW Data Concepts."

Format and Precision

LabVIEW lets you select whether your digital displays are formatted for numeric values or for time and date. If numeric, you can choose whether the notation is floating point, scientific, or engineering. If time, you can choose absolute or relative time in seconds. You can also choose the precision of the display, which refers to the number of digits to the right of the decimal point, from 0 through 20. The precision affects only the display of the value; the internal accuracy still depends on the representation.

You can specify the format and precision by selecting Format & Precision . . . from an object's pop-up menu. The dialog box shown in Figure 4.19 appears. If you'd rather show time and date, choose Absolute Time from the listbox and your dialog box will change accordingly (see Figure 4.20).

Figure 4.19. Format and Precision tab of the Numeric Properties dialog


Figure 4.20. Configuring a numeric to display absolute time


Numeric Range Checking

LabVIEW gives you the option to enforce user input data to a certain valid range of numeric values and increments of data. For example, you might only want to allow an input between zero and 100, in increments of two. You can set range checking by popping up on the appropriate numeric value and selecting Data Range . . . .

From the dialog box that appears (see Figure 4.21), you can leave the default representation (by leaving the box checked), or you can change numeric representation, input maximum and minimum acceptable values, set the increments you want, and change the default value for that object, as well as select a course of action to follow if values are out of range.

Figure 4.21. Data Range tab of the Numeric Properties dialog


  • If you choose to Ignore out-of-range values, LabVIEW does not change or flag them. Clicking on the increment or decrement arrows of a control will change the value by the increment you set, up to the maximum values (or down to the minimum). However, you can still type in or pass a parameter out of the limits.

  • If you choose to Coerce your data, LabVIEW will set all values you type in below the minimum to equal the minimum and all values above the maximum to equal the maximum. Values in improper increments will be rounded.

Numeric range and increment checking is only applicable to user input into front panel controls. It has no effect on values that are passed into a subVI's terminals (controls that have been wired to the subVI's connector pane)in this case, coercion does not occur and the values are passed into the controls, unchanged.


Rings

Rings are special numeric objects that associate unsigned 16-bit integers with strings, pictures, or both. You can find them in the Modern>>Ring & Enum and Classic>>Classic Ring & Enum subpalettes of the Controls palette. They are particularly useful for selecting mutually exclusive options such as modes of operation, calculator function, and so on.

When you create a ring, you enter text or paste a picture into the ring that becomes associated with a certain number (zero for the first text message, one for the next, and so on). You can see this number (shown in Figure 4.22) by selecting Visible Items>>Digital Display from the ring's pop-up menu.

Figure 4.22. Ring controls


A new ring contains one item with a value of zero and an empty display. If you want to edit the items in the ring, select Edit Items . . . from the pop-up menu and a dialog will appear, as shown in Figure 4.23.

Figure 4.23. Edit Items tab of the Ring Properties dialog


The "Items" in the previous Ring Properties dialog are the text lines that will show up in the ring as the possible options to the user.

The "Values" are the numeric values that the block diagram will use for each item.

By default, LabVIEW creates sequential values for you (0, 1, 2, 3 . . .) for each item, so normally you do not need to worry about or edit this property.

If you click on a ring with the Operating tool, you will see a list of all possible messages or pictures, with the current one checked, as shown in Figure 4.24.

Figure 4.24. The list of ring items, shown after clicking on the ring with the Operating tool


Rings are useful if you want a user to select an option that will then correspond to a numeric value in the block diagram. Try dropping a ring on the front panel; then show the digital display and add a few items.

When adding items into a Ring, press <shift-enter> (Windows and Linux) or <shift-return> (Mac OS X) to complete the entry of the current item and add another black ring item after the item just entered. The key focus will remain in the new ring item, so you can quickly enter the new item. This is an extremely fast way to enter multiple sequential items. To quickly edit non-sequential items, use the Edit Items option from the pop-up menu, as previously described.


Booleans

Booleans are named for George Boole, an English logician and mathematician whose work forms the basis for Boolean algebra. For our purposes, you can think of Boolean as just a fancy word for "on or off." Boolean data can have one of two states: true or false. LabVIEW provides a myriad of switches, LEDs, and buttons for your Boolean controls and indicators, all accessible from the Modern>>Boolean and Classic>> Classic Boolean subpalette of the Controls palette (see Figures 4.25 and 4.26). You can change the state of a Boolean by clicking on it with the Operating tool. Like numeric controls and indicators, each type of Boolean has a default type based on its probable use (i.e., switches appear as controls, and LEDs as indicators).

Figure 4.25. Modern Boolean controls


Figure 4.26. Classic Boolean controls


Boolean terminals appear green on the block diagram and contain the letters "TF." With the View As Icon option selected (from a terminal's pop-up menu), the terminal will be displayed as an icon that reflects the specific type of Boolean control or indicator, as shown in Figure 4.27.

Figure 4.27. Boolean controls and indicators (top) with terminals (bottom) in View As Icons mode


Control terminals have thick borders along with an arrow pointing out from the right, while indicator borders are thin and have an arrow pointing in from the left. It is very important to distinguish between the two since they are not functionally equivalent (Control=Input=data source; Indicator = Output = data sink, so they are not interchangeable).


Labeled Buttons

LabVIEW has three buttons with text messages built into them: the OK, Cancel, and Stop buttons.

Not just these three, but all Booleans also have a Visible Items>>Boolean Text option that will display the word "ON," "OFF," depending on their states. This text is merely informative for the user. Each labeled button can contain two text messages: one for the TRUE state and one for the FALSE state. When you first drop buttons, the TRUE state says "ON" and the FALSE state says "OFF." You can then use the Labeling tool to change each message.

Note that clicking the mouse on the Boolean text of a button is the same as clicking on the button itself. However, the same is not true for a button's label or caption. If you move a label or caption over the button, clicking on the label or caption will have no resultit "blocks" the button from the user. This can be not only annoying, but dangerous, if a user cannot press an important button, such as one that aborts a machine operation.


Mechanical Action

A Boolean control has a handy pop-up option called Mechanical Action, which lets you determine how the Boolean behaves when you click on it (e.g., whether the value switches when you press the mouse button, switches when you release it, or changes just long enough for one value to be read and then returns to its original state). Mechanical Action is covered in more detail in Chapter 8, "LabVIEW's Exciting Visual Displays: Charts and Graphs."

Customizing Your Boolean with Imported Pictures

You can design your own Boolean style by importing pictures for the TRUE and FALSE state of any of the Boolean controls or indicators. You can learn more about how to do this in Chapter 17, "The Art of LabVIEW Programming."

Strings

Simply put, string controls and indicators display text data. Strings most often contain data in ASCII format, the standard way to store alphanumeric characters. String terminals and wires carrying string data appear pink on the diagram. The terminals contain the letters "abc." You can find strings in the Modern>>String & Path and Classic>>Classic String & Path subpalettes of the Controls palette, shown in Figure 4.28 and Figure 4.29.

Figure 4.28. Modern string controls


Figure 4.29. Classic string controls


Although string controls and indicators can contain numeric characters, they do NOT contain numeric data. You cannot do any numerical processing on string data; that is, you can no more add an ASCII "9" character than you can an "A." If you need to use numeric information that is stored in string format (to perform arithmetic, for example), you must first convert it to numeric format using the appropriate functions (see Chapter 9). It is a good practice to use only numeric controls and indicators for data that will contain numbers.


String controls and indicators are fairly simple. Their pop-up menus contain few special options:

  • Enable Wrapping occurs where lines of text that are wider than the string control are "wrapped" around and continue on the next line of the string control. This option is enabled by default.

  • Visible Items>>Vertical Scrollbar shows and hides the vertical scrollbar.

  • Visible Items>>Horizontal Scrollbar shows and hides the horizontal scrollbar. This option is disabled when Enable Wrapping is enabled. (There is no reason to scroll horizontally, because lines of text never extend past the right edge of the string control when wrapping is enabled.)

  • Limit to Single Line prevents the user from adding multiple lines of text to a string control. Instead, pressing the <enter> or <return> key causes the value to be applied to the string control.

  • Update Value While Typing causes the control value to change (as read from the terminal on the block diagram, etc.) each time the user types a keystroke. Otherwise, the user must apply the change by clicking outside the string control, pressing the apply button, etc.

We'll talk more about strings and their more complex cousin, the table, in Chapter 9.

Combo Box Control

The combo box control is similar to a text ring control, in that it has a list of strings; however, the value of the combo box is the selected string itself rather than the numeric index of the selected string within the list of strings. You can edit the list of strings, just as you would a ring controlpop up on the combo box and select Edit Items . . . from the shortcut menu. One very cool and little known feature of the combo box is that the user can type values directly into the text area and the combo box will auto-complete the text to match the first, shortest string from the items list that begins with the letters you type. And, you can select the Allow Undefined Strings option from the pop-up menu to allow users to enter values that are not in the list of items. This is a very powerful control that many people don't know about, so give it a try and impress your LabVIEW friends!

Paths

You use path controls and indicators to display paths to files, folders, or directories. If a function that is supposed to return a path fails, it will return <Not A Path> in the path indicator. Paths are a separate, platform-independent data type especially for file paths, and their terminals and wires appear bluish-green on the block diagram. A path is specified by drivename followed by directory or folder names and then finally the filename itself. On a computer running Windows, directory and file names are separated by a backslash (\) (see Figure 4.30); on Mac OS X, folder and file names are separated by a colon (:) (see Figure 4.31); on Linux machines, a forward slash (/) separates files and directories (see Figure 4.32). You'll learn more about paths in Chapter 9 and Chapter 14.

Figure 4.30. Windows path


Figure 4.31. Mac path


Figure 4.32. Unix path


Decorations

Just for fun, you can use LabVIEW's special Decorations subpalette of the Controls palette to enhance your front panel's appearance. These decorations have a solely aesthetic functionthey are the only objects from the Controls palette that do not have corresponding block diagram terminals (aside from the subpanel, which we will discuss in Chapter 13, "Advanced LabVIEW Structures and Functions").

Custom Controls and Indicators

To make programming even more fun, LabVIEW lets you create your own custom controls and indicators. So if LabVIEW doesn't provide exactly the one you want, make your own! You'll learn how to do that in Chapter 17.

Summary of Basic Controls and Indicators

Just to make sure you get your data types straight, we'll recap the four types of simple controls and indicators:

Numerics contain standard numeric values.

Booleans can have one of two states: on or off (true or false, one or zero).

Strings contain text data. Although they can contain numeric characters (such as zero to nine), you must convert string data to numeric data before you can perform any arithmetic on it.

Paths give you a platform-independent data type, especially for file paths.




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