Combining the While Loop and Case Structure in LabVIEW

Publisher:快乐球球Latest update time:2016-08-03 Source: eefocusKeywords:LabVIEW Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  Like all tool software, the various functions and structures in LabVIEW can only create actual applications by combining them. Just like when you build a house, you can't just use a hammer or a saw. You can only make good things by combining these two tools. The same theory applies to your LabVIEW test program development. The structures and functions in LabVIEW are our various tools. We rarely use one of them alone. In actual programs, they are used together. Here, we start with a single While loop structure , which will be like a chainsaw and will not stop until you press the off switch. After that, we will add a Case structure , which will handle all possible situations of the software. In fact, the combination of While loop + Case structure is very powerful. Using this combination, you can create almost any application software you can think of.

Main Loop

  Almost all LabVIEW programs have at least one main loop that will continue to loop until the program ends. The program may end because of a stop button, an error, or other reasons. The following figure shows an example of a While Loop with a standard wait function (to prevent the program from monopolizing the CPU) and a stop button. 

Combining the While Loop and Case Structure in LabVIEW - Senple Chan - Life++
  Now add a Case structure to the While loop and connect a button. In the TRUE case of the Case structure , we add our work function or subVI to do something useful. The following block diagram is such an example. In the example below, when the Do button is pressed, a "Hello World!" dialog box will pop up. (However, you need to set the Do button to Mechanical Action >>Latch When Released to ensure that the Hello World dialog box only appears once after the button is pressed)

 

 

Combining the While Loop and Case Structure in LabVIEW - Senple Chan - Life++
 

 

  This combination of While loop + Case structure is the basis for creating LabVIEW applications.

Handling Multiple Events in a While Loop

  Let's start further discussion. What if there are multiple buttons? The simplest way is to add multiple Case structures in the While loop as shown below. This method is easy at the beginning, but it will be troublesome once you have more Case structures .

Combining the While Loop and Case Structure in LabVIEW - Senple Chan - Life++
  

 

  Now we know how to handle multiple events by combining While loop + Case structure. Similarly, if we want to handle N events, we can add N Case structures in the While loop. But what if there is not enough space in the flowchart? In this case, the solution of "adding another Case structure" is not so suitable. The solution to this situation is actually very simple, which is to create a Case structure with multiple cases, each case in this structure corresponds to an event.

  In order to realize this idea, we need to create an array of Boolean variables, save the value of each button in this array and search the serial number of the element with the value TRUE in the array. Through this serial number, we can know which button is pressed and enter the number of the button into the case selection endpoint of the Case structure, and then the relevant operation corresponding to the button will be executed. As shown in the following figure: 

Combining the While Loop and Case Structure in LabVIEW - Senple Chan - Life++

 

  Now if you want to add a new event, you just need to add a new element to the array and add a corresponding case in the Case structure.

  However, in actual use, we usually use enumerated type (enum) data to connect the case selection endpoints of the Case structure instead of straight I32 type integer data.


Keywords:LabVIEW Reference address:Combining the While Loop and Case Structure in LabVIEW

Previous article:Automatic Indexing of Arrays in LabVIEW
Next article:Three principles to follow when designing VI

Recommended ReadingLatest update time:2024-11-23 07:35

How to correctly understand EXPRESS XY GRAPH in LABVIEW
   The XY graph can be said to be the most flexible control of Labview data graphic display control. It can replace most of the functions of waveform graph and waveform chart. Its input parameter form has many changes. In the following two articles, the various uses of XYGRAPH are discussed in detail.   Express VI (
[Test Measurement]
How to correctly understand EXPRESS XY GRAPH in LABVIEW
Labview stack and queue
Synchronous control technology - stack and queue (Many of the pictures are not immediately visible. To view them, right-click the picture, select Copy Picture Address, and then open it in the browser. Because this article is an excerpt, please forgive us for any inconvenience caused to you!)  
[Test Measurement]
Labview stack and queue
FCT (Functional Circuit Test) Test System Based on PXI and LabVIEW
Challenge: Through PXI control board and LabVIEW software, a relatively complete PCB board functional test (FCT) system is built. The system can realize comprehensive and fully automatic testing of audio, video and various static parameters (voltage, current, frequency). For newly developed and produced PCB boards, the
[Test Measurement]
FCT (Functional Circuit Test) Test System Based on PXI and LabVIEW
Biofluid Perifusion System Automates Cell Secretion Analysis
Biorep Biofluid Perfusion System Challenge: Improve the throughput and reproducibility of cell secretion assays, which are commonly used to analyze pancreatic islet cells in type 1 diabetes research. Solution: Using NI LabVIEW software and CompactRIO hardware, we created an automated biofluid perfusion system that
[Test Measurement]
Biofluid Perifusion System Automates Cell Secretion Analysis
Cost-effective aircraft noise test system based on LabVIEW
industry: Aviation/Aerospace product: PXI-6653, PXI-4462, LabVIEW , PXI-PCI8336, PXI-6651 challenge: Create a scalable, cost-effective system to test the effectiveness of a new design for reducing noise during takeoff, landing and ongoing flight on commercial jetliners
[Test Measurement]
Cost-effective aircraft noise test system based on LabVIEW
In-depth exploration of LabVIEW: Can LabVIEW read and write physical memory?
Friends who are familiar with LABVIEW know that LABVIEW provides IN OUT instructions similar to assembly language, which can directly operate computer ports. This is prohibited in general programming languages, reflecting LABVIEW's powerful hardware control capabilities.   In addition to directly operating ports, we
[Test Measurement]
In-depth exploration of LabVIEW: Can LabVIEW read and write physical memory?
Learning LabVIEW (V) - Feedback Nodes and Iterative Operations
       Sometimes we need to perform the following iterative operations: x = init(); for i in range(30):        x = f(x) print xI thought about it and thought that this operation can probably be implemented in G language using feedback nodes. The basic usage of feedback nodes is very simple. Connecting the output
[Test Measurement]
Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号