Radices and Units


A useful feature of LabVIEW numeric types is that you can manipulate them as more than just pure numbers. Normally, you represent numbers in decimal format. But for some applications, you may need to view numbers in a binary or hexadecimal representation. Similarly, you may want to treat certain numerical variables as having an associated unit (such as feet, calories, or degrees Fahrenheit)especially if you plan to do unit conversions. You can choose a different number base (called a radix) independently for any LabVIEW numeric control or indicator. That choice has no effect on the value of the underlying number; it only affects its visual display. You can also associate a unit with the control or indicator, and that unit will propagate into the actual number in the attached wire and be preserved, enforced, and appropriately modified by any math performed on the signal.

Radices

LabVIEW's numeric displays are very flexible. You can choose to display numbers in decimal, hexadecimal, octal, or binary format by selecting Visible Items>>Radix from the numeric's pop-up menu. Click with the Operating tool (do NOT pop up) on the tiny letter that appears, and you'll pull down a radix selection menu (see Figure 15.67).

Figure 15.67. Adjusting the radix of a numeric control


If your numeric is not an integer (DBL, for example), all radix options except for Decimal and SI Notation are disabled (see Figure 15.67).


Figure 15.68. Numeric controls having the same data, but configured with different radix displays


A user who is working with digital I/O, for example, might find it very useful to represent a numeric control in binary, because it would be easy to see the one-to-one correspondence of each digit to each digital line.

Units

Any floating-point numeric control can have physical units, such as meters or kilometers/second, associated with it. You can access the unit label by selecting Visible Items>>Unit Label from an object's pop-up menu.

Once the unit label is displayed, you can enter a unit using standard abbreviations such as m for meters, ft for feet, etc. (see Figure 15.69). If you enter an invalid unit, LabVIEW flags it with a ? in the label. If you want to know which units LabVIEW recognizes, enter a simple unit such as m, and then pop up on the unit label and select Unit . . . . A dialog box will pop up, showing you information about LabVIEW's units (see Figure 15.70).

Figure 15.69. Selecting Build Unit String . . . from the pop-up menu of the units display launches the Build Unit String dialog


Figure 15.70. Build Unit String dialog


Any numeric value with an associated unit is restricted to a floating-point data type.


LabVIEW preserves the associated unit throughout any operations performed on the data. A wire connected to a source with a unit can only connect to a destination with a compatible unit, as shown in Figure 15.71.

Figure 15.71. Multiplying numbers that have units (output in km)


When we say "compatible," we mean that the destination unit has to make sense from a physical or mathematical point of view. The destination unit does not have to belong to the same classification system (e.g., SI versus English units), as shown in Figure 15.72. Thus, you can transparently convert compatible units from different systems in LabVIEW.

Figure 15.72. Multiplying numbers that have units (output in ft)


You cannot connect signals with incompatible units, as shown by the broken wire in the block diagram of Figure 15.73. If you try, the error window (discussed soon) will contain a block diagram error: You have connected numeric data types that have incompatible units.

Figure 15.73. Multiplying numbers that have units (output in degC does not work since it is not a unit of length)


Some functions are ambiguous with respect to units and cannot be used if a unit is assigned to the data you are trying to operate on. For example, if you are using distance units, the Add One function cannot tell whether to add one meter, one kilometer, or one foot.


Finally, you need to be wary of doing arithmetic that combines numbers with and without units. Well, not really wary, just aware. For example, you can multiply a unitless constant times a number with a unit, but you cannot subtract a number with a unit from a number without a unit. But you don't have to worry about thatLabVIEW enforces the rules with broken wires! Even better, it will prevent you from calculating force as mass times velocity because you forgot a factor deep in a twenty-step derivation.

LabVIEW allows you to "add" a unit to a unitless number using the Convert Unit function (from the Programming>>Numeric>>Conversion palette), shown in Figure 15.74.

Figure 15.74. Convert Unit: Converts a physical number (a number that has a unit) to a pure number (a number with no units) or a pure number to a physical number. To configure the units string, pop up on the Convert Unit function and select Build Unit String.


Figure 15.75 shows an example of how we can use the Convert Unit function to add units to a number.

Figure 15.75. Converting a pure number (no units) to a physical number (with units) using the Convert Unit function


To specify the unit, just type the unit inside the middle box of the terminal or, as with numeric types, pop up on the terminal and select Build Unit String . . . for a list of valid units. The Convert Unit function also allows you to "strip" units from a number (convert a number with units to a pure number).

Simple Unit Conversion: A Great Trick to Know

One very powerful trick that every LabVIEW developer should know is that you can quickly convert the units of a pure number (one without any units) by cascading two Convert Unit functions. Figure 15.76 shows two examples of this.

Figure 15.76. Using two Convert Unit functions is an easy way to convert the units of pure numbers.


Configure the upstream Convert Unit function with the incoming pure number's units and the downstream function with the outgoing pure number's units. It's as easy as that!




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