LabVIEW Basics 02 - For/While Loop/Event/Condition/Sequence/Block Diagram Disabled Structure

Table of contents

1. For loop

1.1 Shift register

1.2 Tunnel Mode

2. While loop

3. Conditional structure

4. Event structure

5. Sequential structure

6. Block Diagram Disable Structure


1. For loop

Set the total number of loops at N in the upper left corner . If you want the internal program of the For loop to be executed n times, set the total number of loops to n;

The lower left corner shows the loop count terminal, starting from 0, and when the loop runs completely, it outputs n-1.

The For loop can display the condition terminal like the While loop, and it can be displayed in its right-click shortcut menu.

 There are two forms of conditional terminals:


1.1 Shift register

You can add a shift register in the right-click shortcut menu of the For loop . The shift register is actually to move the previous value/variable/parameter to the beginning and then execute it, because the last data is stored and moved to the beginning to continue Variables are brought into execution, so they are called shift registers . The following demonstrates the use of shift registers to create arrays.


1.2 Tunnel Mode

Tunneling occurs when data flows through a For loop or other structure.

final value: the last value at the end of the loop;

Index: keep the results of each operation, value → one-dimensional array, one-dimensional array → two-digit array

Connection: The connection is for the array, and the array of each operation is connected;

Condition: Output data that meets the condition.

final value, index, condition

connect

2. While loop

While loop does not have loop count input port, as long as the stop condition of the conditional terminal is not met, the program inside the While loop will keep running.

 On the right-click shortcut menu of the While loop, it can be replaced with the For loop.


3. Conditional structure

In general, the case structure executes the corresponding true branch or false branch according to the Boolean data type of the conditional terminal, the true branch is executed if the input is true, and the false branch is executed if the input is false.

The data type of the conditional terminal of the conditional structure does not have to be Boolean . For various states, you can use the enumeration control to select. (Essentially an integer value)

Edit the item in the right-click shortcut menu of the enumeration control to set the condition name we need.

Then connect the enumeration to the case structure terminal, right-click on the selector label and select "Add branch for each value" to add a subdiagram for each value.

Or the corresponding subprogram block diagram can be executed according to the magnitude of the input value.

If there are not enough branches, there is also "Add branch before or after this branch" in the right-click shortcut menu, and you can use "Rearrange branches" to sort the branches.


4. Event structure

The event structure is a structure dedicated to programming actions generated on the front panel , and it is extremely important. For example, if we click Close in the upper right corner when the program is running, our front panel will be closed. Closing the front panel is an action. We can use the event structure in the program block diagram to program to stop the program when the front panel is closed without closing the front panel .

 Right-click on the event structure and click "Add Event Branch", the added content is shown in the figure below.

The program block diagram is as follows:

 In this way, when the program is running, we can stop the program by closing the front panel.

The following two pictures simply demonstrate the simple example of the mouse entering the Boolean light to make the light on, and leaving the Boolean light to make the light off.

The timeout period is indicated on the upper left corner of the event structure. If no event is triggered within the specified time, the timeout branch will be executed. Setting -1 means that the event structure will never timeout.


5. Sequential structure

The biggest feature of LabVIEW is the data flow drive, so the program will not necessarily be executed in the order of the graphics code, which is the biggest difference from the traditional text programming language.

If it is necessary to specify the sequential execution order of a certain code, it can be realized with a sequential structure. The sequence structure contains one or more subprogram blocks or frames that are executed in sequence. The frame structure is used in the program to control the execution sequence of the program. After the program in a frame is executed from left to right , the program in the next frame is executed. .

As shown in the example above, the difference between the two time counters is the execution time of the Sub VI.

The above figure shows a flat sequence structure, which can be transformed into a stacked sequence structure, but the flat sequence structure display is more intuitive.

 Execute in numerical order from small to large, [0..2] means that there are three steps of 0, 1, and 2 to be executed.


6. Block Diagram Disable Structure

Putting the program block diagram on the program that does not need to be executed temporarily can disable this segment of the program, so as to prevent the program block diagram from reporting an error and failing to run. It is often used when debugging the program.

 If the debugging is completed, you can right-click on the disabled structure of the block diagram to restore this segment of the program and select "Delete Disabled Block Diagram Structure" from the pop-up shortcut menu.

Guess you like

Origin blog.csdn.net/m0_64651092/article/details/130484768