What is LabVIEW?
LabVIEW is termed as Laboratory Virtual Instrument Engineering Workbench. It is a visual/graphical programming language used by engineers, scientists and professionals to build the systems faster. It is developed by National Instruments to verify instruments. However, scope of LabVIEW has spread well across system design and operations as well. To use LabVIEW, you need license, although trial and student packages are there for free use.
Applications built using LabVIEW are also known as VI (Virtual Instrument). These application files have *.vi as their extension. LabVIEW provides in-built development, test and run environment for applications to be developed, tested and run. LabVIEW’s graphical data flow language is sometimes referred as “G” as well. In LabVIEW, applications are developed using icons instead of lines of codes. Here, dataflow will determine execution sequence of VIs and functions. LabVIEW acquires, analyze, stores, displays and troubleshoots the data as and when required.
Modular programming is a process of dividing a program or a module into separate and small sub-modules. Here a sub-module is a independent software code or function which can be used and integrated within various other applications with other different system components. Due to this, a module can be re-used wherever required.
Let us explore few examples to understand the need of modular programming approach.
- Consider a program having millions of lines of code. It is very difficult to manage, debug and maintain this program as there can be too many syntax or logical errors present. To avoid lengthy lines of code, modular programming is implemented.
- Modular programming breaks the large program into various small programs which in turn increases maintainability, reusability and readability. It is easy to make any changes in program or correct any errors.
- Every sub-module offers the execution of one aspect of the required functionality.
[Related Article:-Labview Structure ]
Subscribe to our youtube channel to get new updates..!
While implementing module approach in your applications, you should consider below points to have a perfect architecture for your application.
- Decide the way to partition a program into various sub-modules.
- Decide scope and limitation of each module which can help us to have transparency between modules.
- Decide the proper execution plan and communication between various modules.
Benefits of Modular Programming
Almost all the programming languages prefer modular approach while using it. Do you want to know why? Below are the advantages of using it.
- Easy to maintain and use – due to modular approach, you can build, test, run and debug each module in isolation instead of focusing millions of lines of code. This approach is also prone to less errors.
- Any module can be reusable in different application for the same functionality instead of writing the whole code again
- Access for private data can be restricted by hiding them into private functions which restricts its misuse.
- Code can be easily read and understood by programmers.
- As code is divided into different sub-modules, there will be less collision while working on modules. Different team can work together for the same application.
Modular Programming in LabVIEW
LabVIEW implements modular approach in programs by using subVI.
What is subVI?
A VI is a LabVIEW program. A VI which is used in another VI is called subVI. A subVI is nothing but the reusable code. The subVI will be inserted into the block diagram of another VI. For feeding data to subVI, icon for subVI uses terminals for their corresponding inputs and outputs. Block diagram and front panel of subVI can be accessed by double-clicking on the subVI icon.
[Related Article:- LabView Basics]
How to create subVI from existing VI?
Let us see how can create and use subVI in another VI. Below are some mandatory things to check while working with subVI.
- Declare the inputs and outputs of the SubVI.
- Connect the subVI properly: define which of the terminal will be used as input and which one will be used as output. This allows to feed data to the SubVI and receive results from the SubVI.
- Modify the subVI icon to differentiate between other icons.
Below is the sample diagram which depicts how subVI is a life savior for LabVIEW. We can simplify different sections into a subVI and use it instead of mentioning all the sections in the single VI.
We can choose sections of the block diagram which we want to convert and then click on Edit????Create subVI from Tools menu. The selected section of diagrams will be replaced with subVI icon. LabVIEW itself generates indicators and controls for subVI. It automatically configures the connector pane based on the number of control and indicator terminals you selected and wires the SubVI to the existing wires.
To differentiate subVI from other icons, it is advisable to change the icon for subVI. We can change the icon for subVI with whatever custom icon we want to use. For example, subVI icon is changed to below customized icon.
For reusing the subVI, you need to save this subVI. To add this subVI in another VI, right click on the block diagram of VI and click “Select a VI”. Browse to the folder where you have saved the subVI file and select the same. It will add subVI into your VI’s block diagram. Configure the way you want to use it.
Below are some generic steps to create subVI and use it in another VI.
- Edit the Icon
- Edit the Terminal Pattern
- Assign Terminal to Controls and Indicators
- Add Description
- Save the SubVI
- Write a New VI and call the SubVI (Function>Select a VI)
LabVIEW is an interactive, easy-to-use graphical programming language which is ideal for engineers and scientists. Whether you are a professional or a student, LabVIEW programming is valuable and must to have skill with many benefits. Applying modular programming in LabVIEW makes programming very easy and fast for beginners.