LabVIEW - first acquaintance

    Hello colleagues!

    In a relatively small article, I would like to talk about the LabVIEW programming language. Unfortunately, this very interesting product is not widely used, and I would like to fill in the gap to some extent.

    image

    What is LabVIEW?

    LabVIEW is one of National Instruments' core products . First of all it should be noted that the LabVIEW - an abbreviation that stands for Lab oratory V irtual I nstrumentation E ngineering Workbench. Already in the title there is a focus on laboratory research, measurement and data collection. Indeed, building SCADA - a system in LabVIEW is somewhat easier 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 differently and sometimes provides absolutely fantastic opportunities for the developer. Is LabVIEW a programming language in general? 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 "G" language. Formally, such a language does not exist, but this is the beauty of this development tool: From version to version, new constructions are introduced into the language. It is difficult to imagine that in the next C reincarnation, for example, a new structure for the for-loop will appear. And in LabVIEW this is quite possible.
    However, it should be noted that LabVIEW is included in the ranking of TIOBE programming languages , currently occupying the thirtieth place - somewhere between Prolog and Fortran.

    NI LabVIEW - creation story


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

    In Austin, the head office of the company is still located today. Today, the company employs almost four thousand people, and offices are located 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 began to work under a new contract, and my then chief handed me a pack of discs with the words "now you will work on it." I installed LabVIEW (it was the fifth version), and after playing for a while I said that there was nothing serious to do on THIS, it’s better I was "old-fashioned" on Delphi ... What he told me was that you simply did not try it. Work a week or two. After some time, I will understand that I will not be 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 rather difficult to compare graphical and textual programming languages. This is perhaps a comparison from the category of “PC” versus “MAC” or “Windows” versus “Linux” - you can argue as much as you like, but the argument is completely meaningless - each system has the right to exist and each one has 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. Although this product is sometimes closely related to National Instruments hardware, it is nonetheless not related to a specific machine. There are versions for Windows, Linux, MacOS. The source code is portable, and the programs will look the same on 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, however here Palm itself is more to blame). 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 assembler inserts - this is also possible, you just need to generate the DLL and insert the calls into the code. On the other hand, a high-level language allows you to easily perform very nontrivial operations with data, which in a normal language could take many lines (if not tens of lines) of code. However, for the sake of fairness, it should be noted that some operations of low-level languages ​​(for example, working with pointers) are not so simple to implement in LabVIEW due to its "high level". Of course, the LabVIEW language includes the basic control constructs, which have analogues in the "traditional" languages:
    • variables (local or global)
    • branching (case structure)
    • For - loops with and without completion check.
    • While - loops
    • Grouping operations.

    LabVIEW - program and language features


    In LabVIEW, software modules under development are called “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, one can quite easily draw an analogy with a function with the only difference being that in LabVIEW one function is contained in one file (you can also create tool libraries). It goes without saying that one VI can be called 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 what the classic Hello, World! Example looks like:

    image

    LabVIEW is based on a data flow paradigm. In the above example, the constant and the indicator terminal are interconnected by a line. This line is called Wire. You can call it a "wire." The wires transmit data from one element to another. This whole concept is called Data Flow. The essence of the Block Diagram is nodes (nodes), the outputs of some nodes are connected to the inputs of other nodes. A node will start execution only when all the data necessary for work arrives. There are two nodes in the diagram above. 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 transmitted by the constant (but not immediately, but as soon as the data arrives from the constant).

    Here's a slightly more complex 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's what it looks like in LabVIEW:

    image

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

    And here is what the while / for loops and 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 performed in parallel on several processors. In recent versions, you can even explicitly indicate on which of the processors this or that while-loop should be executed. Now there are add-ons for text languages, which make it easy to achieve support for multiprocessor systems, but as simple as LabVIEW, this is probably not implemented anywhere. (Well, I still slipped into a comparison with text languages). If we are already talking about multithreading, it should also be noted that the developer has at his disposal a wide selection of tools for synchronizing flows - semaphores, queues, rendezvous, etc.

    LabVIEW includes rich sets of elements for building user interfaces. Already on what interfaces "in Delphi" quickly "attacked", and in LabVIEW this process happens even faster.

    image

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

    Often you can hear the opinion that the graphic code is poorly read. Indeed, out of habit, the abundance of icons and conductors is somewhat shocking. Also, novice developers create “bed sheets” and “spaghetti” programs. 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-documenting,” since it is already based on a graphical representation.

    image

    For a long time, while programming in LabVIEW, I was completely sure 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 so. 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 development, the program is always ready to run. Also, LabVIEW code can be compiled into a full-fledged executable file that can be run on a computer without LabVIEW installed (although it does require LabVIEW Run-Time). You can also assemble the installation package-installer, third-party utilities such as InstallShield are not required.

    A further and more detailed description of the features of the package is beyond the scope of this article, but I just suggest trying it (the links are given below). As the great ones said, "... the only way to learn a new programming language is to write programs on it." Well, experienced programmers will be able to extrapolate the acquired knowledge to their own needs.

    Related Links


    In English:

    In Russian:

    Also popular now: