CPU automated control systems and industrial safety. Getting to know LabView Lab view

Hello colleagues!

In a relatively short article I would like to talk about the LabVIEW programming language. This very interesting product, unfortunately, is not widely popular, and I would like to fill the gap to some extent.

What is LabVIEW?

LabVIEW is one of the main products of National Instruments. First of all, it should be noted that LabVIEW is an acronym that stands for Lab oratory V virtual I instrumentation E ngineering W orkbench. Already in the name one can see the focus on laboratory research, measurements and data collection. Indeed, building a SCADA 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 broader. This is a fundamentally different programming language, or, if you want, a whole “philosophy” of programming. A functional language that forces you to 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, like, for example, ANSI C. In narrow developer circles, 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, more and more new constructs are introduced into the language. It’s hard to imagine that the next reincarnation of C will feature, for example, a new structure for the for loop. And in LabVIEW this is quite possible.
However, it should be noted that LabVIEW is included in the TIOBE programming language rating, currently occupying thirtieth place - somewhere between Prolog and Fortran.

NI LabVIEW - history of creation

National Instruments was founded in 1976 by three founders, Jeff Kodosky, James Truchard and Bill Nowlin, in Austin, Texas. The main specialization of the company was tools for measurements and production automation.
The first version of LabVIEW was released ten years after the company was founded - in 1986 (it was a version for Apple Mac). NI engineers decided to challenge “traditional” programming languages ​​and created a completely graphical development environment. Jeff became the main ideologist of the graphic approach. New versions were released year after year. The first cross-platform version (including Windows) was version 3, released in 1993. The current version is 8.6, released last year.

The company's head office is still located in Austin today. Today the company employs almost four thousand people, and has offices in almost forty countries (there is also an office in Russia)

My introduction to LabVIEW

My acquaintance with LabVIEW happened almost ten years ago. I started working under a new contract, and my then boss handed me a stack of CDs 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 nothing serious could be done with THIS, I’d rather do it “the old fashioned way” in Delphi... To which he told me - you just haven’t tried it. Work for a week or two. After a while I will understand that I will no longer be able to write on anything other than LabVIEW. I simply fell in love with this language, although it was not “love at first sight.”

Generally speaking, it is quite difficult to compare graphical and textual programming languages. This is, perhaps, a comparison like “PC” versus “MAC” or “Windows” versus “Linux” - you can argue as much as you like, but the argument is absolutely meaningless - every system has the right to exist and each 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 cross-platform graphical environment application development. LabVIEW is, in principle, a universal programming language. Although this product is sometimes closely related to National Instruments hardware, it is nevertheless not related to a specific machine. There are versions for Windows, Linux, MacOS. Source texts portable, and programs will look the same on all systems. Code generated by LabVIEW can also be executed on Windows Mobile or PalmOS (in fairness, it should be noted that support for PalmOS has been discontinued, however, Palm itself is more to blame here). This language can be successfully used to create large systems, for processing texts, images and working with databases.

LabVIEW is a very high-level language. However, there is nothing stopping you from including “low-level” modules in LabVIEW programs. Even if you want to use assembler 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 very non-trivial operations with data, which in a regular language could take many lines (if not tens of lines) of code. However, to be fair, it should be noted that some operations of low-level languages ​​(for example, working with pointers) are not so easy to implement in LabVIEW due to its “high-level” nature. Of course, the LabVIEW language includes basic control constructs that have analogues in “traditional” languages:

  • variables (local or global)
  • branching (case structure)
  • For – loops with and without completion checking.
  • While - loops
  • Grouping of operations.

LabVIEW - program and language capabilities

In LabVIEW, the software modules being developed are called “Virtual Instruments” or simply VI. They are saved in files with the *.vi extension. VIs are the building blocks that make up the LabVIEW program. Every LabVIEW program contains at least one VI. In terms of the C language, you can fairly safely draw an analogy with a function, the only difference being that in LabVIEW one function is contained in one file (you can also create libraries of tools). It goes without saying that one VI can be called from another VI. In principle, each VI consists of two parts - a Block Diagram and a Front Panel. A block diagram is a program code (or rather a visual graphical representation code), and the Front Panel is the interface. Here's what a classic Hello, World! example looks like:

LabVIEW is based on the data flow paradigm. In the above example, the constant and the indicator terminal are connected to each other by a line. This line is called Wire. You can call it a “wire”. Wires transmit data from one element to another. This whole concept is called Data Flow. The essence of a Block Diagram is nodes, the outputs of some nodes are connected to the inputs of other nodes. The node will begin execution only when all the data necessary for operation has arrived. There are two nodes in the diagram above. One of them is a constant. This node is self-contained - it starts executing 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 arrives from the constant).

Here's a slightly more complex example: adding and multiplying two numbers. In traditional languages ​​we would write something like

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

Here's what it looks like in LabVIEW:

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

And this is what while / looks like for loops and if/then/else structure:

As already mentioned, all elements will be executed in parallel. You don't need to think about how to parallelize a task into multiple threads that can be executed in parallel on multiple processors. IN latest versions You can even explicitly specify on which processor a particular while loop should be executed. Now there are add-ons for text languages ​​that allow you to easily achieve support for multiprocessor systems, but this is probably not implemented anywhere as easily as in LabVIEW. (well, I still slipped into comparison with text languages). If we are already talking about multithreading, then we should also note that the developer has a wide selection of tools for synchronizing threads at his disposal - semaphores, queues, rendezvous, etc.

LabVIEW includes rich sets of elements for building user interfaces. Interfaces were quickly created in Delphi, but in LabVIEW this process happens even faster.

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 would you be without this in the laboratory), and in addition to The mentioned ability to call DLLs, LabVIEW allows you to work with ActiveX components and .net. Starting with the eighth version, support for classes was added to LabVIEW - the language became 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 NI Vision Toolkit - for image processing and computer vision and others. And using the Application Builder module you can generate an executable exe file. Using the Internet Toolkit you can work with ftp servers, using Database Connectivity Toolkit - with databases, etc.

You can often hear the opinion that graphical code is difficult to read. Indeed, out of habit, the abundance of icons and conductors is somewhat shocking. Novice developers also create “sheet” programs and “spaghetti” programs. However, an experienced LabVIEW developer will never create diagrams larger than the screen size, even if the program consists of hundreds of modules. A well-designed program is effectively “self-documenting” because it is already based on a graphical representation.

Enough for a long time When 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 occurs “on the fly” - at any time during development, the program is always ready to run. LabVIEW code can also be compiled into a full-fledged executable file that can be run on a computer without LabVIEW installed (although it requires LabVIEW Run-Time). You can also build an installation package, third party utilities the InstallShield type is not required.

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

Hello colleagues!

In a relatively short article I would like to talk about the LabVIEW programming language. This very interesting product, unfortunately, is not widely popular, and I would like to fill the gap to some extent.

What is LabVIEW?

LabVIEW is one of the main products of National Instruments. First of all, it should be noted that LabVIEW is an acronym that stands for Lab oratory V virtual I instrumentation E ngineering W orkbench. Already in the name one can see the focus on laboratory research, measurements and data collection. Indeed, building a SCADA 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 broader. This is a fundamentally different programming language, or, if you want, a whole “philosophy” of programming. A functional language that forces you to 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, like, for example, ANSI C. In narrow developer circles, 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, more and more new constructs are introduced into the language. It’s hard to imagine that the next reincarnation of C will feature, for example, a new structure for the for loop. And in LabVIEW this is quite possible.
However, it should be noted that LabVIEW is included in the TIOBE programming language rating, currently occupying thirtieth place - somewhere between Prolog and Fortran.

NI LabVIEW - history of creation

National Instruments was founded in 1976 by three founders, Jeff Kodosky, James Truchard and Bill Nowlin, in Austin, Texas. The company's main specialization was measurement tools and production automation.
The first version of LabVIEW was released ten years after the company was founded - in 1986 (it was a version for Apple Mac). NI engineers decided to challenge “traditional” programming languages ​​and created a completely graphical development environment. Jeff became the main ideologist of the graphic approach. New versions were released year after year. The first cross-platform version (including Windows) was version 3, released in 1993. The current version is 8.6, released last year.

The company's head office is still located in Austin today. Today the company employs almost four thousand people, and has offices in almost forty countries (there is also an office in Russia)

My introduction to LabVIEW

My acquaintance with LabVIEW happened almost ten years ago. I started working under a new contract, and my then boss handed me a stack of CDs 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 nothing serious could be done with THIS, I’d rather do it “the old fashioned way” in Delphi... To which he told me - you just haven’t tried it. Work for a week or two. After a while I will understand that I will no longer be able to write on anything other than LabVIEW. I simply fell in love with this language, although it was not “love at first sight.”

Generally speaking, it is quite difficult to compare graphical and textual programming languages. This is, perhaps, a comparison like “PC” versus “MAC” or “Windows” versus “Linux” - you can argue as much as you like, but the argument is absolutely meaningless - every system has the right to exist and each 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, in principle, a universal programming language. Although this product is sometimes closely related to National Instruments hardware, it is nevertheless 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 support for PalmOS has been discontinued, however, Palm itself is more to blame here). This language can be successfully used to create large systems for processing texts, images and working with databases.

LabVIEW is a very high-level language. However, there is nothing stopping you from including “low-level” modules in LabVIEW programs. Even if you want to use assembler 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 very non-trivial operations with data, which in a regular language could take many lines (if not tens of lines) of code. However, to be fair, it should be noted that some operations of low-level languages ​​(for example, working with pointers) are not so easy to implement in LabVIEW due to its “high-level” nature. Of course, the LabVIEW language includes basic control constructs that have analogues in “traditional” languages:

  • variables (local or global)
  • branching (case structure)
  • For – loops with and without completion checking.
  • While - loops
  • Grouping of operations.

LabVIEW - program and language capabilities

In LabVIEW, the software modules being developed are called “Virtual Instruments” or simply VI. They are saved in files with the *.vi extension. VIs are the building blocks that make up the LabVIEW program. Every LabVIEW program contains at least one VI. In terms of the C language, you can fairly safely draw an analogy with a function, the only difference being that in LabVIEW one function is contained in one file (you can also create libraries of tools). It goes without saying that one VI can be called from another VI. In principle, each VI consists of two parts - a Block Diagram and a Front Panel. The block diagram is the program code (more precisely, a visual graphical representation of the code), and the Front Panel is the interface. Here's what a classic Hello, World! example looks like:

LabVIEW is based on the data flow paradigm. In the above example, the constant and the indicator terminal are connected to each other by a line. This line is called Wire. You can call it a “wire”. Wires transmit data from one element to another. This whole concept is called Data Flow. The essence of a Block Diagram is nodes, the outputs of some nodes are connected to the inputs of other nodes. The node will begin execution only when all the data necessary for operation has arrived. There are two nodes in the diagram above. One of them is a constant. This node is self-contained - it starts executing 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 arrives from the constant).

Here's a slightly more complex example: adding and multiplying two numbers. In traditional languages ​​we would write something like

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

Here's what it looks like in LabVIEW:

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

And here’s what the while / for loops and if / then / else structure look like:

As already mentioned, all elements will be executed in parallel. You don't need to think about how to parallelize a task into multiple threads that can be executed in parallel on multiple processors. In the latest versions, you can even explicitly specify on which processor a particular while loop should be executed. Now there are add-ons for text languages ​​that allow you to easily achieve support for multiprocessor systems, but this is probably not implemented anywhere as easily as in LabVIEW. (well, I still slipped into comparison with text languages). If we are already talking about multithreading, then we should also note that the developer has a wide selection of tools for synchronizing threads at his disposal - semaphores, queues, rendezvous, etc.

LabVIEW includes rich sets of elements for building user interfaces. Interfaces were quickly created in Delphi, but in LabVIEW this process happens even faster.

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 would you be without this in the laboratory), and in addition to The mentioned ability to call DLLs, LabVIEW allows you to work with ActiveX components and .net. Starting with the eighth version, support for classes was added to LabVIEW - the language became 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 NI Vision Toolkit - for image processing and computer vision and others. And using the Application Builder module you can generate an executable exe file. Using the Internet Toolkit you can work with ftp servers, using the Database Connectivity Toolkit - with databases, etc.

You can often hear the opinion that graphical code is difficult to read. Indeed, out of habit, the abundance of icons and conductors is somewhat shocking. Novice developers also create “sheet” programs and “spaghetti” programs. However, an experienced LabVIEW developer will never create diagrams larger than the screen size, even if the program consists of hundreds of modules. A well-designed program is effectively “self-documenting” because it is already based on a graphical representation.

For quite a long time, programming in LabVIEW, I was completely confident that LabVIEW was an interpreter and block diagrams were 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 occurs “on the fly” - at any time during development, the program is always ready to run. LabVIEW code can also be compiled into a full-fledged executable file that can be run on a computer without LabVIEW installed (although it requires LabVIEW Run-Time). You can also assemble an installer installation 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, but I simply suggest trying it (links are given below). As the greats said, “... the only way to master a new programming language is to write programs in it.” Well, experienced programmers will be able to extrapolate the knowledge gained to their own needs.

Almost all developers of microcontroller devices, whether amateurs or professionals, sooner or later need to connect a microcontroller device to its “big brother,” namely a PC. That’s when the question arises: what software should I use to exchange with the microcontroller, analyze and process the data received from it? Often, to exchange the MK with a computer, they use the RS232 interface and protocol - the good old COM port in one implementation or another.

On the computer side, various terminal programs are used, of which there are hundreds. But these programs only provide reception and transmission of information. It is difficult to somehow process and visualize it in a visual form.

Some write such software independently in some programming language (Delphi, C++), providing the necessary functionality. But this task is not easy; you need to know, in addition to the language itself, the device operating system, methods of working with communication ports, many other technical subtleties that distract from the main thing - the implementation of the program algorithm. In general, being a Windows/Unix programmer at the same time.

The concept of virtual instruments (vi) differs sharply from these approaches. This article will discuss the LabView software product from Nationals Instruments. I'm just starting to master this wonderful product, so I may make inaccuracies and mistakes. The experts will correct you :-)) What exactly is LabView?

LabView is a development environment and platform for running programs written in graphic language"G" programming from National Instruments.

Speaking in simple language, LabView - This is an environment for creating applications for the tasks of collecting, processing, visualizing information from various instruments, laboratory installations, etc. And also for management technological processes and devices. However, using LabView you can create quite ordinary application software. I have no intention of describing this product and working with it in detail. There are thousands of pages of excellent documentation and hundreds of books written on LabView. The Internet is full of resources dedicated to LabView, where you can get answers to all your questions.

The purpose of the article is to show how simple and convenient it is, compared to traditional programming, to create applications for a PC and what power LabView carries. (In fact, it’s debatable, because in traditional programming, it’s not more difficult to do it in Delphi. And in terms of efficiency it’s hardly worse, if not better. But for this you need to study Delphi for much longer. Everything is quick and clear almost immediately . control of watering and heating for a hemp greenhouse. With all sorts of PID controllers. I brought it to the potentiometers and sensors of the laboratory stand that was in our technician and started this hellish unit. And everything worked immediately, without debugging, all the equipment of the hadron collider works on LabView. and also a lot of scientific equipment approx. DI HALT) After all, PC programming is foreign to most electronics engineers, right? This is what we will try to fix. In order not to study spherical vacuum horses, we will set for ourselves and implement a simple task. The task is really simple, but based on it you can understand the basic principles of programming in LabView. We will use LabView version 2010. For other versions the differences will be minimal.

Task
We have a fee with AVR microcontroller, connected to a computer via RS232. The controller is loaded with firmware, according to which the controller measures the voltage value at one of the ADC inputs and transmits the ADC code (from 0 to 1023) to the computer via a serial channel. It is necessary to write a PC program that will receive a data stream from the ADC, display the ADC code, convert the ADC code into a voltage value in volts, display the voltage value in volts, and plot the voltage change over time.

Well, probably enough of the lyrics, let’s get started!

So what do we need for work:

  • Actually LabView itself. You can download the trial version from the NI website: http://www.ni.com/trylabview/. The pirated version can also be googled without any problems. By the way, on rutracker.org, in addition to a ton of pirated ones, there is also a version for Linux for which registration does not seem to be required at all. NI decided to meet the open source halfway?
  • It is also necessary to download the NI VISA component. Without this program, LabView will not “see” the COM port on the computer. VISA contains functions for working with communication ports and much more. You can download it from joule.ni.com. Install LabView and VISA. The installation of this software is standard and does not have any special features.

First of all, we need to make sure that VISA has found a COM port in the system and is working with it correctly. You can check this like this: launch the Measurement & Automation program. It comes with LabView. If it is not installed, you can install it manually. It is on the disk (the image with LabView).

On the left side of the window we see the equipment detected in the system. Among other things, we find our COM port. On the right there is a button Open Visa test panel. Using it you can test the selected device. In the case of a COM port, you can send or receive a default or arbitrary sequence of characters. If everything is in order with the port, we can proceed directly to creating our program.

Launch LabView. In the Getting Started window, select the Blank Vi item to create a new virtual device.

We get something like this:

So what do we have? The work area consists of two large panels, Front Panel and Block Diagram. On the front panel we will create the interface of our program using controls from the Controls panel. These elements are the familiar variable resistor knobs, LEDs, buttons, pointer instruments, oscilloscope screen, etc. They serve to enter information into the program and display execution results. The Block Diagram panel contains the program code itself. Here we need to step back a little and explain the principle of programming in LabView. A small example. It is customary to start working on a program by designing the interface, and then implementing the algorithm on a block diagram. Let's make a simple program for multiplying two numbers. To do this, we will place three controls on the front panel by dragging them, say the Knob and Numeric Indicator elements to display the result.

Let's create the interface as you wish, for example like this:

Ok, now we need to implement the actual multiplication. We go to the Block diagram panel and see that a corresponding icon has been created for each of our controls. It is best to immediately switch the display mode to terminals. The diagram won't be so cluttered. In addition, the terminals display the type of data that a particular control operates on. To do this, right-click on the icon and uncheck View as icon. At the top of the screen there is a control in the form of a terminal, at the bottom and on the right in the form of an icon. In order to configure the default view of the block diagram as terminals, you need to select the Tools->Options menu item, select Block diagram on the left and uncheck Place front panel terminals as icons. It is very useful to display contextual help. You can display it using the combination Ctrl+H. This window displays information about the object on which the cursor is currently placed. Mega convenient thing.

Now we need to add a multiplication function to the block diagram. Right-click on the block diagram and select the Multiply function from the Numeric palette. Let's put it on the diagram. It is worth noting that LabView has a simply huge set of functions. This includes various mathematics, statistics, signal analysis, PID regulation, video, sound and image processing. You can't list everything.

The most important concept in LabView programming is the concept of DataFlows. The gist is this: Unlike imperative programming languages, where statements are executed in order, in LabView functions only work if all function inputs have information (each function has input and output values). Only then does the function implement its algorithm, and the result is sent to the output, which can be used by another function. Thus, within one virtual instrument, functions can operate independently of each other.

Now, in order to revive our example, we need to follow this concept and feed the function input the numerical values ​​that we set with the controls, and get the result from the output and display it.

To connect elements in a block diagram, use the Connect Wire tool from the Tools panel. Select it and draw our connections.

That's all, you can run this stupid program for cyclic execution and turn the knobs, observing the result of the multiplication.

As you can see, there seems to be nothing complicated. But at the same time, LabView allows you to solve problems of any complexity! Damn, the TANK control system is made on it! So that.

Well, now let's do more interesting things, namely, let's make our simplest voltmeter, which I talked about at the very beginning.

So what do we need to do. First you need to configure and initialize serial port. Start an endless loop. In the loop we use the read function from the port and receive the information. We convert the information for display on the graph, recalculate the ADC code into a voltage value in volts. When exiting the loop, close the port.
So in the interface of our program there will be no control elements except the Stop button, but only a display of the result. We will do this: first we will create a block diagram, and then we will add the missing elements to the front panel. Although you need to do the opposite! But in this case it is more convenient.

On the block diagram panel we place the While Loop element from the Structures palette, this is our endless loop. We draw a loop frame around an area large enough to fit inside the algorithm. There is a red dot in the lower right corner, right-click on it and select Create Control. We will immediately have a Stop button on the front panel. When you click on it, our program will end.

Now outside the loop we must place the functions for initializing and closing the port. On the left is initialization, on the right is closing. Again, right-click and select the Configure Port, Read and Close functions. These functions are located in the Instrument I/O –> Serial palette. We place the reading function inside the loop. We connect the outputs and inputs of the functions using a coil of wires. For the Read function, we must specify the number of bytes it will receive. Right-click on the middle input of the Read function and select Create->Constant, enter a value, for example 200. At this stage it should look like the screenshot.

You need to create controls for the port initialization function. Two are enough for us - port speed and port name. Just like we created a constant for the reading function, we create controls. PCM at the required inputs of the initialization function and item

Create->Control.

We are interested in two inputs: Visa resource name And Baud Rate(default 9600). Now let's go to the front panel and add the necessary components, namely the graph drawing screen and labels for displaying the ADC code and voltage in volts.
Accordingly, these are Waweform Chart elements from the Graph palette and two Numeric Indicator elements from the Numeric palette.

Let's return to the block diagram and move the elements that appear inside the loop. We are nearing completion! The only thing is that we still need to convert the string of characters coming from the output of the Read function to a format that our indicators can digest. And also implement the simplest mathematics to convert the ADC code into volts. Below are screenshots of the front panel and block diagrams at this stage:

To convert a string, we will use the Scan from string function from the String palette. We place it inside the loop. Now for the math. In order to convert the ADC code into a voltage value in volts, you need to multiply the code by the value of the reference voltage (in my case it is five volts) and divide the resulting value by 1023 (since the ADC has a 10-bit width). We will place the necessary multiplication and division functions, as well as constants (5 and 1023) in a loop. I won’t take screenshots of each connection, because there are already too many pictures. I will give the final screenshot of all connections. Everything is extremely simple there.

I think everything is clear, if you have any questions, ask in the comments. Let's figure it out together :-))) In the meantime, the program is ready.

Let's go to our interface and set up the chart a little. Select the lower value along the Y axis and set it to 0. Select the upper value and set it to 5. Thus, our scale along the Y axis is in the range of 0-5 volts. Well, we select the COM port, enter the baud rate, launch our program using the arrow button and furiously twist the resistor on the board, while freely observing the result of our work on the screen. Click on the Stop button to stop the program.

As you can see, everything is quite simple. This example This is only a tiny part of all LabView's capabilities. If this article helps anyone, I will be glad. Just don’t hit me too hard in the comments, I’m not a pro. Another little trick. If the diagram looks like Cthulhu, you can try using the CleanUp Diagram button. It will bring the diagram into a more or less divine form, but it must be used carefully. Here is the result of her work

You can also combine the pieces into functional blocks so that they do not clutter the diagram.

Almost all developers of microcontroller devices, whether amateur or professional, sooner or later need to connect a microcontroller device to its “big brother,” namely a PC. That’s when the question arises: what software should I use to exchange with the microcontroller, analyze and process the data received from it? Often, to exchange the MK with a computer, they use the RS232 interface and protocol - the good old COM port in one implementation or another.

On the computer side, various terminal programs are used, of which there are hundreds. But these programs only provide reception and transmission of information. It is difficult to somehow process and visualize it in a visual form.

Some write such software independently in some programming language (Delphi, C++), providing the necessary functionality. But this task is not easy; you need to know, in addition to the language itself, the structure of the operating system, how to work with communication ports, and many other technical subtleties that distract from the main thing - the implementation of the program algorithm. In general, being a Windows/Unix programmer at the same time.

The concept of virtual instruments (vi) differs sharply from these approaches. This article will discuss the LabView software product from Nationals Instruments. I'm just starting to master this wonderful product, so I may make inaccuracies and mistakes. The experts will correct you :-)) What exactly is LabView?

LabView is a development environment and platform for running programs written in the National Instruments graphical programming language G.

In simple terms, LabView is an application creation environment for the tasks of collecting, processing, visualizing information from various instruments, laboratory installations, etc. And also for controlling technological processes and devices. However, using LabView you can create quite ordinary application software. I have no intention of describing this product and working with it in detail. There are thousands of pages of excellent documentation and hundreds of books written on LabView. The Internet is full of resources dedicated to LabView, where you can get answers to all your questions.

The purpose of the article is to show how simple and convenient it is, compared to traditional programming, to create applications for a PC and what power LabView carries. (In fact, it’s debatable, because in traditional programming, it’s not more difficult to do it in Delphi. And in terms of efficiency it’s hardly worse, if not better. But for this you need to study Delphi for much longer. Everything is quick and clear almost immediately . control of watering and heating for a hemp greenhouse. With all sorts of PID controllers. I brought it to the potentiometers and sensors of the laboratory stand that was in our technician and started this hellish unit. And everything worked immediately, without debugging, all the equipment of the hadron collider works on LabView. and also a lot of scientific equipment approx. DI HALT) After all, PC programming is foreign to most electronics engineers, right? This is what we will try to fix. In order not to study spherical vacuum horses, we will set for ourselves and implement a simple task. The task is really simple, but based on it you can understand the basic principles of programming in LabView. We will use LabView version 2010. For other versions the differences will be minimal.

Task
We have a board with an AVR microcontroller connected to a computer via RS232. The controller is loaded with firmware, according to which the controller measures the voltage value at one of the ADC inputs and transmits the ADC code (from 0 to 1023) to the computer via a serial channel. It is necessary to write a PC program that will receive a data stream from the ADC, display the ADC code, convert the ADC code into a voltage value in volts, display the voltage value in volts, and plot the voltage change over time.

Well, probably enough of the lyrics, let’s get started!

So what do we need for work:

  • Actually LabView itself. You can download the trial version from the NI website: http://www.ni.com/trylabview/. The pirated version can also be googled without any problems. By the way, on rutracker.org, in addition to a ton of pirated ones, there is also a version for Linux for which registration does not seem to be required at all. NI decided to meet the open source halfway?
  • It is also necessary to download the NI VISA component. Without this program, LabView will not “see” the COM port on the computer. VISA contains functions for working with communication ports and much more. You can download it from joule.ni.com. Install LabView and VISA. The installation of this software is standard and does not have any special features.

First of all, we need to make sure that VISA has found a COM port in the system and is working with it correctly. You can check this like this: launch the Measurement & Automation program. It comes with LabView. If it is not installed, you can install it manually. It is on the disk (the image with LabView).

We get something like this:


So what do we have? The work area consists of two large panels, Front Panel and Block Diagram. On the front panel we will create the interface of our program using controls from the Controls panel. These elements are the familiar variable resistor knobs, LEDs, buttons, pointer instruments, oscilloscope screen, etc. They serve to enter information into the program and display execution results. The Block Diagram panel contains the program code itself. Here we need to step back a little and explain the principle of programming in LabView. A small example. It is customary to start working on a program by designing the interface, and then implementing the algorithm on a block diagram. Let's make a simple program for multiplying two numbers. To do this, we will place three controls on the front panel by dragging them, say the Knob and Numeric Indicator elements to display the result.

Ok, now we need to implement the actual multiplication. We go to the Block diagram panel and see that a corresponding icon has been created for each of our controls. It is best to immediately switch the display mode to terminals. The diagram won't be so cluttered. In addition, the terminals display the type of data that a particular control operates on. To do this, right-click on the icon and uncheck View as icon. At the top of the screen there is a control in the form of a terminal, at the bottom and on the right in the form of an icon. In order to configure the default view of the block diagram as terminals, you need to select the Tools->Options menu item, select Block diagram on the left and uncheck Place front panel terminals as icons. It is very useful to display contextual help. You can display it using the combination Ctrl+H. This window displays information about the object on which the cursor is currently placed. Mega convenient thing.

The most important concept in LabView programming is the concept of DataFlows. The gist is this: Unlike imperative programming languages, where statements are executed in order, in LabView functions only work if all function inputs have information (each function has input and output values). Only then does the function implement its algorithm, and the result is sent to the output, which can be used by another function. Thus, within one virtual instrument, functions can operate independently of each other.

Now, in order to revive our example, we need to follow this concept and feed the function input the numerical values ​​that we set with the controls, and get the result from the output and display it.

To connect elements in a block diagram, use the Connect Wire tool from the Tools panel. Select it and draw our connections.

As you can see, there seems to be nothing complicated. But at the same time, LabView allows you to solve problems of any complexity! Damn, the TANK control system is made on it! So that.

Well, now let's do more interesting things, namely, let's make our simplest voltmeter, which I talked about at the very beginning.

So what do we need to do. First you need to configure and initialize the serial port. Start an endless loop. In the loop we use the read function from the port and receive the information. We convert the information for display on the graph, recalculate the ADC code into a voltage value in volts. When exiting the loop, close the port.
So in the interface of our program there will be no control elements except the Stop button, but only a display of the result. We will do this: first we will create a block diagram, and then we will add the missing elements to the front panel. Although you need to do the opposite! But in this case it’s more convenient.

On the block diagram panel we place the While Loop element from the Structures palette, this is our endless loop. We draw a loop frame around an area large enough to fit inside the algorithm. There is a red dot in the lower right corner, right-click on it and select Create Control. We will immediately have a Stop button on the front panel. When you click on it, our program will end.

You need to create controls for the port initialization function. Two are enough for us - port speed and port name. Just like we created a constant for the reading function, we create controls. PCM at the required inputs of the initialization function and item

Create->Control.

Create->Control.

We are interested in two inputs: Visa resource name And Baud Rate(default 9600). Now let's go to the front panel and add the necessary components, namely the graph drawing screen and labels for displaying the ADC code and voltage in volts.
Accordingly, these are Waweform Chart elements from the Graph palette and two Numeric Indicator elements from the Numeric palette.

Let's return to the block diagram and move the elements that appear inside the loop. We are nearing completion! The only thing is that we still need to convert the string of characters coming from the output of the Read function to a format that our indicators can digest. And also implement the simplest mathematics to convert the ADC code into volts. Below are screenshots of the front panel and block diagrams at this stage:



To convert a string, we will use the Scan from string function from the String palette. We place it inside the loop. Now for the math. In order to convert the ADC code into a voltage value in volts, you need to multiply the code by the value of the reference voltage (in my case it is five volts) and divide the resulting value by 1023 (since the ADC has a 10-bit width). We will place the necessary multiplication and division functions, as well as constants (5 and 1023) in a loop. I won’t take screenshots of each connection, because there are already too many pictures. I will give the final screenshot of all connections. Everything is extremely simple there.


I think everything is clear, if you have any questions, ask in the comments. Let's figure it out together :-))) In the meantime, the program is ready.

Let's go to our interface and set up the chart a little. Select the lower value along the Y axis and set it to 0. Select the upper value and set it to 5. Thus, our scale along the Y axis is in the range of 0-5 volts. Well, we select the COM port, enter the baud rate, launch our program using the arrow button and furiously twist the resistor on the board, while freely observing the result of our work on the screen. Click on the Stop button to stop the program.

You can also combine the pieces into functional blocks so that they do not clutter the diagram.



NI LabVIEW is a streaming graphical programming environment. When writing a program in LabVIEW, the user defines the sequence of data flow transformation operations using a block diagram. Images are placed on the block diagram functional units, connected by conductors through which the data flow passes from one node to another. Also, LabVIEW has a number of paradigm-breaking tools streaming programming, however, allowing you to significantly expand the functionality of the applications developed in it.

What is a programming technique

The term “programming technique” combines a selection of different programming languages, computational models, levels of abstraction, methods of working with code, and representing algorithms. Over the years, National Instruments has developed LabVIEW functionality to provide support for a wider variety of programming techniques.


You can present code written using various techniques as well as G flow code on a block diagram, and LabVIEW will compile instructions for the appropriate target devices (regular desktop PCs, RTOS platforms, FPGAs, mobile devices, ARM-based embedded devices)

Fig.1. Wide range of platforms and programming techniques in LabVIEW



Transferring data between sections of code written using different approaches is organized in LabVIEW very simply - the data flow is the connecting link between different computing models and languages. In the G language, information input/output is carried out using a specialized user interface (front panel), network interfaces, analysis libraries, databases and other tools.

Programming in G
The advent of streaming programming in 1986 was truly innovative. The sequence of performing operations with data in the G language is determined not by the order in which they occur, but by the presence of data at the inputs of these nodes. Operators not connected by a data flow are executed in parallel in random order.

The nodes of the diagram represent simple instructions or their sets - functions, virtual devices (VI). Execution of node instructions occurs only after data appears on all input terminals of the node. After instructions are executed, its result is transmitted through the output terminals of the node to the inputs of the following nodes.


Fig.2. This example adds A and B, multiplies the resulting sum by C, and displays the result


Figure 2 shows an example of a mathematical expression in the G language. The diagram consists of two nodes (addition and multiplication) and three inputs (A, B and C). First, the addition of A and B occurs. The code of the multiplication node is not executed until data is received at both its input terminals, and, therefore, it waits for the result of the addition node. As soon as the addition result arrives at the first input of the multiplication node, its code (A+B)*C will be executed.

Despite the fact that the G language allows you to set the data type explicitly, one of the significant differences between this language and others is the presence of conductors that perform the functions of variables. Instead of passing variables between functions, data transfer is determined by wire connections. On the other hand, G also contains constructs that are standard in other languages, such as conditional loops, counter loops, selection structures, callback functions, and logical functions.

Interactive configuration as the basis of programming
In 2003, National Instruments released NI LabVIEW 7 Express, which introduced Express Virtual Instruments (VII) technology, a technology designed to further simplify the process of developing application algorithms. Unlike regular VIs, express VIs are abstract language structures that implement a programming technique based on interactive setup components.


Fig.3. The Express VI palette, placing the Express VI on a block diagram, and displaying the Express VI in icon view


You can distinguish an express VP from a regular VP by the large blue icon. The first time you place an Express VI on a block diagram, a customization dialog box appears. After configuration is complete, LabVIEW automatically generates code based on the Express VI configuration you created. You can view and edit this code or change the settings of the Express VI by reopening the dialog box by double-clicking the Express VI icon.

As an example, consider the task of entering data to implement them program analysis. LabVIEW makes interfacing with a variety of hardware very easy because it includes drivers for thousands of devices. The task of collecting data can be implemented not only by a design of several VPs, but also by more simple option- express VP.

It is enough to specify read/write channels in the settings of the DAQ Assistance Express VI and configure parameters such as sampling rate, scaling, synchronization and triggers. In addition, the Express VI provides the ability to pre-collect data from the device to verify that the data collection settings selected are correct.


Fig.4. The DAQ Assistant Express VI makes it easy to configure trigger timing and channel parameters



Fig.5. G code equivalent to DAQ Assistant Express VI


Despite all its advantages, Express VIs do not provide the possibility of low-level control and configuration of the operating mode of the device, which is implemented using conventional virtual devices. Users new to LabVIEW can use a built-in function that converts a previously configured Express VI into a sequence of regular VIs. This can help beginners learn low-level code. Just select the Open Front Panel line in context menu Express VI on a block diagram. It should be noted that any Express VI can be replaced by a combination of several regular VIs, and the LabVIEW Professional Development System version allows you to create your own Express VIs.

Support for scripts.m files
With the LabVIEW MathScript RT module, you can import, edit, and run *.m file scripts traditionally used in mathematical modeling and analysis, signal processing, and complex mathematical calculations. You can use them with G code to create stand-alone applications for desktop or real-time hardware.

There are several ways to work with MathScript in LabVIEW. To work with scripts in interactive mode, use the MathScript window shown in Fig. 6


Fig.6. Interactive development text algorithm in the MathScript window


To use *.m scripts in a LabVIEW application and combine text and graphical programming capabilities, you should use the MathScript node, which is shown in Figure 7. Using the MathScript node allows you to embed text algorithms into VI code and use graphic capabilities interface for managing scenario parameters (buttons, sliders, knobs, graphs and other elements).


Fig.7. The MathScript node makes it easy to use .m scripts in G code


The LabVIEW MathScript RT module has its own *.m script engine and does not require third-party installation software. Using the MathScript node allows you to combine the benefits of text-based algorithms, LabVIEW's high degree of hardware integration, an interactive user interface, and other programming techniques discussed in this article into one application.

Object-oriented programming
Object-oriented programming is one of the most popular types of programming. This approach allows you to combine many disparate components in a program into single object classes. A class definition contains the characteristics of an object and a description of the actions that the object can perform, usually called properties and methods. Classes can have children that inherit properties and methods and can override them or add new ones.


Fig.8. The object-oriented approach is based on classes (example in the image) and associated properties and functions of the VI


Using OOP in LabVIEW has become possible since version 8.2

The main advantages of this approach are:

  • . Encapsulation: Encapsulation is the grouping of data and methods into a class in such a way that they can only be accessed through VIs that are members of the class. This approach allows you to isolate sections of code and ensure that changing them will not affect the code in the rest of the program.
  • . Inheritance: Inheritance allows you to use existing classes as a basis for defining new classes. When a new class is created, it inherits the data types and VI members of the class and, thus, implements the properties and methods of the parent class. It is also possible to add your own VIs to change the functionality of the class.
  • . Dynamic dispatch: Defining methods is possible using several VIs of the same name in the class hierarchy. This method is called dynamic dispatching, since the decision about which VI will be called is made at the program execution stage.
These OOP features allow you to make the code more understandable and scalable, and also, if necessary, limit access to the VI.

Modeling and simulation
Modeling and simulation physical systems- a popular approach in the development of systems that are described by differential equations. Studying the model allows us to identify the characteristics of dynamic systems and develop a control unit with the required behavior.

Figure 9 shows the Control & Simulation Loop, which solves a differential equation using algorithms built into LabVIEW in real time over a certain period of time. This programming approach is also data-flow based, like the G language, however, it is usually called signal flow. As shown in Figure 9, you can combine mathematical modeling techniques with other techniques such as G Data Streams and the MathScript Node.


Rice. 9. The simulation diagram shows signal propagation, I/O hardware, and the MathScript node.


The Control & Simulation Loop supports functions that are used to implement models of linear stationary systems on devices running a real-time OS. You can use these functions to define discrete models by specifying a transfer function, a pole-zero diagram, and a system of differential equations. Time- and frequency-domain analysis tools, such as the time-step response or Bode plot functions, allow you to interactively analyze the behavior of open and closed loop control/simulations. You can also use the built-in model conversion tools developed in The MathWorks, Inc. programming environment. Simulink®, which will allow them to be used in the LabVIEW environment. These dynamic systems can be installed on real-time OS devices without requiring multiple program conversion steps thanks to the functionality of the LabVIEW Real-Time Module library, which is ideal for developing control system prototypes and firmware simulation applications.

State diagrams
The NI LabVIEW Statechart module provides the developer with the ability to describe the functionality of a system in the most abstract way possible using state diagrams. Integrating LabVIEW code into diagram states allows you to create an actual working specification of the application. The NI LabVIEW Statechart module adds the ability to organize hierarchical nesting and parallel execution to the functionality of conventional statecharts. It should be noted that state diagrams allow you to describe how a system reacts to events, which makes them a very useful tool for developing reactive systems, such as embedded devices, control systems, and complex user interfaces.


Rice. 10. The LabVIEW Statechart module describes a system based on a state diagram.


Quite often, statecharts are used to divide an application into subsystems, such as data acquisition, data output, network communications, data logging, and user interface management. In this case, state diagrams define what information is transferred between states (subsystems) and in what order they operate.

Statechart-based application architecture allows you to more efficiently develop complex software systems, especially event-responsive systems such as dynamic system controllers, complex user interfaces, and digital communication protocols.

VHDL for FPGA
The LabVIEW FPGA module allows you to use the G language to write FPGA code. However, as with other development techniques, you can use previously written code or simply have the option of choosing how to implement the program. Most FPGAs are programmed using the text-based stream programming language VHDL. Instead of rewriting existing IP blocks in G, you can import VHDL code using a Component-Level IP (CLIP) node. Typically you need a CLIP XML file to configure the interface between block diagram elements, but LabVIEW has a CLIP Import Wizard that allows you to do this automatically. It displays a list of inputs and outputs of the IP block, which can be dragged with the mouse onto the block diagram and used in the application, as shown in Fig. eleven.


Rice. eleven. CLIP node.


Because NI uses Xilinix FPGAs and the Xilinx software toolset in a LabVIEW FPGA module, you can use the Xilinx kernel generator to create a compatible kernel. You can also use the Xilinx Embedded Development Kit to create any software microprocessor. And finally, many third party developers provide Various types IP blocks for bus management, signal processing and specific cores.

Integration of C-like code
You can use sequential text code in your block diagram VIs ​​in several ways. The first way is the Formula Node, which supports a C-like syntax, with variable definitions and semicolons at the end of lines.

The Inline C Node is similar to the Formula Node and provides additional features low-level programming and support for header files without the unnecessary overhead of procedure calls. You can use the Inline C Node to inline any C code, including #defines statements that are syntactically enclosed in parentheses in C code.

Interacting with executable files
When programming in LabVIEW, you often need to access compiled files and libraries from an application written in LabVIEW to reuse algorithms previously developed in other environments. Also, when creating a project, you must access applications written in LabVIEW from other applications.

LabVIEW provides a wide range of different tools to solve these problems. First, LabVIEW can call DLL functions, as well as use ActiveX and .NET interfaces.

Second, an application written in LabVIEW can expose its functionality to another application as a DLL or using ActiveX tools.

In case you have C source code that you want to use in your LabVIEW application, you can compile DLL and connect it using the Call Library Function node. For example, you can organize parallel computing using algorithms written in C, while the management of parallel threads will be handled by a program written in LabVIEW. To make working with external libraries easier, LabVIEW includes an Import Shared Library Wizard that allows you to automatically create or update a wrapper to call the appropriate libraries (Windows . dll file, Mac OS .framework file or Linux .so file).

Also, using System Exec.vi, you can use the interface command line operating system.

The combination of several programming techniques in one development environment makes it possible to reuse algorithms developed in other languages. In addition, the developer can combine high-level and low-level operations in one application, making the code more flexible and visual. Various levels of abstraction allow complex algorithms to be visualized while still allowing low-level application and hardware control. With tight hardware integration, you can use both approaches to handle signals on multi-core, FPGA, and embedded processor platforms.

Problems typically have multiple solutions, and the LabVIEW programming environment is flexible enough to allow you to choose the solution that best suits your needs.

Simulink® is a registered trademark of The MathWorks, Inc.

ARM, Keil, and µVision are trademarks and registered trademarks of ARM Ltd or its subsidiaries.