5 mistakes that new LabVIEW developers must make

Publisher:之敖赵先生Latest update time:2013-09-28 Keywords:LabVIEW Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

While NI LabVIEW software has long helped engineers and scientists quickly develop functional measurement and control applications, not all new users follow LabVIEW programming best practices. LabVIEW graphical programming is unique because it is immediately apparent whether a user is following coding best practices by just looking at their application. Some users make these mistakes because they do not truly understand the principles behind the data flow of a LabVIEW block diagram, while others simply do not know which features improve the quality of their LabVIEW programming.

  This article describes some of the most common programming mistakes made by inexperienced LabVIEW programmers and provides suggestions for adopting correct LabVIEW programming methods.

  Figure 1. A typical LabVIEW novice's masterpiece

  Overuse of Flat Sequence Structures

  Many people who are new to LabVIEW do not fully understand the concepts behind "data flow" execution, which is the foundation of LabVIEW programming. One of the manifestations is that users tend to overuse Flat Sequence structures in the block diagram. Users often rely on Flat Sequence structures to implement the serial execution of code in the block diagram instead of using data flow and wires between nodes.

  Figure 2. Users often over-rely on flat sequence structures without fully understanding dataflow programming concepts.

  Dataflow programming means that nodes (subVIs, primitives, structures, etc.) on the block diagram will only start executing when all required data inputs arrive. This is very useful for programmers using LabVIEW because independent processes can run in parallel by themselves, while imperative languages ​​require additional settings to implement parallel execution. As computer CPUs continue to increase, LabVIEW can automatically decompose parallel processes and improve code performance without the user having to write any additional code. Forcibly using flat sequential structures to execute program flowcharts will not only limit parallel execution, but also lose this advantage. Limiting unnecessary structures in the program flowchart can help improve overall readability and maintain a more concise flowchart.

  Error wires are an efficient way to implement data flow on a block diagram without relying on Flat Sequence structures and can help implement error handling strategies.

  When should I use a Flat Sequence structure?

  Executing a block diagram with a Flat Sequence structure can help benchmark the performance of your code. By using a Sequence structure with a tick counter inside the frame, you can determine the time taken for code execution between two tick counters. This is not possible with normal dataflow execution.

  Figure 3. The Flat Sequence structure and Tick Counter VI can help you benchmark your code.

  For more information about dataflow programming, visit the online self-paced training (ni.com/self-paced-training) for the LabVIEW Core Course 1 course, Dataflow. The online self-paced training is available at no charge to customers who have purchased LabVIEW or have a membership to the Standard Service Program (ni.com/SSP).

  Incorrect use of local variables

  Another common mistake in LabVIEW programming is overusing local variables. A local variable is an area in shared memory that is used to pass data between different parts of a computer program. Local variables are commonly used in text-based programming languages ​​and are very powerful, but they can cause problems if race conditions occur.

  For other programming languages, passing data through variables is necessary, while LabVIEW provides a data flow method to move data from one part of the program to another. The inherent parallelism mechanism of LabVIEW determines that users cannot overuse variables because there are usually multiple programs in different locations accessing shared memory at the same time. If variables are overused, a read/write operation will win the "competition" while other operations will lose the "competition", and the operation that loses data will be ignored, so overusing variables in LabVIEW may eventually lead to data loss.

  You can safely pass data from one part of a LabVIEW program to another through a variety of methods, including wires, queues, events, notifications, function global variables, and more. Each mechanism is designed for a specific situation, but all have the ability to eliminate race conditions.

  For more information about correctly moving data within a LabVIEW program, refer to the online self-paced training at ni.com/self-paced-training for the course “Local Variables” in LabVIEW Core Course 1 and the course “Notifications, Queues, and Events” in LabVIEW Core Course 2.

  Ignoring code modularity

  Often, new LabVIEW users create "fire and forget" applications to accomplish simple tasks without considering whether the code will be needed in the future. As the programming workload grows, they find themselves rewriting the same code over and over again. If you create a modular subVI that can be reused in other applications while you are programming, you can save a lot of development time.

  If you know that a particular section of code will be reused in the same application, or feel that it may be used in future applications, you should take a moment to turn that section of code into a subVI. To make a section of code a subVI, the main things you need to do are add a document, use Terminals, and disable certain VI properties. One of the easiest ways to create a subVI is to highlight a section of code on the block diagram and select Edit >> Create SubVI from the menu bar. This will place the section of code into a separate VI and use Terminals. You will still need to add a description to the icon, add documentation to the block diagram and VI properties, and disable certain VI settings, but Edit >> Create SubVI will give you a good idea of ​​the modularity of your code.

  Figure 4. Using the correct approach to modularizing your LabVIEW code can help you save a lot of development time.

  One setting that must be turned off when modularizing code is "Allow debugging." You can find this option in the "Execution" category under "VI Properties (File>>VI Properties)." When the code is fully functional and no longer requires debugging features such as execution highlighting, turn off "Allow debugging" in the execution settings and run the VI again. The benefits of this are that the application may run faster due to optimizations performed during the compilation process, and the physical space occupied by the VI on disk is also reduced because the code that enables debugging is turned off.

  For more information about code modularization, go to the self-paced online training course "Understanding Modularity" in the LabVIEW Core Course 1 course.

  Creating large and cumbersome flowcharts

  Many new LabVIEW users will write very cumbersome and large program flowcharts. For some complex applications, we inevitably need to write large program flowcharts, but large program flowcharts can also indicate that the program lacks programming architecture to a certain extent. Without a basic architecture, it is very difficult to maintain the program in the long term, and it will also be very difficult to add new features in the future. Just as only a good framework can build a well-structured house, a good programming architecture can provide a safe and reliable framework for you to build applications.

  Almost all programmers will find common frameworks for software architecture useful. In fact, many of the architectures in LabVIEW, such as producer/consumer and state machines, are very similar to those in other programming languages.

  Understanding the LabVIEW architecture can reduce development time and increase the scalability of your application. LabVIEW 2012 includes templates and sample projects that make it easier to understand the architecture. Templates explain different architectures and applications. Sample projects are larger applications based on templates that demonstrate how to use the templates to solve real-world challenges. You can add hardware to the sample project or use the sample project as a complete application if you want, and the sample projects are open and well documented so you can customize them for your specific application.

  Figure 5. The templates and sample projects in LabVIEW 2012 make it easy to understand software architecture.

  For more information about the LabVIEW architecture, refer to the self-paced online training (ni.com/self-paced-training) for the LabVIEW Core Course 2 course, Design Patterns.

  Not paying attention to documentation

  Good code documentation is a great way to help others understand your program. Unfortunately, many programmers don't start documenting until the end of the development cycle, after the feature is developed. This leaves very little time to document the code. The right thing to do is to take time to start documenting during the development process. Documentation is also very useful for programmers themselves, especially when they come back to the code after a while and can't remember why they chose certain code in the first place. Programmers often stay up late programming while drinking coffee, which often leads to "temporary amnesia". Documentation can help programmers recall.

  In general, the graphical nature of LabVIEW makes it easier to read a program than a text-based program, but effective documentation can reduce the time required to "decode" the program. The easiest way to add documentation comments to a block diagram is to use free labels. You can add comments by double-clicking the left mouse button in a blank area of ​​the block diagram and typing text. Then, use arrow markers to point to the specific code that the free label refers to. If you need to add pictures, you can copy them to the clipboard and paste them into the block diagram. Both pictures of physical systems and mathematical formulas can help to clearly illustrate the context of the code within the block diagram.

  Figure 6. Properly architected and well-documented code not only helps others understand your code, it also helps you understand your own code better.

  Documenting your code is not just for reusable libraries, it should be for every program. When one person needs to explain something to others, they will have a deeper understanding of the topic. Documentation essentially forces programmers to explain, helping them understand their code better.

  For more information about documentation, go to the self-paced online training course "Documenting Your Code" in the LabVIEW Core Course 1 course.

  LabVIEW is designed to help engineers and scientists more successfully address the world's toughest challenges. The LabVIEW community has a large membership of engineers and scientists, providing an effective platform for them to share their knowledge with others. If you would like to share a rookie mistake you have made, please post it at bit.ly/lvrookiemistakes.

Keywords:LabVIEW Reference address:5 mistakes that new LabVIEW developers must make

Previous article:OLED technology has been greatly improved, and manufacturing costs have been significantly reduced
Next article:Design of 10W non-isolated LED driver

Recommended ReadingLatest update time:2024-11-23 12:10

Design of Networked Control Model
0 Introduction With the development of network technology, the Internet is gradually integrating computer systems and communication systems around the world to form an information highway and a public data network. On this basis, the traditional industrial control field is also undergoing an unprecedented transformati
[Test Measurement]
Design of Networked Control Model
Data Acquisition and Analysis System Based on ADLINK PCI-9846 and LabVIEW
Application Areas Noise, vibration and harshness NVH (Noise, VibrATion, Harshness) is a comprehensive issue to measure the quality of automobile manufacturing. It gives the most direct and superficial feeling to automobile users. It is one of the issues that major vehicle manufacturers and parts manufacturers in the
[Test Measurement]
Data Acquisition and Analysis System Based on ADLINK PCI-9846 and LabVIEW
Design of Electronic Transformer Calibration System Based on LabVIEW
1. Introduction With the accelerated pace of digital substation and smart grid construction, electronic transformers have developed rapidly. Electronic instrument transformers include electronic current transformers and electronic voltage transformers. In order to ensure the accuracy of electronic instrument transf
[Power Management]
Design of Electronic Transformer Calibration System Based on LabVIEW
Design of Photovoltaic Power Supply Monitoring System Based on LabVIEW
0 Introduction Photovoltaic power generation technology is one of the development trends of new energy in the world. It requires more system efficiency, reliability and economy. Traditional monitoring is generally based on close-range conditions, that is, close-range monitoring. This method requires a certain amount o
[Test Measurement]
Design of Photovoltaic Power Supply Monitoring System Based on LabVIEW
Cosmetic packaging production line using LabVIEW software integrating vision and robotics
Determine facial brush position and orientation, perform quality control on it, and program a robotic system to pick up the brush and place it in an 8-slot shuttle. The Solution: Using the DENSO ImagingLab robotics library, two DENSO SCARA HSS-45552 model robots were integrated with a vision system developed usi
[Test Measurement]
Cosmetic packaging production line using LabVIEW software integrating vision and robotics
Design of Electronic Transformer Calibration System Based on LabVIEW
1 Introduction With the accelerated pace of digital substation and smart grid construction, electronic transformers have developed rapidly. Electronic instrument transformers include electronic current transformers and electronic voltage transformers. In order to ensure the accuracy of electronic instrument transfor
[Test Measurement]
Design of Electronic Transformer Calibration System Based on LabVIEW
Analysis and Reporting Features of LabVIEW 2010
Overview LabVIEW 2010 contains hundreds of signal processing and analysis functions, which can better analyze your measurement data. The report generation function of LabVIEW 2010 can summarize and organize the analysis results for better presentation. Table of contents 1. Online analysis and reportin
[Test Measurement]
Analysis and Reporting Features of LabVIEW 2010
Accelerate ARM-based Embedded System Development with LabVIEW
  Many embedded systems —from medical devices to consumer electronics—require software designed for expensive, low-power microcontrollers. ARM is a popular microcontroller architecture for hardware design when low power consumption is a primary design goal. In fact, more than 10 billion ARM processors have been used i
[Test Measurement]
Accelerate ARM-based Embedded System Development with LabVIEW
Latest Analog Electronics 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号