📜 ⬆️ ⬇️

LabVIEW First Meet

Hello colleagues!

In a relatively small article I would like to talk about the programming language LabVIEW. This very curious product unfortunately does not enjoy wide popularity, and I would like to fill the existing gap to some extent.

image
')
What is LabVIEW?

LabVIEW is one of the main products of the company National Instruments . First of all, it should be noted that LabVIEW is an abbreviation, which stands for Lab oratory and Civilization Engineering. Already in the title can be traced orientation on laboratory research, measurement and data collection. Indeed, building a SCADA system in LabVIEW is somewhat simpler than using “traditional” development tools. In this article I would like to show that the possible scope of LabVIEW is somewhat wider. This is a fundamentally different programming language, or if you want a whole "philosophy" of programming. A functional language that makes you think a little differently and sometimes provides absolutely fantastic opportunities for the developer. Is LabVIEW a programming language at all? This is a controversial issue - there is no standard here, such as ANSI C. In the narrow circles of developers, we say that we write in the language of “G”. Formally, such a language does not exist, but this is the beauty of this development tool: from version to version, all new constructions are introduced into the language. It is difficult to imagine that in the next reincarnation of C, for example, a new structure for a for-cycle will appear. And in LabVIEW this is quite possible.
However, it should be noted that LabVIEW is included in the rating of TIOBE programming languages, currently occupying the thirtieth place - somewhere between Prolog and Fortran.

NI LabVIEW - the history of creation


National Instruments was created in 1976 by three founders - Jeff Kodosky, James Truchard and Bill Nowlin in Austin, Texas. The main specialization of the company was instrumentation for measurement and automation of production.
The first version of LabVIEW was released ten years after the creation of the company - in 1986 (it was the Apple Mac version). NI engineers decided to challenge the "traditional" programming languages ​​and created a completely graphical development environment. The main ideologue of the graphic approach was Jeff. Year after year, new versions were released. The first cross-platform version (including Windows) was the third version, released in 1993. Actual at the moment is version 8.6, released last year.

In Austin, and to this day is the head office of the company. Today, the company employs almost four thousand people, and there are offices in almost forty countries (there is also an office in Russia)

My acquaintance with LabVIEW


My acquaintance with LabVIEW happened almost ten years ago. I started working on a new contract, and my then-chief handed me a pack of disks with the words "now you will work on this." I installed LabVIEW (it was the fifth version), and after playing for a while, I said that I couldn’t do anything serious about IT, I’d rather “do it the old way” on Delphi ... To which he told me you just didn’t try it. Work a week or two. After a while I’ll understand that I’m not able to write on anything other than LabVIEW. I just fell in love with this language, although it was not “love at first sight”.

Generally speaking, it is quite difficult to compare graphic and text programming languages. This is, perhaps, a comparison from the category of “PC” against “MAC” or “Windows” against “Linux” - one can argue as much as necessary, but the dispute is absolutely meaningless - each system has the right to exist and each will have both supporters and opponents, In addition, each product has its own niche. LabVIEW is just a tool, albeit a very flexible one.

So what is LabVIEW?


LabVIEW is a cross-platform, graphical application development environment. LabVIEW is basically a universal programming language. And although this product is sometimes closely related to the National Instruments hardware, it is nonetheless not related to a specific machine. There are versions for Windows, Linux, MacOS. Source codes are portable, and programs will look the same in all systems. The code generated by LabVIEW can also be executed on Windows Mobile or PalmOS (in fairness it should be noted that PalmOS support has been discontinued, although Palm itself is more to blame for this). This language can be successfully used to create large systems for processing text, images and working with databases.

LabVIEW is a very high-level language. However, nothing prevents the inclusion of "low-level" modules in LabVIEW programs. Even if you want to use assembly inserts - this is also possible, you just need to generate a DLL and insert calls into the code. On the other hand, a high-level language allows you to easily perform highly non-trivial operations with data that many lines (if not tens of lines) of code could go into in ordinary language. However, for the sake of justice, it should be noted that some operations of low-level languages ​​(for example, work with pointers) are not so easy to implement in LabVIEW due to its “high level”. Of course, the LabVIEW language includes basic control structures that have analogues in the “traditional” languages:

LabVIEW - program and language features


LabVIEW develops software modules called “Virtual Instruments” (Virtual Instruments) or simply VI. They are saved in files with the * .vi extension. VIs are the building blocks of the LabVIEW program. Any LabVIEW program contains at least one VI. In terms of the C language, you can quite boldly draw an analogy with a function with the only difference that in LabVIEW one function is contained in one file (you can also create tool libraries). Needless to say, one VI can be invoked from another VI. In principle, each VI consists of two parts - the Block Diagram and the Front Panel. The block diagram is the program code (more precisely, the visual graphic representation of the code), and the front panel is the interface. Here’s a classic example of Hello, World !:

image

LabVIEW is based on a data flow paradigm. In the above example, the constant and indicator terminal are interconnected by a line. This line is called Wire. You can call it "wire." Data from one element to another is transmitted by wire. This whole concept is called Data Flow. The essence of the Block Diagrams are nodes (nodes), the outputs of some nodes are connected to the inputs of other nodes. The node will start execution only when all the necessary data for the job has arrived. The diagram above has two nodes. One of them is a constant. This node is self-sufficient — it starts execution immediately. The second node is an indicator. It will display the data that the constant transmits (but not immediately, but as soon as the data comes from the constant).

Here is a slightly more complicated example: the addition and multiplication of two numbers. In traditional languages ​​we will write something like

int a, b, sum, mul;
//...
sum = a + b;
mul = a * b;


Here is how it looks in LabVIEW:

image

Note that addition and multiplication are automatically performed in parallel. On a dual-processor machine, both processors will be automatically involved.

And this is how the while / for cycles and the if / then / else structure look like:

image

As already mentioned, all elements will be executed in parallel. You do not need to think about how to parallelize a task into several threads that can be executed in parallel on several processors. In recent versions, you can even explicitly indicate on which of the processors a particular while loop should run. Now there are add-ons for textual languages ​​that make it possible to easily achieve support for multiprocessor systems, but as simple as that at LabVIEW, this is not implemented anywhere. (well, I still slipped into comparison with textual languages). If we are already talking about multithreading, then it should also be noted that the developer has a wide choice of tools for synchronizing threads - semaphores, queues, rendezvous, etc.

LabVIEW includes rich sets of elements for building user interfaces. Already, interfaces in Delphi were quickly attacked, and in LabVIEW this process is even faster.

image

The standard delivery of LabVIEW also includes blocks for working with ini files, the registry, functions for working with binary and test files, mathematical functions, powerful tools for plotting (and where else in the laboratory), and in addition to mentioned call capabilities DLL, LabVIEW allows you to work with ActiveX components and .net. Starting with the eighth version, class support has been added to LabVIEW — the language has become object-oriented. The implemented support cannot be called complete, but the main features of object-oriented languages ​​are inheritance and polymorphism. Also, the language functionality can be extended with additional modules, for example, NI Vision Toolkit - for image processing and machine vision and others. And with the help of the Applcation Builder module, you can generate an executable exe file. Using the Internet Toolkit, you can work with ftp servers, with Database Connectivity Toolkit - with databases, etc.

You can often hear the opinion that the graphic code is hard to read. Indeed, the habit of the abundance of icons and guides is somewhat shocking. Also, novice developers create programs “sheets” and programs “spaghetti”. However, an experienced LabVIEW developer will never create diagrams that are larger than the screen size, even if the program consists of hundreds of modules. A well-designed program is in fact “self-documented”, since the basis is already a graphical representation.

image

For quite a long time, programming in LabVIEW, I was fully confident that LabVIEW is an interpreter and block diagrams are constantly interpreted by the kernel. After talking with NI engineers, it turned out that this was not the case. LabVIEW is a compiler (the quality of code generation, however leaves much to be desired). But compilation takes place “on the fly” - at any time during the development of the program, the program is always ready to be launched. Also, the LabVIEW code can be compiled into a full-fledged executable file that can be run on a computer without LabVIEW installed (although it requires the LabVIEW Run-Time). You can also build an installation installer package, third-party utilities such as InstallShield are not required.

A further and more detailed description of the package’s capabilities is beyond the scope of this article, I just suggest trying it out (links are given below). As the greats said, "... the only way to master a new programming language is to write programs on it." Well, experienced programmers will be able to extrapolate their knowledge for their own needs.

Related Links


In English:

In Russian:

Source: https://habr.com/ru/post/57859/


All Articles