In this tutorial you fill learn the dataflow of LabView. One might be wondering what dataflow is?? Data flow is the flow of data during runtime. How the block diagram is executed when we run the VI i.e. what is the order of execution is it from left to right or top to bottom (as in text based programming languages). At the start an explanatory introduction of dataflow in LabView is given. After that a VI is designed with the help of which data flow is explained in detail. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.
Table of Contents
Introduction to Data Flow in labview
In computer science the term data flow is used extensively and is based on the idea of disconnecting computational actors into stages that can execute concurrently. Streaming process is another term that can be used concurrently with dataflow.
Dataflow or streaming process languages have been subdivided into several forms. We can also define the architecture of the hardware of dataflow as an alternative to Von Neumann architecture. Reactive programming with spreadsheets is the most obvious example of data-flow programming. The entered values by a user are instantly transmitted to the next logical variable or formula for calculation.
In LabView dataflow is consider as one of the very important terms. A node present in a block diagram will execute only when data is present at all of its input as you will see later in this tutorial. After the execution of a node the output data of the node is transmitted to the next node of the dataflow path. The execution order of the VIs and function on the block diagram is determined by the movement of data through the nodes.
Examples of Data Flow in LabView
- I will now design a simple block diagram and try to explain the data flow through each node with the help of it. Let’s first design a single node block diagram than will increment the input value by one. From the function palette select numeric and then select increment as shown in the figure below,
Figure 1: Increment placement
- Create a control at the input of this increment and an indicator at the output side as shown in the figure below,
Figure 2: Block diagram
- Turn on the highlight, by clicking on the highlight button (with a bulb symbol on it) as shown in the figure,
Figure 3: Highlights
- Enabling this button will allow you to see the flow of data through the wires in respective block diagram and will help you see easily the execution flow in you VI. Now, run the program using run button orb by pressing <Ctrl+R> and see the flow of the data.
- The nodes or wires in which data is not flowing yet will be grayed out where as the wires and blocks where the data is flowing currently will be the color of the data type which is flowing as is obvious front the figure below,
Figure 4: Dataflow
- Obviously, the data will always flow from input side to output side. The output of the above block diagram present on the front panel is shown in the figure below,
Figure 5: Output
- Now, if we insert a node in the above block diagram i.e. add an increment block in the block diagram and connect the input side of second increment block to the output of first and at the output of second block create an indicator and give it a proper name as shown in the figure below,
Figure 6: 2nd increment block diagram
- Now, if we run this block diagram with highlight ON we will exactly understand the flow of data through a node
Figure 7: Disabled node
- You can see in the above block diagram that the data coming from the input side will be incremented by 1 first before reaching to the second increment block.
- The second block is grayed out because it is currently disabled. This block will only be enabled when all the inputs at the node are available. The data flowing from the upper wire when provide the value to the node it will enable the node and hence the increment block as shown in the figure below,
Figure 8: Dataflow through node
- Same will have happen when we add multiple nodes in the block diagram i.e. if we insert a third node after the second increment block as shown in the figure below,
Figure 9: 3rd increment block diagram
- Data will start flowing from the input control at that time both the nodes will be disabled as shown in the figure below,
Figure 10: Both nodes disabled
- After that when the data reaches the first node it enables the second increment block because input will know be present at the node, refer to the figure below,
Figure 11: 1 node enabled
- The above diagram shows that the flow has reached the first node and hence enabled the 2nd increment but the data isn’t yet present at the second node therefore the 3rd increment block is still disabled. The 3rd block will enable only when the data reaches the 2nd node and input is present at the node as shown in the figure below,
Figure 12: Both nodes enabled
- This is the execution flow of the code in one block diagram, but what happens when multiple blocks not connected to each other will run simultaneously, which one of all the blocks will be executed first?
- Let’s discuss this with the help of an example. In the above block diagram add another simple incrementing bock with a control and an indicator and give some value to the control lets’ say 5 as shown in the figure below
Figure 13: Multiple blocks
- When you run this program with highlight button turned ON you can easily see the flow of the data as shown in the figure below,
Figure 14: Multi block data flow
- It is obvious from the above block diagram that dataflow in both the block diagrams is parallel. None of the block in a complete VI can be executed first as we have already discussed in sequence structure tutorials. If you want a portion of a code to be executed after one you must create a node in between them as we have done above in 3 stage increment block.
- Try to do the example we did in previous tutorial (the one with loop completion pop-p message) without using sequence structure i.e. with the help of dataflow, managing the nodes method we discuss above.
(Hint: Use Boolean true and false blocks with stop button)