• No results found

PROGRAMMING PREVIEW: DEBUGGING

In document Labview Engineers (Page 102-107)

LabVIEW Math Functions

1. Show context help with block diagram menu options: Help / Show ContextHelp

3.6 PROGRAMMING PREVIEW: DEBUGGING

LabVIEW’s graphical programs mean that the process of debugging will be highly visual as well. While that makes things easier, LabVIEW is such a different approach to programming for most new users, it is not difficult to generate errors that can occasionally be hard to find and fix

LabVIEW provides several tools to help get your VIs running, and running correctly.

• Broken wires—an early warning that something is not working correctly

• Broken Run Button—indicates that the VI will not run, but if you click the broken Run button you will see a list of error messages

• Execution Highlighting—you can watch the flow of information through your block diagram

• Single-Step Execution—you can run the VI step by step to see where something goes wrong

• Probe Tool—you can test to see what any wire contains

• Breakpoints—you can set a breakpoint to stop the program at a point of interest 3.6.1 Fixing Broken Wires

The first error checking is done at the point of wiring the nodes on the block diagram.

If a connection is not allowed, LabVIEW will show a broken wire. Broken wires must be fixed before the VI will run.

If you move your mouse over the broken wire, LabVIEW will display a message indicating the problem with the attempted connection.This is illustrated in Figure 3.47.

The most common problem with broken wires is mismatched data types. There are two solutions:

• Determine why the data type is mismatched and change the incorrect item.

• Convert from one data type to another.

The latter approach often seems reasonable to people new to LabVIEW; it usually leads to trouble eventually. Unless you know why you need to use a data type conversion function, it’s probably a good idea to try to fix the problem instead.

3.6.2 Using the Broken Run Button

The broken Run button, shown in Figure 3.48 is an indicator that the VI will not run in its current form. You commonly see the broken Run button when you are in the process of wiring the VI. When that last connection is made and the broken Run button goes away, you have a lot of hope that the VI will run successfully.

Figure 3.47 Error messages about broken wires appear when you move the mouse over the break.

Figure 3.49

The Error List is displayed when the broken Run button is clicked.

But the broken Run button does even more than tell you there’s a problem. If you click the broken Run button LabVIEW will display the Error List, as shown in Figure 3.49.

Figure 3.48 The Broken Run Button indicates a problem with the VI.

The Error List describes each error and, if you click the Show Error button, will highlight the problem on the VI itself.

3.6.3 Execution Highlighting

LabVIEW is a dataflow programming language. Dataflow programming means that a node (or block) on a block diagram executes as soon as all of the inputs have values. Sometimes seemingly odd results happen because LabVIEW is per-forming calculations in a different order than you expected. You can use execution highlighting to determine the order in which tasks are carried out in your LabVIEW programs.

Section 3.6 Programming Preview: Debugging 89

To highlight execution (from the block diagram):

1. Click the Highlight Execution button (looks like a lightbulb).

2. Click the Run button.

The VI will slowly execute, and LabVIEW will display the progress on the block diagram by showing the wires containing calculated data values in full color instead of being grayed out. In Figure 3.50 the Tank High Warning VI is about halfway through.

Notice that the Level and Alarm controls show values. That indicates that they have already been evaluated. The Boolean controls (e.g., Pump Power switch) show “F”

when they evaluate False.

Figure 3.50

The Tank High Warning VI, running with highlighted execution.

Execution highlighting is kind of fun to watch once in a while, but it can also be very useful in determining how the VI is actually calculating.

3.6.4 Single-Step Execution

Sometimes you need to slow down the execution even further, and you can execute the VI step by step using the Step Into and Step Over buttons on the block dia-gram’s toolbar.

• Step Into—Follow the progress into Loop structures.

• Step Over—Follow the progress but skip over Loop structures.

With single-step execution you can pinpoint where a problem is occurring.

3.6.5 Probes

You can use the Probe Tool to determine the contents of any wire while the VI is running (either at full speed, or with execution highlighting on to slow the speed of execution) or before running the VI.

To set up a probe on a wire before the VI is running, display the Tools Palette (View / Tools Palette) and select the Probe Tool. Then, click on the wire that you

want to probe. In Figure 3.51 the probe is being placed on the wire leaving the Alarm Level control.

Once the probe is in place, when the VI is running, the value in the probed wire is displayed. This is illustrated in Figure 3.52.

3.6.6 Breakpoints

A breakpoint is a location in a program where the program execution is tem-porarily halted. This gives the programmer a chance to probe around to see what’s happening.

• If a program is crashing, breakpoints can be used to see what is happening just before the VI crashes.

• If a program is calculating strange values, breakpoints can be used to follow the progress of the program to see where things go awry.

To set a breakpoint, right-click on a node or wire in the block diagram, and select Set Breakpoint from the pop-up menu. In Figure 3.53 a breakpoint was set just downstream of the Greater Than function.

When the VI executes, execution will stop at the breakpoint, but the wires will still have values so you can use the probe tool to see what’s happening.

To clear the breakpoint, right-click on a breakpoint, and select Clear Breakpoint from the pop-up menu.

Debugging any program is a chore, but LabVIEW provides the tools to let you know what’s going on inside the program, and that is a big help.

Figure 3.51

Placing a probe on the wire leading to the A ⴙ B indicator.

Section 3.6 Programming Preview: Debugging 91

Figure 3.52

Probe 4 indicates that the value in the wire is 80.

Figure 3.53

A breakpoint has been set just after the Greater Than function.

KEY TERMS Add function

And function Body Mass Index

(BMI)

Boolean functions breakpoint

Broken Run Button broken wires comments

comparison functions Context Help

dataflow programming debugging

Dial Numeric Control Divide function Error List

Exclusive Or function Execution Highlighting

exponential Express VI

first-order response Formula Express VI Formula function Function

Hyperbolic Trigonometric functions

integer quotient

Multiply function

Building a VI (General Approach) 1. Create a blank VI:

• From LabVIEW Getting Started window: New Panel/Blank VI

• From an open VI: File/New VI On the front panel . . .

2. Add needed controls and indicators

In document Labview Engineers (Page 102-107)