186
Web Interface Network In this training module, we will cover what the Web Interface Framework, or WIF, is and why we would want to use it. We will then discuss the basics behind how the WIF works. Next we will talk about what we need to set up the WIF in order to get started before ending with examples of using the WIF to configure and monitor our devices. The toolbar you see to the right represents the various settings you can access through the WIF. First let’s talk about what the Web Interface Framework is, and even more importantly why we have it. Prior to the release of the Web Interface Framework, the only way to configure and monitor your remote real-time targets was through NI Measurement and Automation Explorer, which had to reside on a host machine. Only the host had direct access to the setup of and communication with a real-time target.

hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Embed Size (px)

Citation preview

Page 1: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Web Interface NetworkIn this training module, we will cover what the Web Interface Framework, or WIF, is and why we would want to use it. We will then discuss the basics behind how the WIF works. Next we will talk about what we need to set up the WIF in order to get started before ending with examples of using the WIF to configure and monitor our devices. The toolbar you see to the right represents the various settings you can access through the WIF.

First let’s talk about what the Web Interface Framework is, and even more importantly why we have it.

Prior to the release of the Web Interface Framework, the only way to configure and monitor your remote real-time targets was through NI Measurement and Automation Explorer, which had to reside on a host machine. Only the host had direct access to the setup of and communication with a real-time target.

However, with the Web Interface Framework, you can now configure and control your real-time targets through any web browser. You no longer need to install driver software on your host in order to interact with your real-time targets. The Web Interface Framework provides you with a rich, interactive web application client built on Microsoft Silverlight that exposes device-specific information.

Page 2: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

You can compare the interaction between your real-time targets and the Web Interface Framework to the configuration of your router at home. Almost all routers provide a web-client interface that can be accessed through a web-browser. Through the browser you can configure parameters such as the encryption key and security. The router itself has an on-board web-service that deploys this HTML interface.

Similarly, our real-time targets running LabVIEW Real-Time 2010 will run a small embedded web-service to which you can connect using a standard web-browser on the host machine. The browser communicates with the web-service through a standard request/response protocol, allowing you to see the status of your device as well as affect changes to its configuration.

Previously, all configuration and monitoring of remote targets could only be done through NI Measurement and Automation Explorer. Now with the Web Interface Framework, we can configure and monitor our real-time targets by simply pointing to their IP addresses through any standard browser.

Page 3: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

In order to make use of the Web Interface Framework on your remote targets, you will need to have a host computer with LabVIEW 2010 and the LabVIEW Real-Time 2010 Module installed. Through NI Measurement and Automation Explorer, you will have to install LabVIEW Real-Time 2010 on your target device from the host. Upon installing LabVIEW Real-Time 2010 on the target, you will automatically install the NI Web Configuration and Monitoring application, which provides the browser-side interface to your devices. After rebooting the target device, you will be able to make use of the Web Interface Framework by simply opening up a browser and pointing it to the IP address of your target device.

Page 4: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

After directing your browser to the IP address of your target device, you will first come across the Web Configuration and Monitoring homepage which is built upon the Web Interface Framework. You will see several Web Configuration and Monitoring icons on the left-hand side of the page, which allow you to access or configure various settings for your device. At the top of the page, you will notice the buttons that give you the ability to Reboot the real-time target, Login to it, or access the Help documentation for each setting. Clicking on the Help button will open another page in your browser that provides detailed documentation for the current setting you are trying to configure. In this case, we are looking at the System Settings Page.

From the Systems Settings page you can set device settings such as the device name and its comments, and you can view but not edit settings such as the device’s IP Address, model, and serial number.

Page 5: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The next page for the Web Configuration and Monitoring page is the Network Configuration. This page is responsible for viewing and configuring network settings for your LabVIEW Real-Time target. This page lists all the Ethernet adapters detected in the system. The first adapter in the list is the default adapter, but it may not be the primary adapter. For static IPv4 addresses, you can set the IP address and subnet mask through this page.

Page 6: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The Security Configuration page enables you to set security permissions for users to monitor and configure a remote or local system. You can use this page to change the default administrator password, create new user accounts, and grant permissions to users and groups. To create a new user, click on the New User button, set the User Name, Password, and determine what groups they are a part of and what permissions they have.

Page 7: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 8: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Use Time Configuration page to view and set time settings such as the date, current time, time zone, and daylight savings time on your LabVIEW Real-Time target. You can also use this page to set time synchronization sources for your system if it supports this feature.

Page 9: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The Remote File Browser page gives you access to the files stored on your real-time target. With the Remote File Browser, you can transfer files to and from a real-time target. You can also create, delete, and rename files on the target, as well as edit text files in-place.

Page 10: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

With the Web Server Configuration page you can enable the Application Web Server, which hosts LabVIEW web services. You can also enable Secure Sockets Layer (SSL) encryption on both the System Web Server and the Application Web Server.

Page 11: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

You can configure more device-specific parameters. For example, for a Wireless Sensor Network (WSN), you can use the WSN Configuration page to view and set NI WSN gateway settings, add and remove nodes, update firmware, and change network modes.

Page 12: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Using the Installed Configuration Tools page, you can enable and disable the Web Configuration and Monitoring pages installed on the remote device. The Control Name displays the name of each Web Configuration and Monitoring page. Check the Is Enabled? component to specify which pages are enabled from all the installed Web Configuration and Monitoring pages. The Description lists the functionality of each page.

Page 13: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 14: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Getting Started with NI LabVIEW Student Training - Developer Zone - National Instruments (15 March 2011 11:09 PM)

Getting Started with NI LabVIEW Student Training

The LabVIEW Environment

Launching LabVIEW

click National Instruments LabVIEW 8.5.1.

Page 15: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

If you do not have a shortcut for National Instruments LabVIEW 8.5.1, navigate through the programs list and find the National Instruments program directory. A menu appears that shows all National Instruments software installed on your computer. Navigate to LabVIEW 8.5.1 and select the LabVIEW icon. This launches LabVIEW and opens the Getting Started window.

Page 16: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

clipboard.htm

When you launch LabVIEW, the LabVIEW splash screen opens. It may take a few moments for LabVIEW to launch depending on your system configuration and the number of LabVIEW modules you have installed.

 

The Getting Started Window

Page 17: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The Getting Started window is divided in half from left to right. On the left is the Files section and on the right is the Resources section. In the Files section under New, you can create a blank virtual instrument (VI), project, or module-specific project, or you can select the More folder to start from one of the may LabVIEW templates. Under Open, see a list of recently opened LabVIEW files such as VIs and projects. In the Resources section, find additional getting started tools ranging from online discussion forums to a comprehensive library of example programs that are shipped with LabVIEW.

Note: If you do not want to see the Getting Started window every time you launch LabVIEW, you can configure LabVIEW to open a new, blank VI on launch instead. Select Tools»Options.

Page 18: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

clipboard.htm

In the Options dialog box, select Environment from the Category list and place a checkmark inSkip Getting Started window on launch checkbox.

Page 19: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

clipboard.htm

Click OK to save and apply your changes. The many other options in the Getting Started window vary depending on which version of LabVIEW and which toolkits you have installed.It is essential to know how to change the options and preferences for LabVIEW. TheGetting Started windows have many important resources on it that are very useful. Make sure that you are familiar with all of the different resources that are available on the Getting Startedwindow

Front Panel

This tutorial explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of Front Panel objects as well as how to find them on the Controls palette and place them on the Front Panel.

This video explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of Front Panel objects as well as how to find them on the Controls palette and place them on the Front Panel.This video explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of Front Panel objects as well as how to find them on the Controls palette and place them on the Front Panel.This video explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of Front Panel objects as well as how to find them on the Controls palette and place them on the Front Panel.

The front panel window is the user interface for the VI. The front panel has controls and indicators, which are the interactive input and output terminals, respectively, of the VI. Controls and indicators placed on the front panel are automatically placed on the block diagram. Refer to the “Block Diagram” tutorial for more information on block diagram terminals.

Front Panel WindowWhen you open a new or existing VI, the front panel window of the VI appears and functions as the graphical user interface or GUI of a VI. You can find the source code that runs the front panel on the block diagram. The front

Page 20: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

panel window contains a toolbar across the top and a Controlspalette that you can access by right-clicking anywhere on the front panel.

After opening the Controls palette, use it to place controls and indicators on the front panel.  

Note: Use the thumb tack to pin the Controls palette to the front panel and then selectView»Change Visible Categories.

  

In the Change Visible Categories dialog box, click Select All and then OK to make all available controls and indicators visible on the front panel.

Controls and IndicatorsControls – knobs, push buttons, dials, and other input devices – are the interactive input terminals, while indicators — graphs, LEDs, and other displays – are the interactive output terminals of the VI. Controls simulate instrument input devices and supply data to the block diagram of the VI. Indicators simulate instrument output devices and display data the block diagram acquires or generates.

The figure above has two controls – Number of Measurements and Delay (sec) – and one indicator, a waveform graph named Temperature Graph. The user can change the input value for the Number of Measurements and Delay (sec) controls. The user can see the value generated by the VI on the Temperature Graph indicator. The VI generates the values for the indicators based on the code created on the block diagram. To learn more about the block diagram, see the “Block Diagram” tutorial.

Every control and indicator has a data type associated with it. For example, the Delay (sec)horizontal slide is a numeric data type. Double-click the Delay (sec) control to make LabVIEW jump to the terminal location on the block diagram. Notice the color of the terminal. Orange terminals signify a data type called double (DBL), which is a type of numeric data.

The most commonly used data types are numeric, Boolean value, and string. Learn more about data types in the “Data Types” tutorial.

Numeric Controls and IndicatorsThe numeric data type can represent various types of numbers, such as integer or real. The two common numeric objects are the numeric control and the numeric indicator. Objects such as meters and dials also represent numeric data. Use the Controls palette to place a numeric control on the front panel and then use the increment and decrement buttons to adjust its values.

Follow steps 1-3 to create a numeric control and change its value.  

1.       Right-click the front panel to open the Controls palette, and from the Numeric subpalette drag and drop a Numeric Control onto the front panel.  

2.       Label the control Input by double-clicking on the label and typing the word “Input.”

3.       Now change the value of the control by clicking the increment or decrement button. Alternatively, you can double-click the number with either the Labeling tool or the Operating tool, enter a new number, and press the <Enter> key.

Boolean Controls and IndicatorsThe Boolean data type represents data that has only two parts, such as TRUE and FALSE or ON and OFF. Use Boolean controls and indicators to enter and display Boolean values. Boolean objects simulate switches, push buttons, and LEDs. The vertical toggle switch and the round LED Boolean objects are shown below. You can find them in the Boolean subpalette in the Controlspalette (see below).

 String Controls and IndicatorsThe string data type is a sequence of ASCII characters. Use string controls to receive text from the user, such as a password or user name, and use string indicators to display text to the user. The most common string objects are

Page 21: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

tables and text entry boxes as shown below. You can find string controls and indicators in the String and Path subpalette or the Lists and Tables subpalette. Some common string indicators are shown below.

Shortcut Menus and Property Dialog BoxesAll LabVIEW objects have associated shortcut menus and property dialog boxes. As you create a VI, use the shortcut menu items and/or the properties dialog box to change the appearance and/or behavior of front panel and block diagram objects. To access the shortcut menu, right-click the object you want to modify. To access the Properties dialog box, select Properties from the shortcut menu.

Follow steps 1 and 2 to create a string control and then use the Properties dialog box to add a scroll bar. Start with a blank VI.

1.       From the String & Path subpalette, select a String Control and place it on the front panel.

2.       Right-click the string indicator to open the shortcut menu and select Properties.

 

 

3.       From the Properties dialog box, put a check in the Show vertical scroll bar checkbox and click OK.

 

4.       The resulting string control  has a scroll bar so the user can scroll up and down to view all of the text. This allows the use of a small string control to display a large amount of text.

Front Panel Window ToolbarEach window has a toolbar associated with it. Use the front panel window toolbar buttons to run and edit the VI. The following toolbar appears on the front panel window.        Click the Run button to run your VI. You do not need to compile your code; LabVIEW compiles it automatically. You can run a VI if the Run button appears as a solid white arrow, shown at left.        The Run button appears broken when the VI you are creating or editing contains errors. If the Run button still appears broken after you finish wiring the block diagram, the VI is broken and cannot run. Click this button to display the Error List window, which lists all errors and warnings.          Click Run Continuously to run the VI until you abort or pause execution. You also can click the button again to disable continuous running.

        While the VI runs, the Abort Execution button appears. Click this button to stop the VI immediately if there is no other way to stop the VI. If more than one running top-level VI uses the VI, the button is dimmed.

Caution: The Abort Execution button stops the VI immediately before it finishes the current iteration. Aborting a VI that uses external resources, such as external hardware, might leave the resources in an unknown state by not resetting or releasing them properly. Design VIs with a stop button to avoid this problem.

        Click Pause to pause a running VI. When you click the Pause button, LabVIEW highlights on the block diagram the location where you paused execution, and the Pause button appears red. Click the Pause button again to continue running the VI.

  Select the Text Settings pull-down menu to change the font settings for the selected portions of your VI, including size, style, and color.

    Click the Align Objects pull-down menu to align objects along axes, including vertical, edge, and left.  

    Click the Distribute Objects pull-down menu to resize multiple front panel objects to the same size.    Click the Resize Objects pull-down menu to resize multiple front panel objects to the same size.

Page 22: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

    Click the Reorder pull-down menu when your objects overlap each other and you want to define which one is in front or back of another. Select one of the objects with the Positioning tool and then select from Move Forward, Move Backward, Move To Front, and Move To Back.  

        Click the Show Context Help Window button to toggle the display of the context help window.        Enter Text appears to remind you that a new value is available to replace an old value. The Enter Text button disappears when you click it, press the <Enter> key, or click the front panel or block diagram workspace.

Tip: The <Enter> key on the numeric keypad ends a text entry, while the main <Enter> key adds a new line. To modify this behavior, select Tools»Options, choose Environment from the Categorylist, and place a checkmark in the End text entry with Enter key option.

It is important for a VI to have an intuitive and easy-to-read front panel. The front panel is essentially the gateway for all user input and output of a VI. Therefore it is essential that the programmer has good grasp of how to effectively program a front panel

Block Diagram

In this introduction to the Block Diagram, we examine the concept of this tool as well as the Block Diagram’s relationship with the Front Panel. We also explore how to open the Block Diagram, how to find objects in the Functions palette and put them on the Block Diagram, and how to use different toolbar icons. In addition, we learn how to build a simple block diagram to illustrate the important concepts of creating graphical code in NI LabVIEW software.

The block diagram contains the graphical source code of a LabVIEW program. The concept of the block diagram is to separate the graphical source code from the user interface in a logical and simple manner. Front panel objects appear as terminals on the block diagram. Terminals on the block diagram reflect the changes made to their corresponding front panel objects and vice versa.  

Block Diagram WindowWhen you create or open a new VI, the front panel opens automatically. To bring up the block diagram, select Window»Show Block Diagram from the menu bar. Additionally, you can toggle between the block diagram and the front panel by pressing <Ctrl-E>.

Block Diagram Objects and EnvironmentBlock diagram objects include terminals, subVIs, functions, constants, structures, and wires that transfer data among other block diagram objects. You can use LabVIEW tools to create, modify, and debug a VI. A tool is a special operating mode of the mouse cursor, so the operating mode of the cursor corresponds to the icon of the tool selected. LabVIEW chooses which tool to select based on the current location of the mouse. You can manually choose the tool you need by selecting it on the Tools palette (from the menu bar, select View»Tools Palette). Now you can choose your desired tool, which remains selected until you choose another tool from the Toolspalette.

To place objects on the block diagram, simply drag and drop them from the Functions palette. The Functions palette automatically appears when you right-click anywhere on the block diagram workspace. It contains functions, constants, structures, and some subVIs.

Notice the two buttons on the top of the Functions palette.         The Thumb Tack pins the Functions palette to the block diagram.  The Search button opens a search dialog box that you can use to search for functions by name.

Click the Search button to launch the functions search engine. It takes a few moments to launch.

You can use this tool to search for a function by name if you are having trouble finding it.

Page 23: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Once you see the function you want, double -click on it and LabVIEW jumps to the place on theFunctions palette where you can find that function.

Note: Complete the following steps to change the subpalettes visible on the Functions palette:

1.       Use the thumb tack to pin the Functions palette to the block diagram.

 

2.       Notice the View button appears when you pin the Functions palette to the block diagram.

3.       Select View and, from the shortcut menu, select Change Visible Categories.

4.       In the Change Visible Categories dialog box, you can select the Palettes that you use the most or click Select All to include all Palettes.

To change the appearance of the block diagram, select Tools»Options from the menu bar. In theOptions dialog box, select the Block Diagram category. Here you can customize the appearance of your block diagram. To save space on the block diagram, deselect Place front panel terminals as icons.

TerminalsTerminals create the block diagram appearance of objects on the front panel. In addition, they are entry and exit ports that exchange information between the front panel and block diagram. Analogous to parameters and constants in text-based programming languages, terminals come in two types: control or indicator terminals and node terminals. Control and indicator terminals belong to front panel controls and indicators.[+] Enlarge Image

In the example above, data you enter in front panel controls a and b enter the block diagram through their respective control terminals a and b. The data then enter the Add and Subtract functions. When the Add and Subtract functions complete their calculations, they produce new data values. The data values flow to the indicator terminals, where they update the front panel indicators a+b and a-b.

Controls, Indicators, and ConstantsControls, indicators, and constants operate as the inputs and outputs of the block diagram algorithm. Controls receive their values from the front panel and pass data to other block diagram objects. Indicators receive their values from block diagram logic and pass data from the block diagram to the front panel. Constants pass data to the object to which they are wired. Consider an algorithm for computing the area of a triangle. You might have the following front panel and corresponding block diagram.

The constant Triangular Multiplier does not necessarily appear on the front panel window except possibly as documentation of the algorithm. It simply passes the value of .5 into the multiply function. Notice that the Base(cm) and Height(cm) block diagram terminals look different from theArea(cm^2) terminal. There are two distinguishing characteristics between a control and an indicator on the block diagram. The first is an arrow on the terminal that indicates the direction of data flow. The controls have arrows showing the data leaving the terminal, whereas the indicator has an arrow showing the data entering the terminal. The second distinguishing characteristic is the border around the terminal. Controls have a thick border and indicators have a thin border.

You can create controls and indicators from either the block diagram or the front panel. This tutorial demonstrates this in a later section.

Block Diagram NodesNodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs. They are analogous to statements, operators, functions, and subroutines in text-based programming languages. Nodes can be functions, subVIs, or structures. Structures are process control elements, such as case structures, for loops, or while loops, which are covered in a later tutorial. The image below shows some examples of block diagram nodes.

 

Page 24: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

FunctionsFunctions are the fundamental operating elements of LabVIEW. Functions do not have front panel windows or block diagram windows, but they do have input and output terminals for passing data in and out similarly to controls and indicators. You can tell if a block diagram object is a function by the pale yellow background on its icon. The Functions palette has functions arranged in groups based on the type of function they perform. Look in the Numeric subpalette for functions that perform numeric operations.

 

There are many different types of functions. Remember that a function has a pale yellow background like the functions shown below.   

SubVIsSubVIs are VIs that you create to use inside another VI or that you access on the Functionspalette. Any VI has the potential to be used as a subVI. When you double-click a subVI that is on the block diagram, its front panel window appears and you can access its block diagram. Some examples of the subVIs you can find in the Functions palette are shown below.

StructuresStructures, which include for loops, case structures, and while loops, are used for process control. They are examined in a later tutorial. You can open the Structures subpalette from theFunctions palette under Programming.

Below are some examples of different structures and how they look on the block diagram.[+] Enlarge Image

Now create the block diagram shown below by following these steps:

1.       Open a blank VI from the toolbar. Select File»New VI.

2.       Put two multiply functions on the block diagram by dragging them onto the block diagram from the Numeric subpalette under Programming. Repeat to put a second multiply function on the block diagram.

Page 25: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Tip: To copy an object on the block diagram, hold down <ctr> while you click and drag the object.

3.       Hover your mouse over the left-most multiply function to make the input and output terminals appear. If you hold your mouse over one of the terminals, the wire spool appears along with the name of the terminal you are hovering over.

To create a control for the y terminal, simply hover your mouse over it and right-click.

Do the same for the x terminal on the left-most multiply function so that you have a control for each input terminal.

Page 26: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

4.       Wire the output terminal of the left multiply function to the x input of the right multiply function by hovering your mouse over the output terminal. When it turns into the wiring spool, click and hold while you drag the wire to the desired input.

5.       Create the Triangular Multiplier constant .5 by right-clicking on the y input terminal of the right-most multiply function and selecting Create»Constant. You can change the value of a constant by double-clicking it to highlight the text and typing in the new value. Type in .5 and press<enter>.

   

6.       Now right-click the output of the right multiply function and select Create»Indicator to create an indicator that passes the value of the block diagram logic to the front panel.

Tip: You can make comments on the block diagram or the front panel by double-clicking the block diagram and typing your comment into the automatically created text box.

You can change the name of indicators, controls, and constants by double-clicking the label and typing in the desired name. If there is no label showing, right-click the desired object and selectVisible Items»Label.

Page 27: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

7.       Now look at the front panel that was generated from your work on the block diagram by pressing <ctr-E> or selecting Window»Show Front Panel. Notice that the two controls Base(cm) and Height(cm) and the indicator Area(cm^2) were automatically generated and placed on the front panel. You will run this program after learning about the toolbar icons.  

 

Block Diagram Window ToolbarWhen you run a VI, the following toolbar appears on the block diagram. You can use some of the buttons on the block diagram toolbar to debug the VI. Those buttons are covered in a later tutorial.

[+] Enlarge Image

        Click the Run button to run your VI. You do not need to compile your code; LabVIEW compiles it automatically. You can run a VI if the Run button appears as a solid white arrow, shown at left.

        The Run button appears broken when the VI you are creating or editing contains errors. If the Run button still appears broken after you finish wiring the block diagram, the VI is broken and cannot run. Click this button to display the Error List window, which lists all errors and warnings.  

        Click Run Continuously to run the VI until you abort or pause execution. You also can click the button again to disable continuous running.

        While the VI runs, the Abort Execution button appears. Click this button to stop the VI immediately if there is no other way to stop the VI. If more than one running top-level VI uses the VI, the button is dimmed.

Page 28: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Caution: The Abort Execution button stops the VI immediately before it finishes the current iteration. Aborting a VI that uses external resources, such as external hardware, might leave the resources in an unknown state by not resetting or releasing them properly. Design VIs with a stop button to avoid this problem.

        Click Pause to pause a running VI. When you click the Pause button, LabVIEW highlights on the block diagram the location where you paused execution, and the Pause button appears red. Click the Pause button again to continue running the VI.

  Select the Text Settings pull-down menu to change the font settings for the selected portions of your VI, including size, style, and color.

    Click the Align Objects pull-down menu to align objects along axes, including vertical, edge, and left.  

    Click the Distribute Objects pull-down menu to resize multiple front panel objects to the same size.

    Click the Reorder pull-down menu when your objects overlap each other and you want to define which one is in front or back of another. Select one of the objects with the Positioning tool and then select from Move Forward, Move Backward, Move To Front, and Move To Back.  

        Click the Show Context Help Window button to toggle the display of the context help window.

        Enter Text appears to remind you that a new value is available to replace an old value. The Enter Text button disappears when you click it, press the <Enter> key, or click the front panel or block diagram workspace.

Running a VI from the Block DiagramFinally, click the Run Continuously button on the VI you just created and change the values on the front panel. Watch how changing the control values of a and b updates the indicator value of a*b.

 

Values put into the controls on the front are passed to the block diagram, and the result that is computed by the block diagram logic is passed back to the front panel indicator.

Click the Abort Execution button to stop the VI. Save and close the VI by selecting File»Save from the menu bar and then clicking the Close button in the top right corner of the front panel window.

Page 29: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The block diagram is the most fundamental aspect of any virtual instrument. It controls everything from data flow to passing data in and out of the front panel.  It is essential for a LabVIEW programmer to have a clear and solid understanding of how the block diagram works.

User Interface

This tutorial examines how to use NI LabVIEW tools to build user interfaces. Learn how to design controls and indicators, use labels and captions, set default values for user interface objects, and apply color to enhance the appearance of your user interface. Also get some basic tips and tools to help you create elegant and functional user interfaces like the one below.

ConceptA user interface gives users a way to interact with the source code. It allows the user to change the values passed to the source code and see the data that the source code computes. In LabVIEW, the user interface is the front panel. It is important to identify the inputs and outputs of a software development problem during the design phase of the development method. This identification leads directly to the design of the front panel window.

You can acquire the inputs of the problem using the following methods:

1.       Acquiring from a device such as a data acquisition device or multimeter

2.       Reading directly from a file

3.       Manipulating controls

You can display the outputs of the problem with indicators such as graphs, charts, or LEDs, or you can log the outputs to a file. You can also output data to a device using signal generation.

Designing Controls and IndicatorsWhen choosing controls and indicators, make sure that they are appropriate for the task you want to perform. For example, when you want to determine the frequency of a sine wave, choose a dial control, and when you want to display temperature, choose a thermometer indicator.

Labels and CaptionsMake sure to label controls and indicators clearly. These labels help users identify the purpose of each control and indicator. Also, clear labeling helps you document your code on the block diagram. Control and indicator labels correspond to the names of terminals on the block diagram.

Captions help you describe a front panel control. They do not appear on the block diagram. With captions, you can document the user interface without cluttering the block diagram with additional text. Open a blank VI and make a label and a caption for a thermometer indicator.

1.       Put the thermometer indicator on the block diagram.

2.       By default, only the label is visible. To change the label, double-click it and type in a new label that is short but descriptive.

3.       Right-click the thermometer indicator and select Properties.  

In the Properties dialog box, put a check in the Visible checkbox under the Caption section of theAppearance tab. Type Indoor Temperature in the Caption text box. Click OK to save the changes and exit the dialog box. You can also change the label from the Properties dialog box.

Page 30: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

4.       Notice that the caption now appears on the front panel above the indicator. Switch to the block diagram and note that only the label appears.

 

Control and Indicator OptionsThe front panel offers many options for controls and indicators that you can view by right-clicking on the thermometer indicator and browsing through the shortcut menu and submenus. Complete the following steps to create a temperature control and set the default value.  

1.       Put a numeric control on the front panel beneath the thermometer indicator. Make a caption for it that says “Indoor Temperature Control.”

2.        Enter the desired value.

3.        Right-click the control and select Data Operations»Make Current Value Default from the shortcut menu.[+] Enlarge Image

4.       Because you have a good caption for the temperature control, hide the label by right-clicking the control and selecting Visible Items»Label from the shortcut menu. Do the same for the thermometer indicator.

Using ColorThe proper use of color can improve the appearance and functionality of your user interface. Using too many colors, however, can result in color clashes that cause the user interface to look too busy and distracting. LabVIEW provides a color picker that can help with determining the appropriate colors. Select the Coloring tool from the tools palette and right-click an object or workspace to display the color picker. With the color picker open, you can move your cursor to different colors and watch the objects or workspace change as you move over different colors.  [+] Enlarge Image

The top of the color picker contains a grayscale spectrum and a box you can use to create transparent objects. The second spectrum contains muted colors that are well-suited for backgrounds and front panel objects. The third spectrum contains colors that are well-suited for highlights. Moving your cursor vertically from the background colors to the highlight colors helps you select appropriate highlight colors for a specific background color.[+] Enlarge Image

 

Spacing and AlignmentWhite space and alignment are probably the most important techniques for grouping and separation; the more items that your eye can find on a line, the cleaner and more cohesive the organization seems. When items are on a line, the eye follows the line from left to right or top to bottom. This is related to the script direction. Although some cultures view items right to left, almost all follow top to bottom. When you design the front panel, consider how users interact logically with the VI and group controls and indicators. If several controls are related, add a decorative border around them or put them in a cluster.

Centered items are less orderly than items aligned to the left or right. A band of white space on one side acts as a very strong means of alignment. Centered items typically have ragged edges, and users cannot determine the order as easily.

Placing front panel objects too close together can be problematic. Leave some blank space between objects to make the front panel easier to read. Blank space also prevents users from accidentally clicking the wrong control or button.

In general, use common sense and develop your own style of design for your user interfaces. Also refer to these guidelines to help you successfully create user-friendly front panels. Notice the difference between the following two simple user interfaces. Proper labeling, alignment, and spacing can make a big difference.[+] Enlarge Image[+] Enlarge Image

Page 31: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

User Interface Tips and ToolsSome of the built-in LabVIEW tools for creating user-friendly front panel windows include tab controls and decorations.

Tab ControlsPhysical instruments usually have effective user interfaces. Borrow heavily from their design principles but use smaller or more efficient controls, such as ring controls or tab controls, where appropriate. Use tab controls to overlap front panel controls and indicators in a smaller area.

To add more pages to a tab control, right-click a tab and select Add Page Before or Add Page After from the shortcut menu. Relabel the tabs with the Labeling tool and place front panel objects on the appropriate pages. The terminals for these objects are available on the block diagram, as are terminals for any other front panel object (except decorations). Complete the following steps to create a tab control with a thermometer indicator, temperature control, fan speed control, and sector alarm for a building with three sectors. Start with a new VI.

1.       Create a new VI by selecting File»New VI from the menu bar.

2.       Add one round LED and label it Sector 1 Alarm, add one thermometer indicator and label it Sector Temperature, and add one dial control and label it Fan Speed Control. Your front panel should look like this. (This tutorial does not include examples featuring block diagrams.)[+] Enlarge Image

3.       Add a tab control from the Controls palette as shown.[+] Enlarge Image

4.       Expand the tab control and add one additional tab after the second tab by right-clicking the tab and selecting Add Page After. Label each tab appropriately by double-clicking and typing a label for each of the three sectors of the building.[+] Enlarge Image

5.       Add the various controls and indicators to each tab. Remember you can hold <Ctr> while you click and drag an object to copy it. Arrange the objects logically and rescale them if needed. Your VI may look something like this.[+] Enlarge Image

DecorationsUse the decorations located on the Decorations subpalette to group or separate objects on a front panel with boxes, lines, or arrows. The objects on the Decorations palette do not display data or show up on the block diagram. Try adding some decorations to the front panel you just made.[+] Enlarge Image

Page 32: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

[+] Enlarge Image

 

It is important to create visually appealing and organized user interfaces.  Since the user interface is generally what the end user will be working with, it is very important to make it as straight forward and intuitive as possible

Module Exercise

This exercise will go over the components of the LabVIEW Environment. You will be able to see how the Front Panel interacts with the Block Diagram. You will walk through a series of instructions that will introduce you to changing properties of LabVIEW as well as controls, indicators, and functions.

GoalUnderstand the basic components of the LabVIEW environment and learn the elementary concepts of graphical programming.

Description

Page 33: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

This exercise consists of a series of tasks in which will walk you through launching the LabVIEW environment, changing various options, creating a simple virtual instrument, running the virtual instrument, and using the example finder found in LabVIEW.

Introduction to the LabVIEW Environment1. Launch LabVIEW.

❑ From the start menu, click the Labview 8.5 program to launch LabVIEW.

2. Wait for the splash screen to occur and the Getting Started menu to be displayed.

3. Create a blank VI.

     ❑ Click New»Blank VI

4. Display both the front panel and the block diagram.

❑ In the window labeled Untitled 1 Front Panel, navigate to and select  Tile Up and Down to concurrently display both the front panel and block diagram on the screen.

5. Customize the options in LabVIEW.

❑ Navigate to and select Tools»Options to bring up the Options window for LabVIEW.

 

❑ Click on the Environment submenu. In this menu, there are going to be  a few settings of interest:

•  Maximum undo steps per VI – This option sets the maximum amount of “undo” steps the user can make for each individual vi. This number can be increased if the user desires and the physical memory on the system allows it.

•  Automatic Saving Settings – This option sets how LabVIEW auto saves the current project. This can be adjusted to your preferences.

 

 

❑ Next click on the Block Diagram submenu on the left. In this options menu, one useful option to note is the Place front panel terminal as icons. Many people prefer this option to be disabled as it cleans up the block diagram and makes front panel elements easier to read on the block diagram.

 

❑ Close the options menu by clicking OK.

6. Create a Numeric Control on the front panel.

❑ Right click anywhere within the front panel. This brings up the controls palette with all of the available controls.❑ Select Modern»Numeric»Numeric Control from the controls palette and then click on an empty space on the front panel. Notice how an element also appears on the block diagram that corresponds to the control.

7. Use the Search feature to place an Add function on the block diagram.

❑ Right click anywhere on the block diagram. This brings up the functions palette with all of the available functions.  To place a function on the block diagram click the function on the functions palette and then click on an empty space on the block diagram.

Page 34: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

❑ To search for a specific function within the functions palette, click the Search button on the functions palette.  This brings up the search window. In the search field type “Add”.

❑ Place the Add  <<Numeric>> function on the block diagram. This can be done by dragging the search result directly from the search window to the block diagram. 

8. Create a constant input for the Add function with representation I32 

❑ Right click the first input of the Add function and select Create»Constant.

❑ Give the constant a value of 10.❑ Move the control to a different part of the block diagram by clicking and holding it, and then dragging it to a different location. 

❑ Right click the constant and select Representation»I32. This changes the numeric representation of the constant to a 32-bit integer, also known as a long.

9. Create a control for the second input of the Add function.

❑ Right click the second input of the Add function and select Create»Control.

❑ Move the control to a different position of the block diagram by clicking and holding it, and then moving the mouse to an unused spot in the block diagram.

10. Create an indicator output for the Add function.

❑ Right click the output of the Add function and select Create»Indicator. Notice how the representation of the output matches that of the input terminals.

11. Left align the elements on the front panel

❑ Move the Numeric Indicator below the Numeric Control as seen below by clicking and holding the Numeric Indicator and dragging it below the Numeric Control.

 

❑ Highlight both elements and then select Left Edges from the Align Objects menu.

12. Rename the control and indicator on the front panel.

❑ Double click the "y" text label of the numeric control to select the text.

❑ With the keyboard, type "Original Number" to change the name of the control.

❑ Repeat this process for the Numeric Indicator. Name the indicator "Number + 10".

Page 35: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

13. Give a value of 100 to the Original Number control.

❑ On the front panel, double click the number box of the Original Number control and type in a value of 100.

14. Run the VI.

❑ Click the Run button on the toolbar of the front panel.

❑ Observe how the VI takes the number from the Original Number control and add the constant's value of 10 to it. It then displays the result in the Number + 10 indicator.

 

15. Use the Example Finder to find a simple pulse train example.

❑ To access the NI Example Finder, navigate to Help»Find Examples... of either the block diagram or the front panel.

Page 36: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ This brings up the Example Finder. The example finder contains a database of example VIs written by National Instruments. Click on the Search tab. In the search field type “Pulse Train Demo”. Double click the first result to bring up the example VI.

 

❑ On the front panel of the example that opens click the run panel to start the VI.

Page 37: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Observe how a waveform graph is generated based off of the options on the front panel.

❑ Click the STOP button on the front panel.

❑ Change the “pulse prototype” option to “Sine Pattern” by clicking the up arrow on the control.

❑ Run the VI again and observe the generated Sine Wave.

Page 38: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

16. Close both VIs and do not save changes

Page 39: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Module 2: Passing Data, Debugging, and SubVIs - Developer Zone - National Instruments (16 March 2011 12:00 AM)

Module 2: Passing Data, Debugging, and SubVIs

Wires

In text-based programming languages, you store and access data with functions through the use of variables. In the NI LabVIEW graphical programming language, wires implicitly handle all of the data storage and access that are associated with variables in text-based languages. Think of wires as a path for data to flow. Data comes into block diagram objects through a wire and can leave only through a wire. In the figure below, wires connect the control and indicator terminals to the Add and Subtract functions. As you can see, each wire has a single data source or starting point. However, you can branch off one wire and wire it to many VIs and functions. By branching off the main wire, you can send data to multiple destinations. Note that wires are different colors, styles, and thicknesses. Color, style, and thickness change depending on the type of data the wire is transmitting.

 

Broken wires (wires that are not connected properly) prevent your VI from running. A broken wire appears as a dashed black line with a red X in the middle, as shown below.

 

Broken wires occur for a variety of reasons such as wiring two objects with different or incompatible data types. For example, you cannot wire an array output to a numeric input. The data in the wire is an array and the input is expecting a single numeric, so the data types are not compatible. When connecting block diagram objects with wires, you must connect a wire to one input and at least one output. For example, you cannot wire two indicators together. The figure below shows the most common wire types. Notice the different colors and thicknesses of the wires indicating the different data types.

 

Data TypesEvery wire has a type based on the data that it is transmitting. The data type of a wire determines which object, indicators, or functions you can connect a wire to. For example, if a switch has a green border, you can wire a switch to any input with a green label on an Express VI or function. Note that the wire will also be green, reflecting the Boolean data type. If a knob has an orange border, you can wire a knob to any input with an orange label and the wire will be orange. You cannot wire an orange knob to an input with a green label because the data types are not compatible. Note that the wires are the same color as the terminal. The figure below shows the correct wiring of two controls to a subVI. Note that the color of the wire and control matches the color of the input terminal.  

 

The figure below shows the incorrect wiring of two controls to a subVI. The data type of the control does not match the data type of the input terminal on the subVI. Hold your mouse over the broken wire to see the data types required. Note that the source is a double and the sink, or input, is a Boolean. The wire is broken because the data types are different.  

Tip: You can quickly delete all broken wires from your block diagram by pressing <ctr-B>.

Automatically Wiring ObjectsYou can use the LabVIEW auto wiring feature to connect objects on the block diagram faster. As you move a selected object close to other objects on the block diagram, LabVIEW draws temporary wires to show you valid connections. When you release the mouse button to place the object on the block diagram, LabVIEW automatically

Page 40: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

connects the wires. You can also automatically wire objects already on the block diagram. LabVIEW connects only the terminals that match. Toggle automatic wiring by pressing the spacebar while you move an object using the Positioning tool.

You enable automatic wiring by default when you select an object from the Functions palette or when you copy an object already on the block diagram. You disable automatic wiring by default when you use the Positioning tool. You can adjust these settings by selecting Tools»Options and selecting Block Diagram from the Category list. 

You can enable or disable automatic wiring by checking or unchecking the checkbox as shown. 

Manually Wiring ObjectsOften you may want to manually wire the objects on the block diagram together. Note that when you pass the Wiring tool over a terminal, a tip strip appears with the name of the terminal. Use this feature to ensure that you are selecting the correct terminal before wiring.  

To wire objects together, pass the Wiring tool over the first terminal and click and drag the cursor over to the second terminal (if the Tools palette is on auto-select, the wiring tool automatically appears when you hold the mouse over a terminal). Click again on the destination terminal to terminate the wire.

After wiring, you may want to clean up the path of the wire. Simply right-click the wire and selectClean Up Wire from the shortcut menu. LabVIEW automatically chooses a path for the wire.  

To learn more about wiring by manually wiring several controls and indicators, follow the steps below:

1.       Create a new VI and place a knob on the front panel by selecting it from the numeric subpalette in the Controls palette.

2.       Place a tank indicator on the front panel to the right of the knob.

3.       Place a round LED on the front panel beneath the tank.

4.       Now switch to the block diagram. Note that all three front panel objects are on the block diagram. Both Knob and Tank are orange and Boolean is green. Remember that the color represents the data type. Knob and Tank are both a data type of DBL while Boolean is a data type of Boolean. Hold the mouse over the output terminal of Knob so that the wiring tool appears. Click and drag the wire to the input terminal of Tank.[+] Enlarge Image

5.       Hold your mouse over the wire connecting Knob and Tank so that the wiring tool appears. Click and drag to create a new wire coming off the existing wire. Try to connect the new wire toBoolean. Note that doing this causes the wire to break. Because Knob is a data type of DBL andBoolean is a data type of Boolean, you cannot connect them. Also notice that the Run arrow on the toolbar is broken. A broken wire prevents your VI from running.  

6.       Delete the broken wires by pressing <ctr-B> and reconnect Knob to Tank. Go to the front panel and select Run Continuously. Use your mouse to move the Knob control to different values. Notice how it updates the level in the tank. This happens because the value of the Knob control is being passed by the wire on the block diagram to the Tank indicator. Because there is no data wired to Boolean, it does not change value.

7.       Select Abort Execution to stop the VI. From the Controls palette, select a vertical toggle switch and place it next to the LED.

8.       Note that they are both labeled as Booleans. Switch to the block diagram and wire the output of the vertical toggle switch (Boolean2) to the input of the LED (Boolean).

9.       Now select Run Continuously from the front panel. Use your mouse to toggle the vertical toggle switch from on to off. Observe how the LED changes from off to on.

10.   Close the block diagram and front panel without saving changes.  

Wires are one of the most fundamental building blocks of a virtual instrument. They determine how the elements on the block diagram interact with each other and determine the flow of the execution in general.

Page 41: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Data Types, Dataflow and Debugging

Just as in any other programming languages, it is important to have a basic understanding of the different data types in NI LabVIEW software and how to access them when composing a VI. When you are unsure of a wire’s data type or of the inputs and outputs a certain VI accepts, the Context Help window is a very powerful tool for finding this information. Once you wire a VI, it is important to pay attention to the data flow of the VI to determine the program’s sequence of events. When you are unsure of the exact sequence of events in a VI, you can use the Highlight Debugging feature to slow down the code and visually observe the data flow of the VI.

LabVIEW Data Types1.       Open a blank VI from the toolbar by selecting File»New VI.

2.       Right-click on the front panel to open the Controls palette and selectModern»Boolean»Vertical Toggle Switch, and place the switch on the front panel. This control is of the Boolean data type, which means it can take on one of two values, TRUE or FALSE.

 

3.       Open the Controls palette and select Modern»Boolean»Round LED, and place the LED on the front panel. This indicator is also a Boolean data type.

Page 42: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

 

4.       Open the block diagram of the VI by selecting Window»Show Block Diagram, and notice that the Boolean control and indicator are both represented by green icons. This is the color for all Boolean data types in LabVIEW.

5.       Wire the output of the toggle switch control to the input of the LED indicator. Note that the wire connecting the two icons is also green.

6.       Return to the front panel by selecting Window»Show Front Panel. Right-click on the toggle switch control and hover your mouse over Mechanical Action to view the available switching actions for switch when pressed. Leave the action as Switch When Pressed.

Page 43: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

7.       Open the Controls palette, select Modern»String & Path»String Control, and place a string control on the front panel. The string data type is composed of a sequence of displayable or non-displayable ASCII characters.

8.       Open the Controls palette, select Modern»Numeric»Numeric Control, and place a numeric control on the front panel. The numeric data type is composed of numbers, and can take on several different representations. Right-click on the numeric control and selectRepresentation»Long (I32) to change the control to a 32-bit integer.

Page 44: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

9.       From the Controls palette, select Modern»Numeric»Numeric Indicator and place the numeric indicator on the front panel. Leave this indicator’s representation as the default double precision (DBL).

Page 45: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

10.    Open the block diagram and observe the colors associated with each new control and indicator. The string data type is pink, the long numeric data type is blue, and the double precision numeric data type is orange.

11.   Open the front panel and the Controls palette, select Modern»Ring & Enum»Enum, and place the Enum control on the front panel. The Enum control is an enumerated list of string values, where each string value has a numeric value associated with it.

Page 46: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

12.   Right-click on the Enum control and select Edit Items… to open up the Edit Items tab under Enum Properties. On the Edit Items tab, click on Insert and type in a string with the keyboard. Press the <Enter> key to create a new item below the current item, or click on Insert to insert a new item above the current item. Repeat the process until you have at least a few items in the Enum.

Page 47: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

13.   Click on the OK button when finished entering items into the Enum.

14.   Open up the block diagram, right-click on the output pin of the Enum control, and selectCreate»Indicator to create an indicator that is wired to the Enum control. Note that the indicator is also an Enum.

15.   In the block diagram of the VI from above, right-click on a blank space to open the Functionspalette, select Programming»String»String Length, and place the function on the block diagram.

Page 48: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

[+] Enlarge Image

16.   Open the Functions palette again, select Programming»Numeric»Add, and place an add function on the block diagram.

Page 49: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

[+] Enlarge Image

17.   Wire the newly placed functions with the unconnected controls and indicators as seen in the figure below.

 

Using Context HelpThe Context Help window displays basic information about LabVIEW objects when you hover your mouse over each object.

 

Page 50: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

1.       Open the Context Help window by selecting Help»Show Context Help, pressing the <ctr-H>keys on the keyboard, or by clicking on the Show Context Help Window button on the toolbar, as seen in the figure below.

 

2.       Hover your mouse over the different wires, controls, and indicators to see their data types in the Context Help window. Hover your mouse over the functions to see a brief explanation of their functions and the inputs and outputs they accept.

[+] Enlarge Image

3.       Click on the Detailed Help link at the bottom of the Context Help window to get a more detailed description of the function and its inputs and outputs.

Data FlowAs mentioned earlier, the concept of data flow is important to keep in mind when programming. Just as a line of text-based code must wait for data to reach it before executing, a node (function or VI) must wait until data reaches all of its input terminals before executing. Once that node finishes execution, it passes its output to the next node in

Page 51: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

the execution sequence. In the VI that you built, although one of the inputs to the add function is immediately available, the node must wait for the string length function to execute first because its output is the other input to the add function.

So data flow can sometimes determine the order of execution of LabVIEW code. In this case, it forces the string length function to execute before the add function, as seen in the figure above.

Debugging with Highlight Execution

When trying to visualize the data flow of a particular VI, a very useful tool is highlight execution or execution highlighting. Implement execution highlighting by clicking on the Highlight Executionbutton on the toolbar, as seen in the figure below.

1.       Click on the Highlight Execution button on the toolbar. Note that the light bulb on the button is now filled in.

 

2.       Run the VI by selecting Operate»Run, pressing the <ctr-R> keys on the keyboard, or by clicking on the Run button on the toolbar.

 

 

3.       Observe the data flow of the VI on the block diagram. Observe the sequence of execution of the nodes.

Page 52: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Note: Not only does execution highlighting show the sequence of execution, but it also slows down the speed of execution so that it is visible to the user. This execution speed impacts the overall performance of the VI, and should be turned off to return execution to normal speeds.

 

4.       Click on the Highlight Execution button to turn off execution highlighting. The light bulb on the button is no longer filled in.

Note: When an application appears to be running suspiciously slowly, it is always a good idea to check the Highlight Execution button to see if execution highlighting is enabled

SubVIs

Modularity, by definition, means to use modules or smaller parts for the overall objective. Within LabVIEW, program modularity means creating smaller sections of code known as subVIs. SubVIs are the same as VIs. They contain front panels and block diagrams, but you call them from within a VI. A subVI is similar to a subroutine in text-based programming languages.

When you create a subVI and use it, you see an icon within your block diagram that represents the subVI. You can customize this icon, which is the same icon in the upper right corner of the subVI front panel and block diagram. Learn how to customize icons in a later section of this tutorial.

The following figures demonstrate the difference when replacing a section of code with a subVI. You can see the simplicity in the bottom figure.

Page 53: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

You can create a subVI just like a VI and then use it as a subVI, or you can create a subVI from code already within another VI. Once you create a VI, you can:

•    Customize the icon for the subVI

•    Configure the terminals

•    Use it within other VIs repeatedly

Creating a SubVI from an Existing VIYou can simplify the block diagram of a VI by converting sections of the block diagram into subVIs.

1.  Create a new VI and construct the following block diagram.

2.  Select the section of the block diagram you want to convert.

Page 54: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3.  From the Tools menu, select Edit»Create SubVI.

 

The selected section of the block diagram is replaced with an icon for the subVI. LabVIEW creates controls and indicators for the new subVI, automatically configures the connector pane based on the number of control and indicator terminals you selected, and wires the subVI to the existing wires.

The new subVI uses a default pattern for the connector pane and a default icon.

Creating an IconCreate custom icons to replace the default icon by right-clicking the icon in the upper right corner of the front panel or block diagram and selecting Edit Icon. You can also do this by double-clicking the icon in the upper right corner of the front panel.

 

Page 55: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

Once you open the Icon Editor, you have many tools for creating a custom icon or importing an image.

You also can drag a graphic from anywhere in your file system and drop it in the upper right corner of the front panel or block diagram. LabVIEW converts the graphic to a 32x32 pixel icon.

You can find a standard set of graphics to use as a VI icon at ni.com/info by entering the info codeexpnr7.

Use the tools on the left side of the Icon Editor dialog box to create the icon design in the editing area. The normal size image of the icon appears in the appropriate box to the right of the editing area, as shown in image of the front panel above.

Use the Edit menu to cut, copy, and paste images from and to the icon. When you select a portion of the icon and paste an image, LabVIEW resizes the image to fit into the selected area. You also can drag a graphic from anywhere in your file system and drop it in the upper right corner of the front panel window or block diagram window. LabVIEW converts the graphic to an icon.

Use the Copy from option on the right side of the Icon Editor dialog box to copy from a color icon to a black-and-white icon and vice versa. After you select the Copy from option, click the OK button to complete the change.

Use the Icon Editor tools to perform the following tasks:

The menu bar in the Icon Editor dialog box contains more editing options under the Edit menu such as Undo, Redo, Cut, Copy, Paste, and Clear.

Develop a simple icon for the subVI created:1.  If the subVI is not open, double-click the placed icon on the block diagram.

2.  From the front panel or block diagram of the subVI, double-click the icon in the upper right-hand corner.

Page 56: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

3.  Double-click the filled rectangle tool, , to create a blank icon with a border.

 

4.  Draw the icon you want to represent your subVI using the tools on the left.

 

5.  Select the 16 colors icon on the right and click the 256 Colors button under Copy from. Repeat for the B & W icon.

 

6.  Click OK to save the icon.

Building the Connector PaneYou need to build a connector pane, shown as follows, to use the VI as a subVI. The connector pane is a visual representation of how inputs and outputs are connected to the subVI from the calling VI.

Setting Up the Connector PaneDefine connections by assigning a front panel control or indicator to each of the connector pane terminals.

1.  Right-click the icon in the upper right corner of the front panel.

Page 57: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2.  Select Show Connector.

3.  You can select a different pattern by right-clicking the connector pane and selecting Patterns.

Each rectangle on the connector pane represents a terminal. Use the rectangles to assign inputs and outputs.

The following front panel has four controls and one indicator, so LabVIEW displays four input terminals and one output terminal on the connector pane.

 

 

Assigning Terminals to Controls and IndicatorsAfter you select a pattern to use for the connector pane, you must assign a front panel control or indicator to each of the connector pane terminals. It is generally good programming practice to organize the inputs to a subVI on the left and the outputs on the right.

To assign a terminal to a front panel control or indicator:

1.      Click a terminal of the connector pane.

2.      Click the front panel control or indicator you want to assign to that terminal.

Page 58: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Note that the terminal color changes to that of the data type to which you have connected it. You also can select the control or indicator first and then select the terminal.

3.      Click an open space on the front panel to deselect the control.

4.      Repeat these steps for all the controls and indicators that you will use to pass data to and from the calling VI.

Using SubVIsTo place a subVI on the block diagram:

1.  Click the Select a VI button on the Functions palette.

2.  Navigate to the VI.

3.  Double-click to place it on the block diagram.

Opening and Editing SubVIsTo open the front panel of a subVI from the calling VI, double-click the subVI on the block diagram. To display the block diagram of a subVI from the calling VI, press the <Ctrl>key and double-click the subVI on the block diagram.

You can edit and save a subVI, and the changes affect all calls to the subVI, not just the current instance.

Setting Required, Recommended, and Optional Inputs and OutputsIn the Context Help window, the labels of required terminals appear bold, recommended terminals appear as plain text, and optional terminals appear dimmed. The labels of optional terminals do not appear if you click the Hide Optional Terminals and Full Path button in theContext Help window. Output terminals cannot be set as Required.

To designate which inputs and outputs are required, recommended, and optional:

1.  Right-click a terminal in the connector pane.

Page 59: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2.  Select This Connection Is from the shortcut menu.

3.  Select Required, Recommended, or Optional.

You also can select Tools»Options»Front Panel and put a checkmark in the Connector pane terminals default to required checkbox. This option sets terminals on the connector pane toRequired instead of Recommended. This applies to connections made using the wiring tool and to subVIs created using Create SubVI.

Inputs and outputs of VIs in vi.lib are already marked as Required, Recommended, or Optional. LabVIEW sets the inputs and outputs of the VIs you create to Recommended by default. Set a terminal setting to Required only if the VI must have the input or output to run properly

Page 60: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Module Exercise

This exercise will go over dataflow within a VI. You will then go over debugging techniques and lastly how to turn your program into a subVI that you can use in alternate programs.

GoalUnderstand the basic behavior of data flow and debugging in the LabVIEW environment. Modular programming using SubVIs is also explored.

DescriptionThis exercise consists of a series of tasks in which will walk you through how data is passed from one element to another in the LabVIEW environment as well as how to debug using highlighted execution. Users will also learn how to create a SubVI for modular programming.

Data Flow, Debugging, and SubVIs1. Launch LabVIEW and open a blank VI.

❑ Select File»New VI

2. Open the front panel.

3. Place a numeric control on the front panel.

❑ Select and place Modern»Numeric»Numeric Control on the front panel.❑ Double click the number box of the numeric control and give it a value of 5.❑ Right click the numeric control and navigate to Data Operation»Make Current Value Default.

4. Place a numeric control on the front panel.

❑ Select and place Modern»Numeric»Numeric Control on the front panel underneath theNumeric control.❑ Double click the number box of the numeric control and give it a value of 10.❑ Right click the numeric control and navigate to Data Operation»Make Current Value Default.

5. Place a numeric control on the front panel.

❑ Select and place Modern»Numeric»Numeric Control on the front panel underneath theNumer 2 control.❑ Double click the number box of the numeric control and give it a value of 8.❑ Right click the numeric control and navigate to Data Operation»Make Current Value Default.

6. Place a numeric indicator to the right of the numeric controls and name it “Result”.

❑ Select and place Modern»Numeric»Numeric Indicator on the front panel to the right of the numeric controls.❑ Right click the numeric control and navigate to Data Operation»Make Current Value Default.

Page 61: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

6. Switch to the block diagram.

❑ Select Window»Show Block Diagram.

7. Place an “Add” function

❑ Select and place Programming»Numeric»Add from the functions palette on the Block Diagram.

8. Place an “Add” function

❑ Select and place Programming»Numeric»Subtract from the functions palette on the Block Diagram.

9. Wire the block diagram as seen below.

❑ Wire the output of the Numeric control to the first input of the Add function.❑ Wire the output of the Numeric 2 control to the second input of the Add function.❑ Wire the output of the Add function to the first input of the Subtract function.❑ Wire the output of the Numeric 3 control to the second input of the Subtract function.❑ Wire the output of the Subtract function to the input of the Result indicator

10. Enable Highlight Execution by clicking the light bulb in the block diagram’s tool bar.

Page 62: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

11. Run the VI by clicking the Run button on the block diagram.

12. Observe how the program executes and the sequential steps taken during the execution. Take note how intermediary values are also shown.

13. Save the VI as "add_subtract.vi".

14. Open the front panel.

15. Create a custom icon.

❑ Double click the VI icon in the upper right corner to open the icon editor.

❑ In the icon editor that opens, use the paint tools to create your own icon or the one below.

Page 63: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ When done click OK.

15. Configure the connector pane. 

❑ Right click the VI icon in the upper right corner and select Show Connector.

❑ Click the upper left terminal of the connector pane.

❑ Click on the Numeric control on the front panel. This links the terminal with this control.❑ Click the next terminal of the connector pane.

❑ Click on the Numeric 2 control on the front panel. This links the terminal with this control.❑ Click the next terminal of the connector pane.

❑ Click on the Numeric 3 control on the front panel. This links the terminal with this control.❑ Click the terminal in the upper right of the connector pane.

Page 64: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Click on the Result indicator on the front panel. This links the terminal with this indicator.

15. Save the VI.

16. Create a blank VI.

❑ Select File»New VI.

17. Switch to the block diagram.

❑ Select Window»Show Block Diagram.

18. Add the previously created add_subtract.vi VI to the block diagram.

❑ From the functions palette navigate to and select Select a VI...

Page 65: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Navigate to where you saved add_subtract.vi. Select this VI and press OK.

Page 66: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Place the VI on the front panel. Notice how the inputs and outputs correspond to those defined in the previous section.

19. Create constants for the input of the add_subtract VI.

❑ Right click the Numeric input of the add_subtract VI and select Create»Constant. Give this constant a value of 10.❑ Right click the Numeric 2 input of the add_subtract VI and select Create»Constant. Give this constant a value of 20.❑ Right click the Numeric 3 input of the add_subtract VI and select Create»Constant. Give this constant a value of 30.

20. Create an indicator for the output of the add_subtract VI.

❑ Right click the Result output of the add_subtract VI and select Create»Indicator.

Page 67: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

21. Switch to the front panel.

❑ Select Window»Show Front Panel.

22. Run the VI. Observe how the add_subtract VI behaves just as the VI that was created earlier in this exercise.

23. Close both VIs. Save if desired.

End of Exercise

Page 68: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Module 3: Loops - Developer Zone - National Instruments (16 March 2011 12:06 AM)

Module 3: Loops

For Loops and While Loops

This tutorial explores some of the basic functions and uses of For Loops and While Loops. You will learn how to create For Loops and While Loops and when the appropriate time would be to use them in your program.

A while loop is a control flow statement you use to execute a block of the subdiagram code repeatedly until a given Boolean condition is met. First, you execute the code within the subdiagram, and then the conditional terminal is evaluated. Unlike a for loop, a while loop does not have a set iteration count; thus, a while loop executes indefinitely if the condition never occurs.

 

A for loop is a control flow statement you use to execute a block of the subdiagram code a set number of times, but a while loop stops executing the subdiagram only if the value at the conditional terminal exists.

 

Building a While Loop1. Open a new VI. You can open a blank VI by selecting File»New VI

2. If the Functions palette is not visible, right-click any blank space on the block diagram to display a temporary version of the palette. Click the thumbtack in the upper left corner of the Functions palette to pin the palette so it is no longer temporary.

3. Select the while loop from the Structures palette under the Functions palette.

 

4. Use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat.

5. When you release the mouse button, a while loop boundary encloses the section you have selected.

6. Place a Stop button on the front panel. You can find this under Controls Palette»Boolean»Stop.

7. Add the Stop button from the block diagram to the while loop by dragging and dropping it inside the while loop.

8. The conditional terminal, shown below, defines when the loop stops. There are two settings for the conditional terminal: Continue if True and Stop if True. When set to Continue if True, the while loop runs only if a Boolean value of true is sent to the terminal. If the conditional terminal is set to Stop if True, and a Boolean value of true is sent to the conditional terminal, the loop halts execution.

Stop if True

Continue if True

9. To switch the conditional terminal between Continue if True and Stop if True, right-click on the conditional terminal and check the corresponding setting.

Page 69: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

10. Wire the Stop button to the conditional terminal so that you can control the execution of the while loop. When the Stop button is pressed, a true value is passed to the conditional terminal causing the while loop to stop execution. You can wire any Boolean data to the conditional terminal to control the execution of a while loop.

11. The iteration terminal is an output terminal that contains the number of completed iterations. The iteration count always starts at zero. During the first iteration, the iteration terminal returns 0.

12. You have just created a simple while loop that generates random numbers and displays them until the Stop button is pressed.

Structure TunnelsUse structure tunnels to feed data into and out of structures like the while loop. If you want to send data into your while loop, you need to create structure tunnels. Data sent into the While Loop is sent only on the first iteration, and data sent out of the while loop is sent only after the last iteration. Now create a structure tunnel to display the number of iterations executed.

1. Create a numeric indicator on the front panel.

2. Drag a data wire from the iteration counter into the border of the while loop to create a structure tunnel.

3. The tunnel appears as a solid block on the border of the while loop. The block is the color of the data type wired to the tunnel. Data pass out of a loop after the loop terminates. When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel.

4. Drag a data wire from the structure tunnel into the numeric indicator to pass the number of iterations to your display.

5. In the following block diagram, the iteration terminal is connected to a tunnel. The value in the tunnel does not get passed to the iteration indicator until the while loop finishes executing.

 

Manipulating the Conditional TerminalBy using Boolean functions, you can implement multiple conditions to affect your while loop conditional terminal. You can use an “or” function to compare an error wire status and a Stop button control so that if either is TRUE, the conditional terminal receives a TRUE signal, and the while loop stops.

1. Create a while loop as outlined previously.

2. Place an Error In 3D.ctl control on the front panel. You can find this under Controls Palette»Array, Matrix & Cluster»Error In 3D.ctl.

3. Remove the connection wire between the Stop button and the conditional terminal.

4. Make sure the Error In 3D.ctl is outside of the while loop.

5. Place a Simple Error Handler outside of the while loop. You can find this under Functions Palette»Dialog & User Interface»Simple Error Handler.vi. This function reports any errors encountered when called.

Page 70: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

6. Link the error in control with the Simple Error Handler through the while loop via structure tunnels. Drag a wire from the output of the error in control to the border of the while loop, and then drag the error wire from the tunnel created to the opposite border of the while loop and into the input of the Simple Error Handler.

7. Place an Unbundle By Name function inside of the while loop. You can find this under Functions Palette»Programming»Cluster, Class, & Variant. This function separates the Boolean portion of the error data wire.

Page 71: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

8. Place an “or” function inside of the while loop. You can find this under Functions Palette»Programming»Boolean.

9. Link the data wires as shown below. This simple VI stops execution of the while loop if either the Stop button is pressed or an error is detected inside of the while loop.

Building a For Loop1. Open a new VI. You can open a blank VI by selecting File»New VI.

2. If the Functions palette is not visible, right-click any blank space on the block diagram to display a temporary version of the Functions palette. Click the thumbtack in the upper left corner of the Functions palette to pin the palette so it is no longer temporary.

3. Select the for loop from the Structures palette under the Functions palette.

Page 72: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

4. You also can place a while loop on the block diagram. Right-click the border of the while loop and select Replace with For Loop from the shortcut menu to change a while loop to a for loop.

5. A for loop contains a count terminal. The count terminal dictates how many times the subdiagram is executed.

6. Right-click on the count terminal and Create Constant to link the count terminal with a numeric value.

Page 73: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

7. By inserting 100 into the numeric constant, the for loop executes 100 times before stopping.

8. The iteration terminal, shown as follows, is an output terminal that contains the number of completed iterations. The example below would update an indicator on the front panel with the current iteration number.

Adding a Conditional Terminal to a For LoopIf necessary, you can add a conditional terminal to configure a for loop to stop when a Boolean condition or an error occurs.1. Right-click on the edge of the for loop and select Conditional Terminal.

2. A for loop with a conditional terminal executes until the condition occurs or until all iterations are complete, whichever happens first.

3. For loops you configure for a conditional exit have a red glyph in the count terminal as well as a conditional terminal in the lower right corner.

4. After you configure the for loop to exit conditionally, the loop appears similar to the figure below. The following for loop generates a random number every second until 100 seconds has passed or the user clicks the Stop button.

Page 74: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

For more information on the uses of for loops and while loops, refer to the Context Help. You can access Context Help from Help»Show Context Help or using the shortcut <Ctrl-H>.

Module Exercise

This exercise will show you the differences between while loops and for loops. You will go through the steps in creating each type of loop and how to use them.

GoalUnderstand the basic behavior of For and While loops in LabVIEW.

DescriptionThis exercise consists of a series of tasks in which will walk you through how to use For and While loops effectively in LabVIEW.

While LoopsGoalUse a While Loop and an iteration terminal and pass data through a tunnel.

ScenarioCreate a VI that continuously generates random numbers between 0 and 1000 until it generates a number that matches a number selected by the user. Determine how many random numbers the VI generated before the matching number.

Design

Type Name Properties

Input Number to Match Double-precision,  floating-point between 0 and 1000, coerce to nearest whole number, default value = 50

Output Current Number Double-precision, floating-point

Output Number of Iterations Integer

 

ImplementationOpen a blank VI and build the following front panel. Modify the controls and indicators as shown in the following front panel and as described in the following steps.

Page 75: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

1. Open a blank VI.

❑ Select File»New VI

2. Save the VI as Auto Match.vi.

3. Create the Number to Match input.

❑ Add a numeric control to the front panel window.

❑ Label the control Number to Match.

4. Set the properties for the Number to Match control so that the default value is 50, the data range is from 0 to 1000, the increment value is 1, and the digits of precision is 0.

❑ Right-click the Number to Match control and select Data Entry from the shortcut menu. The Data Entry page of the Numeric Properties dialog box appears.

❑ Set the Default Value to 50.

❑ Set the Minimum value to 0 and select Coerce from the Response to value outside limits pull-down menu.

❑ Set the Maximum value to 1000 and select Coerce from the Response to value outside limits pull-down menu.

❑ Set the Increment value to 1 and select Coerce to Nearest from the Response to value outside limits pull-down menu.

❑ Select the Display Format tab.

❑ Select Floating Point and change Precision Type from Significant digits to Digits of precision.

❑ Enter 0 in the Digits text box and click OK.

5. Create the Current Number output.

❑ Add a numeric indicator to the front panel window.

❑ Label the indicator Current Number.

❑ Right-click the indicator and select Advanced»Synchronous Display.

6. Set the digits of precision for the Current Number output to 0.

❑ Right-click the Current Number indicator and select Display Format from the shortcut menu. The Display Format page of the Numeric Properties dialog box appears.

Page 76: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Select Floating Point and change Precision Type to Digits of precision.

❑ Enter 0 in the Digits text box and click OK.

7. Create the # of iterations output.

❑ Place a numeric indicator on the front panel.

❑ Label the indicator # of iterations.

8. Set the representation for the # of iterations output to a long integer.

❑ Right-click the # of iterations indicator.

❑ Select Representation»I32 from the shortcut menu.

 

Create the following block diagram. Refer to the following steps for instructions.

9. Generate a random number integer between 0 and 1000.

❑ Add the Random Number (0-1) function to the block diagram. The Random Number (0-1) function generates a random number between 0 and 1.

❑ Add the Multiply function to the block diagram. The Multiply function multiplies the random number by the y input to produce a random number between 0 and y.

❑ Wire the output of the Random Number function to the x input of the Multiply function.

❑ Right-click the y input of the Multiply function, select Create»Constant from the shortcut menu, enter 1000, and press the <Enter> key to create a numeric constant.

❑ Wire the output of the Multiply function to the input of the Round To Nearest function.

❑ Add the Round To Nearest function to the block diagram. This function rounds the random number to the nearest integer.

❑ Wire the output of the Round To Nearest function to the Current Number indicator.

10. Compare the randomly generated number to the value in the Number to Match control.

Page 77: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Add the Not Equal? function to the block diagram. This function compares the random number with Number to Match and returns True if the numbers are not equal; otherwise, it returns False.

❑ Wire the output of the Round To Nearest function to the x input of the Not Equal? function.

❑ Wire the Number to Match numeric control to the y input of the Not Equal? function.

❑ Wire the output of the Not Equal? function to the conditional terminal.

11. Repeat the algorithm until the Not Equal? function returns True.

❑ Add a While Loop from the Structures palette to the block diagram.

❑ Right-click the conditional terminal and select Continue if True from the shortcut menu.

12. Display the number of random numbers generated to the user by adding one to the iteration terminal value.

❑ Wire the iteration terminal to the border of the While Loop. A blue tunnel appears on the While Loop border.

Tip: Each time the loop executes, the iteration terminal increments by one. Wire the iteration value to the Increment function because the iteration count starts at 0. The iteration count passes out of the loop upon completion.

❑ Add the Increment function to the block diagram. This function adds 1 to the While Loop count.

13. Save the VI.

Test1. Display the front panel.

2. Change the number in Number to Match to a number that is in the data range, which is 0 to 1000 with an increment of 1.

3. Run the VI.

4. Change Number to Match and run the VI again. Current Number updates at every iteration of the loop because it is inside the loop. # of iterations updates upon completion because it is outside the loop.

5. To see how the VI updates the indicators, enable execution highlighting.

❑ On the block diagram toolbar, click the Highlight Execution button to enable execution highlighting. Execution highlighting shows the movement of data on the block diagram from one node to another so you can see each number as the VI generates it.

6. Run the VI and observe the data flow.

7. Try to match a number that is outside the data range.

8. Change Number to Match to a number that is out of the data range.

❑ Run the VI. LabVIEW coerces the out-of-range value to the nearest value in the specified data range.

9. Close the VI.

For LoopsImplementation1. Open a blank VI.

❑ Select File»New VI

Page 78: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2. Switch to the block diagram.

❑ Select Window»Show Block Diagram.

3. In the block diagram place a For Loop.

❑ From the functions palette navigate and select Programming»Structures»For Loop.❑ Place the For Loop on the block diagram by clicking and dragging the mouse on the block diagram to form a square shape.

 

4. Set the number of iterations of the loop. 

❑ Right click the input of the Loop Count terminal of the For Loop and selectCreate»Constant.❑ Give this constant a value of 10.

 

Page 79: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

5. Place a Subtract function on the block diagram.

❑ From the functions palette navigate and select Programming»Numeric»Subtract.❑ Place the Subtract function inside the for loop.

6. Create a constant on the input of the Subtract function.

❑ Right click the first input of the Subtract function and select Create»Constant.❑ Give this constant a value of 10.

6. Create an indicator on the output of the Subtract function.

❑ Right click the first input of the Subtract function and select Create»Indicator.

8. Wire the Loop Iteration output of the For Loop to the second input of the Subtract function.

9. Add a Wait function to the block diagram.

❑ Select Programming»Timing»Wait from the functions palette and place it inside the for loop.❑ Right click the  input of the Wait function and select Create»Constant.❑ Give this constant a value of 1000.

10. Switch to the Front Panel.

❑ Select Window»Show Block Diagram.

11. Run the VI. Observe how the program counts down from 10 to 1 for each iteration of the For Loop.

13. Close the VI.

Page 80: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

End Of Exercise

Page 81: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Module 4: Timing, Structures, and Storing Data - Developer Zone - National Instruments (16 March 2011 12:09 AM)

Module 4: Timing, Structures, and Storing Data

Tutorial: Timing, Shift Registers, and Case Structures

Normally when a loop, such as a while loop, finishes executing one iteration, it immediately begins running the next. It is often beneficial to control how often a loop executes, or its frequency. For example, if you wanted to acquire data in a loop, you would need a method to control the frequency of the data acquisition. Timing a loop also allows the processor time to complete other tasks such as updating and responding to the user interface. In the following figures, the processor usage for a simple VI with a while loop running untimed and timed are shown. Timing a loop can drastically increase performance.Untimed LoopTimed Loop Executing at 1000 Times a Second

Wait FunctionsAfter you create a loop, you can place a wait VI inside of the loop to control how long it waits before performing the next iteration.

There are two basic wait functions in LabVIEW: Wait (ms) and Wait Until Next ms Multiple.                

The Wait (ms) function forces the loop to wait for a user-specified amount of time, in milliseconds, before running the next iteration.

The Wait Until Next ms Multiple function watches the millisecond counter and waits for it to reach a multiple of the user-specified time, in milliseconds, before running the next iteration of the loop. You can use this VI to synchronize different activities. For example, you can configure multiple loops to execute at each multiple of 200 ms.

Tutorial: Implementing a Wait Function in a LoopConsider using one of the wait functions in a while loop. Using the information from previous tutorials, create a blank VI in LabVIEW.

1.       Place a knob numeric control on the front panel by right-clicking on the front panel and navigating to Controls»Modern»Numeric»Knob.

2.       Change the knob’s limits to 1 and 1000 by double-clicking on the knob’s current limits and entering the new values. You will use the knob to control a while loop’s wait time. 

3.       Place a numeric indicator on the front panel by right-clicking on the front panel and navigating to Controls»Modern»Numeric»Numeric Indicator.

4.       This indicator displays the while loop iterations.

 

5.       Change the Representation of the numeric indicator to I-32 (long integer) by right-clicking on the indicator and selecting Representation. Click on I32.

Page 82: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

6.       Place a Stop Boolean control on the front panel. You can find this atControls»Modern»Boolean»Stop Button. Use this Stop button to stop the while loop.

7.       Double-click the name of the knob and change its name to “Wait Time (ms).”         

8.       Double-click the name of the numeric indicator and change its name to “Iteration.” 

9.       View the block diagram by selecting Window»Show Block Diagram or pressing <ctr-E>.

10.   On the block diagram, drag a while loop around the front panel controls and indicator. Find the while loop at Functions»Programming»Structures»While loop.

 

After selecting the while loop, drag it around the three icons. If you miss one icon, just click and drag it into the loop.

11.   Wire the Stop control to the while loop’s stop conditional terminal. Click on the right terminal of the Stop button’s icon, drag to the left input terminal of the stop conditional terminal, and click to complete the wire.

12.   Wire the numeric indicator to the while loop iteration terminal. 

13.   Right-click on the block diagram to open the Functions palette and then navigate to and open the Timing palette, which is located at Functions»Programming»Timing.

Page 83: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

14.   Place the Wait (ms) function, located in the Timing palette, inside the while loop.

15.   Wire the knob control Wait Time (ms) to the input of the Wait (ms) function. The knob value specifies how long, in milliseconds, the loop waits before running the next iteration.

Page 84: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

16.   View the block diagram by selecting Window»Show Front Panel or pressing <ctr-E>.

17.   Run the VI.

18.   As the VI runs, change the knob value by clicking and dragging the knob; note that the speed of the loop, as shown by the iteration indicator, changes accordingly.

19.   Stop the VI using the Stop Boolean control.

Iterative Data TransferWhen programming with loops, sometimes you need to call data from previous iterations of the loop. In LabVIEW, you can use shift registers, which are similar to static variables in text-based programming languages, to pass values from one loop iteration to the next.

Page 85: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Data enters the right shift register and is passed to the left shift register on the next iteration of the loop.

Tutorial: Using Shift RegistersThe next section of this tutorial guides you through creating and using shift registers in a simple LabVIEW VI.

1.       Create a new LabVIEW VI by navigating to File»New VI.

2.       Place a numeric control on the front panel and change its value to 2.

3.       Double-click on the control’s name and change it to “Initial.”

 

4.       Place a numeric indicator on the front panel and name it “Result.”

5.       View the block diagram by selecting Window»Show Block Diagram or pressing <ctr-E>.

6.       Place a for loop on the block diagram between the numeric control and indicator. The for loop is located at Functions»Programming»Structures»For Loop.

Page 86: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

7.       Right-click on the input of the count terminal of the for loop and select Create Constant. Change the value of this constant to 2.

8.       Wire the output of the Initial control to the right edge of the for loop to create a tunnel.

9.       Right-click on the tunnel that you just created and select Replace with Shift Register.

10.   Wire the output of the right shift register to the Result indicator.

11.   Place a multiply function in the for loop.

Page 87: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

12.   Place a numeric constant in the for loop, assign it a value of 3, and connect it to one of the input terminals of the multiply function.

13.   Wire the left shift register to the remaining input of the multiply function, and wire the output of the function to the right shift register.

14.   View the block diagram by selecting Window»Show Front Panel or pressing <ctr-E>.

15.   Run the VI. The VI changes the value of the Result indicator to 18.

ExplanationShift registers are integral to this VI. To understand how the VI works, you can step through the code.

Because the for loop’s counter terminal is wired to a constant of 2, it runs twice. On the first iteration of the for loop, the value of Initial, 2, is multiplied by 3. The result is 6, and this value is passed to the right shift register. On the second iteration of the for loop, the left shift register receives the value that was sent to the right shift register on the previous iteration, 6. The value of 6 is multiplied by 3, for a result of 18. Because the for loop completed all of its iterations, it stops running and the value of 18 is sent to the Result indicator on the front panel.

The mathematical formula for this simple VI looks like this:

Result = ( ( Initial * 3 ) * 3 )

If you changed the value of the for loop’s count terminal to 4, the mathematical formula looks like this:

Result = ( ( ( ( Initial * 3 ) * 3 ) * 3 ) * 3 )

Case StructuresWhen programming in LabVIEW, you may want to choose between multiple sections of code based on an input. Based on the input it receives on the case selector terminal, the case structure chooses which “case,” or section of code, to execute. The case selector terminal appears as a small question mark (?) on the left side of the case structure.

Page 88: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

If you change the input to the case selector terminal, the section of code that is executed changes. In the figures below, the case structure executes different code for the input strings “True” and “False.”

                     

Selector TerminalThe case selector terminal can receive multiple data types. You can use the following data types as inputs to the case selector terminal:

•          Integers

•          Boolean values

•          Strings

•          Enumerated type values (Enums)

A case structure with a Boolean wired to its selector terminal has a maximum of two cases; all other data types allow two or more cases.

Tutorial: Programming with a Case StructureThe following tutorial demonstrates how you can use a case structure to choose between multiple sections of code.

1.       Create a new LabVIEW VI by navigating to File»New VI.

2.       Place two numeric controls and a numeric indicator on the front panel. Name the numeric controls “Input A” and “Input B.” Name the indicator “Result.”

Page 89: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3.       Place an Enum control on the front panel. This control is located in Controls»Modern»Ring & Enum. Rename the control “Operation.”

4.       Right-click on the Enum and select Edit Items… to open the Enum Properties.

Page 90: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

5.       Click the Insert button and add the following Items: Add, Subtract, Multiply, and Divide.

6.       Click the OK button at the bottom of the Enum Properties box to close it.

Your front panel should look similar to the following figure.

Page 91: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

7.       View the block diagram by selecting Window»Show Block Diagram or pressing <Ctrl-E>.

8.       Place a case structure on the block diagram, between your controls and indicator. Find the case structure at Functions»Programming»Structures.

9.       Wire the Operation Enum control to the case structure’s selector terminal, located on the left side of the case structure.

10.   Right-click on the border of the case structure and select Add Case for Every Value. The case structure now has a case for every value of the Enum that is wired to the case selector terminal. This tutorial demonstrates four cases: Add, Subtract, Multiply, and Divide.

Page 92: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

11.   Switch to the “Add” case of the case selector terminal by clicking the right or left arrows at the top of the case structure, or by placing your mouse inside the case structure and pressing <ctr>while scrolling with the mouse.

12.   Place the add function in the Case Statement when the “Add” case is selected.

13.   Wire the controls Input A and Input B to the inputs of the add function. Wire the output of the add function to the Result indicator. You can wire through the case structure, which acts much like a loop and creates tunnels automatically.

14.   Switch to the “Subtract” case of the case selector terminal by clicking the right or left arrows at the top of the case structure, or by placing your mouse inside the case structure and pressing <ctr> while scrolling with the mouse.

15.   Add the subtract function to the “Subtract” case. Wire the function to the controls and indicators in the same way you wired the add function.

16.   Add the multiply function to the “Multiply” case and the divide function to the “Divide” case. Wire these functions to the controls and indicators in the same way you wired the add and subtract functions. Your case structure should now contain four cases similar to the following:

Page 93: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

     

17.   When you have successfully wired all the outputs, the tunnel to the Result indicator changes from a hollow square to a filled square, as shown in the following figures.

                 

18.   View the block diagram by selecting Window»Show Front Panel or pressing <Ctrl-E>.

19.   Change the value of Input A to 1 and the value of Input B to 2.

20.   Change the value of the Operation Enum to “Add.”

21.   Run the VI, which changes the value of the Result indicator to 3.

22.   Experiment with different values of the Operation Enum and run the VI again

Understand the basic behavior and operation of case structures, shift registers, and timing functions in the LabVIEW environment.

Description

Page 94: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

This exercise consists of a series of tasks in which will walk you through how shift registers can be used to retain data between iterations of loops. The use of case structures to control the flow of a program will also be explored in detail. Timing functions will be explained and a simple implementation will be shown.

Timing VI1. Launch LabVIEW and open a blank VI.

❑ Select File»New VI.

2. Open the block diagram of the VI.

❑ Select Window»Show Block Diagram.

3. Place a While Loop on the block diagram.

❑ Select Programming»Structures»While Loop from the functions palette.❑ Place the While Loop on the block diagram by clicking and holding on the block diagram and then dragging the mouse to form a square shape.

4. Create a Stop control for the While Loop. 

❑ Right click the input of the Loop Condition terminal of the While Loop and selectCreate»Control.

5. Place a Random Number (0-1) function on the block diagram. 

❑ From the Functions palette select Programming»Numeric»Random Number (0-1) and place it inside the while loop.

6. Place a Multiply function on the block diagram. 

❑ From the Functions palette select Programming»Numeric»Multiply and place it inside the while loop.

❑ Right click the first input of the Multiply function and select Create»Constant.❑ Give this constant a value of 100.❑ Right-click the output of the multiply function and select Create»Indicator.

7. Wire the output of the Random Number function to the second input of the Multiply function.

8. Place a Wait function on the block diagram.

❑ Select Programming»Timing»Wait from the functions palette and place it on the block diagram inside of the while loop.

Page 95: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Right click the milliseconds to wait input of the Wait function and select Create»Constant.❑ Set the value of the constant to 1000.

9. Switch to the front panel of the VI.

❑ Select Window»Show Front Panel.

10. Run the VI. Observe how a random number between zero and a hundred is generated every second.

11. Click the STOP button on the front panel.

12. Close the VI

Shift Registers1. Launch LabVIEW and open a blank VI.

❑ Select File»New VI.

2. Open the block diagram of the VI.

❑ Select Window»Show Block Diagram.

3. Place a While Loop on the block diagram.

❑ Select Programming»Structures»While Loop from the functions palette.❑ Place the While Loop on the block diagram by clicking and holding on the block diagram and then dragging the mouse to form a square shape.

4. Create a shift register on the while loop.

❑ Right click on the left border of the While Loop and select Add Shift Register.

5. Place a numeric constant on the block diagram.

❑ Select Programming»Numeric»Numeric Constant and place it on the block diagram inside the for loop.❑ Give the constant a value of 100.❑ Connect constant to the input of the shift register.[+] Enlarge Image

6. Place an Increment function on the block diagram. 

❑ From the Functions palette select Programming»Numeric»Increment and place it inside the while loop.

7. Place a Greater? function on the block diagram. 

❑ From the Functions palette select Programming»Comparison»Greater? and place it inside the while loop.❑ Right click the y input of the Greater? function and select Create»Constant.❑ Give this constant a value of 9000.

8. Place a Select function on the block diagram. 

❑ From the Functions palette select Programming»Comparison»Select and place it inside the while loop.[+] Enlarge Image

❑ Right click the output of the Select function and select Create»Indicator.

9. Create a String Constant.

Page 96: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Select  Programming»String»String Constant from the Functions palette and place it inside the while loop.❑ Give this constant a value of “Over 9000!”❑ Wire this constant to the t input of the Select function.

10. Create a String Constant.

❑ Select  Programming»String»String Constant from the Functions palette and place it inside the while loop.❑ Give this constant a value of “Under 9000!”❑ Wire this constant to the f input of the Select function.

11. Place a Wait function on the block diagram.

❑ Select Programming»Timing»Wait from the functions palette and place it on the block diagram inside of the while loop.❑ Right click the milliseconds to wait input of the Wait function and select Create»Constant.❑ Set the value of the constant to 1.

12. Wire the block diagram as shown below.

❑ Wire the output of the shift register on the left side of the while loop to the input of theIncrement function❑ Wire the output of the Increment function to the input of the shift register on the right side of the loop.❑ Wire the output of the Increment function to the x input of the Greater? function.❑ Wire the output of the Greater? function to the s input of the Select function.❑ Wire the output of the Greater? function to the Loop Condition input of the while loop.[+] Enlarge Image

13. Switch to the front panel.

❑ Select Window»Show Front Panel.

14. Run the VI. Notice how the shift register always retains the value from the previous iteration of the loop. When the value reaches over 9000, a warning is displayed and the VI halts.

15. Close the VI.

Case StructuresInputs and Outputs

Type Name Properties

Input Number Double-precision, floating point; default value of 25

Output Square Root Value Double-precision, floating

point

 

Implementation

1. Open a blank VI and build the front panel shown in the figure below.

2. Add a numeric control to the front panel window.

❑ Name the numeric control Number.

Page 97: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3. Add a numeric indicator to the front panel window.

❑ Rename the numeric indicator Square Root Value.

Build the block diagram shown in the figure below.

4. Determine whether Number is greater than or equal to zero, because you cannot calculate the square root of a negative number.

❑ Add the Greater or Equal to 0? function to the right of the Number control. This function returns True if Number is greater than or equal to 0.

❑ Wire Number to the input of the Greater or Equal to 0? function.

5. If Number is less than 0, display a dialog box that informs the user of the error.

❑ Add the Case structure to the block diagram.

❑ Click the decrement or increment button to select the False case.

❑ Add a numeric constant to the False case.

❑ Right-click the numeric constant and select Representation»DBL.

❑ Enter -99999 in the numeric constant.

❑ Wire the numeric constant to the right edge of the Case structure.

❑ Wire the new tunnel to the Square Root Value indicator.

❑ Add the One Button Dialog function to the False case. This function displays a dialog box that contains a message you specify.

❑ Right-click the message input of the One Button Dialog function and selectCreate»Constant from the shortcut menu.

❑ Enter "Error...Negative Number" in the constant.

❑ Finish wiring the False case as shown in the above figure.

6. If Number is greater than or equal to 0, calculate the square root of the number.

❑ Select the True case of the Case structure.

❑ Place the Square Root function in the True case. This function returns the square root of Number.

❑ Wire the function as shown in the figure below.

7. Save the VI as Square Root.vi.

Test1. Display the front panel.

2. Enter a positive number in the Number control.

3. Run the VI.

4. Enter a negative number in the Number control.

Page 98: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Caution: Do not run this VI continuously. Under certain circumstances, continuously running this VI could result in an endless loop.

5. Run the VI.

If Number is positive, the VI executes the True case and returns the square root of Number. If Number is negative, the VI executes the False case, returns –99999, and displays a dialog box with the message Error...Negative Number.

6. Close the VI.

End of Exercis

Source: Module 5: Arrays, Clusters, and Text Based Nodes - Developer Zone - National Instruments (16 March 2011 12:11 AM)

Page 99: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Module 5: Arrays, Clusters, and Text Based Nodes

Array and Cluster Functions

This tutorial examines array and cluster data types and gives you an introduction to creating and manipulating arrays and clusters.

An array, which consists of elements and dimensions, is either a control or an indicator – it cannot contain a mixture of controls and indicators. Elements are the data or values contained in the array. A dimension is the length, height, or depth of an array. Arrays are very helpful when you are working with a collection of similar data and when you want to store a history of repetitive computations.

Array elements are ordered. Each element in an array has a corresponding index value, and you can use the array index to access a specific element in that array. In NI LabVIEW software, the array index is zero-based. This means that if a one-dimensional (1D) array contains n elements, the index range is from 0 to n – 1, where index 0 points to the first element in the array and index n – 1 points to the last element in the array.

Clusters group data elements of mixed types. An example of a cluster is the LabVIEW error cluster, which combines a Boolean value, a numeric value, and a string. A cluster is similar to a record or a struct in text-based programming languages.

Similar to arrays, a cluster is either a control or an indicator and cannot contain a mixture of controls and indicators. The difference between clusters and arrays is that a particular cluster has a fixed size, where a particular array can vary in size. Also, a cluster can contain mixed data types, but an array can contain only one data type.

Creating Array Controls and IndicatorsTo create an array in LabVIEW, you must place an array shell on the front panel and then place an element, such as a numeric, Boolean, or waveform control or indicator, inside the array shell.

1.       Create a new VI.

2.       Right-click on the front panel to display the Controls palette.

3.       On the Controls palette, navigate to Modern»Array, Matrix, & Cluster and drag the Arrayshell onto the front panel.[+] Enlarge Image

4.       On the Controls palette, navigate to Modern»Numeric and drag and drop a numeric indicator inside the Array shell.

5.       Place your mouse over the array and drag the right side of the array to expand it and display multiple elements.

The previous steps walked you through creating a 1D array. A 2D array stores elements in a grid or matrix. Each element in a 2D array has two corresponding index values, a row index and a column index. Again, as with a 1D array, the row and column indices of a 2D array are zero-based.

 

To create a 2D array, you must first create a 1D array and then add a dimension to it. Return to the 1D array you created earlier.

1.       On the front panel, right-click the index display and select Add Dimension from the shortcut menu.

Page 100: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2.       Place your mouse over the array and drag the corner of the array to expand it and display multiple rows and columns.

Up to this point, the numeric elements of the arrays you have created have been dimmed zeros. A dimmed array element indicates that the element is uninitialized. To initialize an element, click inside the element and replace the dimmed 0 with a number of your choice.

You can initialize elements to whatever value you choose. They do not have to be the same values as those shown above.

Creating Array ConstantsYou can use array constants to store constant data or as a basis for comparison with another array.

1.       On the block diagram, right-click to display the Functions palette.

2.       On the Functions palette, navigate to Programming»Array and drag the Array Constantonto the block diagram.

3.       On the Functions palette, navigate to Programming»Numeric and drag and drop theNumeric Constant inside the Array Constant shell.

4.       Resize the array constant and initialize a few of the elements.

Array Inputs/OutputsIf you wire an array as an input to a for loop, LabVIEW provides the option to automatically set the count terminal of the for loop to the size of the array using the Auto-Indexing feature. You can enable or disable the Auto-Indexing option by right-clicking the loop tunnel wired to the array and selecting Enable Indexing (Disable Indexing).

If you enable Auto-Indexing, each iteration of the for loop is passed the corresponding element of the array.

When you wire a value as the output of a for loop, enabling Auto-Indexing outputs an array. The array is equal in size to the number of iterations executed by the for loop and contains the output values of the for loop.

1.       Create a new VI. Navigate to File»New VI.

2.       Create and initialize two 1D array constants, containing six numeric elements, on the block diagram similar to the array constants shown below.

3.       Create a 1D array of numeric indicators on the front panel. Change the numeric type to a 32-bit integer. Right-click on the array and select Representation»I32.

4.       Create a for loop on the block diagram and place an add function inside the for loop.

5.       Wire one of the array constants into the for loop and connect it to the x terminal of the add function.

6.       Wire the other array constant into the for loop and connect it to the y terminal of the add function.

7.       Wire the output terminal of the add function outside the for loop and connect it to the input terminal of the array of numeric indicators.

8.       Your final block diagram and front panel should be similar to those shown below.

  

Block Diagram

Front Panel

Page 101: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

9.       Go to the front panel and run the VI. Note that each element in the array of numeric indicators is populated with the sum of the corresponding elements in the two array constants.

Be aware that if you enable Auto-Indexing on more than one loop tunnel and wire the for loop count terminal, the number of iterations is equal to the smaller of the choices. For example, in the figure below, the for loop count terminal is set to run 15 iterations, Array 1 contains 10 elements, and Array 2 contains 20 elements. If you run the VI in the figure below, the for loop executes 10 times and Array Result contains 10 elements. Try this and see it for yourself.

You can create a 2D array using nested for loops and Auto-Indexing as shown below. The outer for loop creates the row elements, and the inner for loop creates the column elements.

Creating Clusters1.       Create a new VI.

2.       Right-click on the front panel to display the Controls palette.

3.       On the Controls palette, navigate to Modern»Array, Matrix, & Cluster and drag the Clustershell onto the front panel.

 

Page 102: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

[+] Enlarge Image

4.       Resize the Cluster shell so that it is big enough to contain multiple elements.

 

Page 103: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

5.       On the Controls palette, navigate to Modern»Numeric and drag and drop a numeric control inside the Cluster shell.

6.       On the Controls palette, navigate to Modern»String & Path and drag and drop a String Control inside the Cluster shell.

7.       On the Controls palette, navigate to Modern»Boolean and drag and drop a Vertical Toggle Switch inside the Cluster shell.

Page 104: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

8.       Your cluster should now look similar to the one shown below.

You can now wire the numeric, string, and Boolean controls throughout the block diagram with one wire rather than three separate wires.

Creating Cluster ConstantsSimilar to array constants, you can use cluster constants to store constant data or as a basis for comparison with another cluster. Create cluster constants the same way you created array constants in the steps discussed earlier.

Page 105: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

If you already have a cluster control or indicator and want to make a cluster constant that contains the same data types, make a copy of the cluster control or indicator on the block diagram and then right-click on the copy and select Change to Constant from the shortcut menu.

Page 106: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Cluster FunctionsThis tutorial examines four main cluster functions often used to manipulate clusters. These are the Bundle, Unbundle, Bundle By Name, and Unbundle By Name functions.

Use the Bundle function to assemble a cluster from individual elements. To wire elements into the Bundle function, use your mouse to resize the function or right-click on the function and selectAdd Input from the shortcut menu.

Use the Bundle By Name or the Bundle function to modify an existing cluster. You can resize theBundle By Name function in the same manner as the Bundle function.

Page 107: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

                                   

                               

The Bundle By Name function is very useful when modifying existing clusters because it lets you know exactly which cluster element you are modifying. For example, consider a cluster that contains two string elements labeled “String 1” and “String 2.” If you use the Bundle function to modify the cluster, the function terminals appear in the form of pink abc’s. You do not know which terminal modifies “String 1” and which terminal modifies “String 2.”

 

However, if you use the Bundle By Name function to modify the cluster, the function terminals display the element label so that you know which terminal modifies “String 1” and which terminal modifies “String 2.”

Page 108: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Use the Unbundle function to disassemble a cluster into its individual elements. Use theUnbundle by Name function to return specific cluster elements you specify by name. You can also resize these functions for multiple elements in the same manner as the Bundle and Bundle By Name functions.

[+] Enlarge Image

 

Cluster OrderCluster elements have a logical order unrelated to their position in the shell. The first object you place in the cluster is element 0, the second is element 1, and so on. If you delete an element, the order adjusts automatically. The cluster order determines the order in which the elements appear as terminals on the Bundle and Unbundle functions on the block diagram. You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Cluster from the shortcut menu.

Page 109: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The white box on each element shows its current place in the cluster order. The black box shows the element’s new place in the order. To set the order of a cluster element, enter the new order number in the Click to set to text box and click the element. The cluster order of the element changes, and the cluster order of other elements automatically adjusts. Save the changes by clicking the Confirm button on the toolbar. Revert to the original order by clicking the Cancelbutton.

Mathscript and Formula Nodes

The Formula Node in the LabVIEW software is a convenient, text-based node you can use to perform complicated mathematical operations on a block diagram using the C++ syntax structure. It is most useful for equations that have many variables or are otherwise complicated. The text-based code simplifies the block diagram and increases its readability. Furthermore, you can copy and paste existing code directly into the Formula Node rather than recreating it graphically.

In addition to text-based equation expressions, the Formula Node can accept text-based versions of if statements, while loops, for loops, and do loops, which are familiar to C programmers. These programming elements are similar but not identical to those you find in C programming.

The MathScript Node implements similar functions but with the additional functionality of a full .m file compiler, making it useful as a textual language for signal processing, analysis, and math. LabVIEW MathScript is generally compatible with .m file script syntax, which is widely used by alternative technical computing software.

Using the Formula NodeComplete the following steps to create a VI that computes different formulas depending on whether the product of the inputs is positive or negative.

1. Selecting File»New VI to open a blank VI.

Page 110: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2. Place a Formula Node on the block diagram.1. Right-click on the diagram and navigate to Programming»Structures»Formula Node.2. Click and drag the cursor to place the Formula Node on the block diagram.3. Right-click the border of the Formula Node and select Add Input from the shortcut menu.4. Labelthe input variable x.5. Repeat steps 3 and 4 to add another input and label it y.6. Right-click the border of the Formula Node and select Add Output from the shortcut menu.7. Create two outputs and name them z1 and z2, respectively.

Note: It is considered good programming practice to keep the inputs on the left border and the outputs on the right border of the Formula Node. This helps you follow the data flow in your VI and keep your code organized.

8. Enter the expressions below in the Formula Node. Make sure that you complete each command with a semicolon. Notice, however, that the if statement does not require a semicolon after the first line.

if (x*y>0)z1 = 3*x**2 - 2*y**3;else z1 = 0;z2 = sinh(z1);

9. Create controls and indicators for the inputs and outputs.1. Right-click on each input and select Create»Control from the shortcut menu.Right-click on each output and select Create»Indicator from the shortcut menu.10. Place a While Loop with a stop button around the Formula Node and the controls. Be sure to include a Wait

(ms) function inside the loop to conserve memory usage. Your block diagram should appear as follows.11. Click the Run button to run the VI. Change the values of the input controls to see how the outputs change.

In this case, the Formula Node helps minimize the space required on the block diagram. Accomplishing the same task without the use of a Formula Node requires the following code.

ResourcesFor more information on the Formula Node syntax or the functions available, see the LabVIEW Help by pressing the <Ctrl-H> keys while you are developing your code. This opens the Context Help window, which includes information about the feature that your mouse is hovering over. In the Context Help window, select Detailed help for more information.

Using the MathScript NodeComplete the following steps to create a VI that performs various operations on a 1D array in LabVIEW.

1. Open a blank VI from the toolbar by selecting File»New VI.2. Place a MathScript Node on the block diagram.1. Right-click on the diagram and navigate to Programming»Structures»MathScript Node.2. Click and drag the cursor to place the MathScript Node on the block diagram.3. In the same manner as you implemented in the Formula Node exercise, right-click on the border and

select Add Input from the shortcut menu. Label the input x.4. Right-click the border and select Add Output from the shortcut menu. Repeat this process to create three

outputs labeled y, y1, and d.5. Place an array of numeric controls on the front panel. Label the array x and wire it to the xinput of the

MathScript Node on the block diagram.6. Create indicators for each of the three outputs by right-clicking each output and

selectingCreate»Indicator from the shortcut menu.7. In the MathScript Node, enter the following expressions:

y = x.^2;y1 = y(1);d = dot(x,y);

8. Place a While Loop with a stop button around the MathScript Node and the controls. Be sure to include a Wait (ms) function inside the loop to conserve memory usage. Your block diagram should appear as follows.

9. On the front panel, expand the arrays to show multiple elements. With the cursor, grab the bottom middle selector of the array and drag it down to show multiple elements.

Page 111: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

10. Begin by placing a 1, 2, and 3 in the first three elements of the x control. Your front panel should look similar to the one below. Note that the fourth and fifth elements are grayed out. This is because they are not initialized. You can initialize them by clicking inside the cell and entering a value. To uninitialize a cell, right-click the element and select Data Operations»Delete Element from the shortcut menu.

11. Click the Run button. Change the values of the elements in the array to see how the outputs change.

ResourcesFor more information on the Formula Node syntax or the functions available, see the LabVIEW Help.  Remember you can access the help by using the Context Help window (Ctrl-H). View the related links below to learn more about the MathScript Node.

Developer Zone: Developing Algorithms Using LabVIEW MathScript: Part 1 – The LabVIEW MathScript NodeDeveloper Zone: Developing Algorithms Using LabVIEW MathScript: Part 2 – The MathScript Interactive Window

Module Exercise

This exercise will walk you through creating arrays and clusters. You will then be able to see how to use arrays and clusters with Formula Nodes and MathScript nodes.

GoalUnderstand the basic behavior of MathScript and Formula Nodes, as well as clusters and arrays.

DescriptionThis exercise consists of a series of tasks in which will walk you through how clusters and arrays can be manipulated and controlled. MathScript and Formula Nodes will also be used to perform mathematical operations.

Arrays, Clusters, and Text Based Nodes1. Launch LabVIEW and open a blank VI.

❑ Select File»New VI.

2. Open the front panel.

3. Place a cluster control on the front panel.

❑ Select Modern»Array, Matrix & Cluster»Cluster from the Controls palette.❑ Place the cluster on the front panel by clicking and holding the cluster on the front panel and then creating a box shape with the mouse.

 

Page 112: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

4. Place three numeric controls in the cluster and label the controls Number, Index, andMultiple, respectively, as shown in the following front panel.

5. Place two array controls on the front panel and label them Original Array and New Array, as shown in the following front panel.

6. Place a numeric control in Original Array.

❑ Select Modern»Numeric»Numeric Control from the controls palette and place it within theOriginal Array structure.❑ Resize the array to seven elements by hovering the mouse on the right side of the array until the double arrows appear, and then clicking and dragging the array out to seven elements, as shown in the following front panel.

❑ Initialize the array by double clicking the last element, entering a value of 0 and pressing the <Enter> key.

7. Place a numeric indicator in New Array.

❑ Select Modern»Numeric»Numeric Indicator from the controls palette and place it within the New Array structure.❑ Resize the array to seven elements by hovering the mouse on the right side of the array until the double arrows appear, and then clicking and dragging the array out to seven elements.

8. Place a numeric indicator on the front panel and label it 5th Element, as shown in the following front panel.

9. Select Window»Show Block Diagram to switch to the block diagram.

10. Place a While Loop structure on the block diagram.

11. Drag all of the elements currently outside the while loop to inside the While Loop.

12. Right-click the conditional terminal of the While Loop and select Create»Control from the shortcut menu.

13. Place an Unbundle by Name function inside the While Loop.

14. Place a Replace Array Subset function inside the While Loop.

15. Wire the output of Cluster to the input of the Unbundle by Name function. 

❑ Resize the Unbundle by Name function so that there are three elements.

16. Place a MathScript Node on the block diagram inside the While Loop.❑ Inside the MathScript Node, enter  z = x*y;.

17. Create inputs and output for the MathScript Node, as shown in the following block diagram.

❑ Right-click the left side of the structure and select Add Input from the shortcut menu.❑ Label this input x.❑ Right-click the left side of the structure and select Add Input from the shortcut menu.❑ Label this input y.

Page 113: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Right-click the right side of the structure and select Add Output from the shortcut menu.❑ Label this input z.

18. Place a Formula Node on the block diagram inside the While Loop to the right of the MathScript Node.

❑ Inside the Formula Node, enter s = t[4];.

19. Create input and output for the Formula Node.

❑ Right-click the left side of the structure and select Add Input from the shortcut menu.❑ Label this input t.❑ Right-click the right side of the structure and select Add Output from the shortcut menu.❑ Label this input s.

20. Wire the block diagram as shown in the following screenshot.

❑ Wire the Number output of the Unbundle by Name function to the x input of the MathScript Node.❑ Wire the Multiple output of the Unbundle by Name function to the y input of the MathScript Node.❑ Wire the output of the Original Array control to the array input of the Replace Array Subset function.❑ Wire the Index output of the Unbundle by Name function to the index input of the Replace Array Subset function.❑ Wire the new array output of the Replace Array Subset function to the input of the New Arrayindicator.❑ Wire the z output of the MathScript Node to the new element input of the Replace Array Subset function.❑ Wire the new array output of the Replace Array Subset function in to the t input of the Formula Node.❑ Wire the s output of the Formula Node to the input of the 5th Element indicator.[+] Enlarge Image

 

21.   Select Window»Show Front Panel to switch to the Front Panel.

22.   Enter the value 5 into the Number input, 3 into the Index input, and 20 into the Multiple input.

23.   Run the VI. Note how the value in the specified index is changed to the value outputted by the MathScript Node. Also note how the Formula Node returns the fifth element of the array.

24.   Press the STOP button.

25.   Close the VI.

END OF EXERCISE

Source: Module 6: Variables - Developer Zone - National Instruments (16 March 2011 12:16 AM)

Page 114: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Module 6: Variables

Local Variable, Global Variable, and Race Conditions

In NI LabVIEW software, the order of execution is controlled by the flow of data (data flow) though wires rather than the sequential order of commands. This allows you to create a block diagram with simultaneous (parallel) operations. When you have parallel loop structures, you cannot use wires to communicate data between the two loops because data flow prevents parallel operation. To overcome this, you must use variables. With variables, you can circumvent normal data flow by passing data from one place to another without connecting the two places with a wire. In LabVIEW, variables take many forms. This tutorial explores the local and global variable as well as race conditions, which can result from the improper use of variables.

Necessity of Variables in LabVIEWThe following steps demonstrate the need for using variables in LabVIEW.

1.       Open a blank VI.

2.       Save the VI as Parallel Loops.vi.

3.       Right-click to open the Controls palette and navigate to Modern»Boolean»Round LED.

4.       Place two Round LED Boolean indicators on the front panel.

5.       Rename the indicators by double-clicking each text label Boolean and typing the title Loop 1 Executed and Loop 2 Executed.

6.       From the menu bar, select Window»Show Block Diagram.

7.       Right-click to open the Functions palette and navigate to Programming»Structures»While Loop.

8.       Place two while loops on the block diagram.[+] Enlarge Image

9.       Right-click to open the Functions palette and navigate to Programming»Timing»Wait (ms).

10.   Place one Wait (ms) VI in each while loop.

11.   Right-click on the input terminal of one Wait (ms) VI (milliseconds to wait) and selectCreate»Constant.

12.   Double-click the Numeric Constant and type “1000.”

13.   Right-click on the input terminal of the second Wait (ms) VI (milliseconds to wait) and selectCreate»Constant.

14.   Double-click the Numeric Constant and type “1000.”

15.   Place one of the Boolean indicators into each while loop.

16.   Right-click to open the Functions palette and navigate to Programming»Boolean»Boolean Constant.

17.   Place one Boolean constant outside each while loop.

18.   Wire each Boolean constant to one of the Boolean indicators in each loop.

19.   Right-click the Loop Conditional Terminal and select Create»Control.[+] Enlarge Image

Page 115: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

20.   Run an additional wire from the newly created Boolean Stop Control to the Loop Conditional Terminal of the second loop.[+] Enlarge Image

Run this VI. Note that the Loop 1 Executed indicator immediately displays a value of true whileLoop 2 Executed remains false. Press the Stop Boolean control. Note that although you have the stop button wired to the loop conditional terminals of both loops, only the first loop immediately stops when you press the Stop button control. Once the first loop stops, the true value is passed out of the first while loop to the second while loop. The second while loop can then execute. TheLoop 2 Executed Boolean indicator should now display a value of true. After a wait of 1 second (1000 ms), a true value is passed to the Loop Conditional Terminal, which stops the second while loop. Because there is no more code to execute, the VI stops executing.

Tip: The two Boolean indicators retain their most recent value after the VI has stopped running. With the program you have created, these two indicators retain a true value. You can set this back to false by right-clicking on the indicator (on either the block diagram or the front panel) and selecting Data Operations»Reinitialize to Default Value.

Implementing a Local Variable

Using the same VI you just created, implement local variables so you can execute both while loops simultaneously as well as stop both while loops simultaneously using a single Boolean control.

1.       Change the milliseconds to wait constant to 10 for both Wait (ms) VIs.

2.       Delete the wire running from the Stop Boolean control to the Loop Conditional Terminal of the second while loop.

3.       On the block diagram, right-click the Stop Boolean control and select Create»Local Variable.[+] Enlarge Image

 

4.       Place the local variable in the second while loop.

5.       Right-click the local variable and select Change to Read.[+] Enlarge Image

6.       Wire the output of the local variable to the input of the loop conditional terminal.[+] Enlarge Image

Note: At this point, you are not able to run the VI because Boolean controls associated with a local variable cannot use latch mechanical action. For example, Latch When Released changes the control value only after you release the mouse button within the graphical boundary of the control. When the VI reads it once, the control reverts to its default value. A switch mechanical action does not revert back to its default value.

7.       On the front panel, right-click the Stop Boolean control and select Mechanical Action»Switch When Released.

8.       Run the VI.[+] Enlarge Image

Notice that the Boolean indicators associated with each loop immediately display true when you run the VI, and both loops stop running when you press the Stop Boolean control.

Implementing a Global VariableYou can use local variables only to pass data between two different locations in a single VI. If you require control over two separate VIs running in parallel or a VI and subVI, you must use a global variable.

1.        Select File»New Project.

Page 116: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2.       When prompted to add the open VI to the new project, select Add. The open VI should be the VI you created in the previous section of this tutorial.

3.       Delete the local variable from the second while loop.[+] Enlarge Image

4.       Within the block diagram, right-click to open the Functions palette.

5.       Navigate to Structures»Global Variable.[+] Enlarge Image

6.       Double-click the global variable to open its front panel.

7.       Right-click the global variable front panel and navigate to Modern»Boolean»Stop Button.

8.       Save the global variable as Global 1.vi and close its front panel.

9.       In the Project Explorer window, right-click My Computer and select New»VI.

10.    Save the New VI as Second Loop.vi.

11.   In Parallel Loops.vi, select the second while loop as well as the constant and wires running into the while loop.[+] Enlarge Image

12.    Select Edit»Cut.

13.   Open the block diagram of Second Loop.vi and select Edit»Paste.

14.   Save Parallel Loops.vi as Parallel Global.vi.

15.   From the Project Explorer window, drag and drop Global 1.vi onto the block diagram of Second Loop.vi.[+] Enlarge Image

16.    Right-click the global variable icon and select Change to Read.

17.    Wire the Stop global variable to the Loop Conditional Terminal.

18.   Save the VI.

19.   Open Parallel Global.vi.

20.    Place the Stop global variable inside the while loop and wire it to the Stop Boolean control.

21.    Run both VIs.

22.   Press the Stop button on Parallel Global.vi – note that both VIs stop executing simultaneously.

Race ConditionsA race condition is when the execution timing or order of a program unintentionally affects an output or data value. This is the same condition that can occur within text-based programming. However, dataflow programming prevents race conditions. In instances where data flow breaks down, such as in parallel programming, race conditions can occur.

Open the attached Race Condition.lvproj and open counter 1.vi. This VI uses shared variables to pass data between the two loops. Shared variables are similar to global variables except they also contain error in and out terminals and have the ability to be published across the network. In this VI, you are simply using the shared variables to communicate data locally between the two loops.

The two loops increment the same variable in each iteration. The expected result of running this VI is Total Count, which is the sum of Count 1 and Count 2. In actuality, Total Count displays a value less than the sum of Count 1 and Count 2. The behavior worsens the longer the code is run. This is due to a race condition present

Page 117: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

in the VI. In a single processor computer, this code is actually running sequentially, but LabVIEW and the operating system switch between tasks rapidly so the code can essentially operate in parallel. Note that both loops perform the following operations:

•          Read the shared variable

•          Increment the value read

•          Write the incremented value to the shared variable

Now consider what happens if the loop operations happen to be scheduled in the following order:

1.       Loop 1 reads the shared variable

2.       Loop 2 reads the shared variable

3.       Loop 1 increments the value it read

4.       Loop 2 increments the value it read

5.       Loop 1 writes the incremented value to the shared variable

6.       Loop 2 writes the incremented value to the shared variable

When this occurs, both loops write the same incremented value to the shared variable. This generates a race condition and can cause problems if you expect the result to be an exact sum ofCount 1 and Count 2.

Exercise: Local Variable, Global Variable, and Race Conditions

This exercise will show you how to create local and global variables. You will be able to see when in your program you should use local versus global variable. Lastly, you will learn about how to identify and resolve race conditions in your program.

GoalUnderstand the basic behavior of variables in the LabVIEW environment. Understand the danger of race conditions and how to identify them in a program.

DescriptionThis exercise consists of a series of tasks in which will walk you through how variables are created and manipulated in a virtual instrument. Race conditions are also explored and the user is walked through how to identify and fix them.

Local VariablesScenarioYou have a LabVIEW Project that implements a temperature weather station. The weather station acquires a temperature every half a second, analyzes each temperature to determine if the temperature is too high or too low, then alerts the user if there is a danger of a heat stroke or freeze. The VI logs the data if a warning occurs. Two front panel controls determine the setpoints—the temperature upper limit and the temperature lower limit. However, nothing prevents the user from setting a lower limit that is higher than the upper limit. Use variables to set the lower limit equal to the upper limit if the user sets a lower limit that is higher than the upper limit.

Page 118: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Note: In this exercise, you will be using a simulated temperature signal. If desired, a data acquisition device could be installed.  Also, all of the files required for this project are located in the variables.zip file at the bottom of this page. Download it, extract it, and reference the included files for this project.

DesignThe VIs in this project have already been written. Your only task is to modify the VIs so that the lower limit is set equal to the upper limit when necessary.

State Definitions

The following table describes the states in the state machine.

State Description Next State

Acquisition Set time to zero, acquire data from the temperature sensor, and read front panel  controls

Analysis

Analysis Determine warning level Data Log if a warning occurs, Time Check if no warning occurs

Data Log Log the data in a tab-delimited ASCII file

Time Check

Time Check Check whether time is greater than or equal to .5 seconds

Acquisition if time has elapsed, Time Check if time has not elapsed

 

Changing the value of the lower temperature limit control should happen after the user has entered the value but before the value determines the warning level. Therefore, make the modifications to the VI in the Acquisition or Analysis state, or place a new state between the two.

1. Before determining which option to use, take a closer look at the content of the Acquisition and Analysis states:

❑ Open the Weather Station project located in the weather_station.zip file at the bottom of this page.

❑ Open Weather Station UI.vi.

❑ Review the contents of the Acquisition and Analysis states, which correspond to the Acquisition and Analysis cases of the Case structure.

Design OptionsYou have three different design options for modifying this project.

Option Description Benefits/Drawbacks

1 Insert a Case structure in the Acquisition state to reset the controls before a local variable writes the values to the cluster.

Poor design: the acquisition state has another task added, rather than focusing only on acquisition.

2 Insert a new state in the state Ability to control when the state

Page 119: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

machine that checks the controls and resets them if necessary.

occurs.

3 Modify the Determine

Warnings subVI to reset the controls.

Easy to implement because functionality is already partially in place. However, if current functionality is used, one set of data always is lost when resetting the lower limit control.

 

New State Definitions for Option 2The following table describes the new state definitions to implement.

 

1. If the Weather Station.lvproj is not already open, open it.

2. Add the Range Check state to the state machine.

❑ From the Project Explorer window, open the Weather Station States.ctl by double-clicking the listing. This is the type-defined enumerated control that defines the states for the state machine.

❑ Right-click the control and select Edit Items from the shortcut menu.

❑ Insert an item and modify to match the following table. Be careful not to add an empty listing.

Item Digital Display

Acquisition 0

Range Check 1

Analysis 2

Data Log 3

Time Check 4

❑ Save and close the control.

❑ If the Weather Station UI.vi is not open, open it by double-clicking the listing in the Project Explorer window.

❑ Open the block diagram.

❑ Right-click the state machine Case structure and select Add Case for Every Value from the shortcut menu. Because the enumerated control has a new value, a new case appears in the Case structure.

3. Read the upper and lower limit controls in the Range Check state, instead of the Acquisition state.

❑ Return to the block diagram of the Weather Station UI VI. Select the Acquisition case in the state machine Case structure.

Page 120: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Inside the Acquisition case, change the Next State enum to Range Check.

❑ Make a copy of the Next State enum by pressing <Ctrl> and dragging a copy outside the While Loop.

❑ Move the Upper Limit and Lower Limit numeric controls outside the While Loop.

❑ Resize the Bundle by Name function to one element, as shown in the figure above

❑ Select the Range Check case in the state machine Case structure.

❑ Move the Upper Limit and Lower Limit numeric controls and the Next State enum into the Range Check state.

4. Set the Range Check state to transition to the Analysis state.

❑ In the Range Check case, wire the Next State enum to the Next State output tunnel.

❑ Change the Next State enum to Analysis.

5. If the Upper Limit is less than the Lower Limit, use a local variable to write the Upper Limit value to the Lower Limit control.

❑ Add a Less? function to the Range Check state.

❑ Add a Case structure to the right of the Less? function.

❑ Wire the Upper Limit and Lower Limit controls to the Less? function and the Case structure as shown in the figure above.

❑ Right-click the Lower Limit control and select Create»Local Variable from the shortcut menu.

❑ Move the local variable inside the True case of the Case structure.

❑ Add a Bundle By Name function to the right of the Case structure.

❑ Wire the Temperature Data cluster to the input cluster input of the Bundle By Name function.

Page 121: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Expand the Bundle By Name function to two elements.

❑ Select T Upper Limit in the first element and T Lower Limit in the second element.

❑ Add a False constant to the outer Case structure.

❑ Wire the case as shown in the previous figure.

7. If the Upper Limit is equal to or greater than the Lower Limit, pass the values of the controls to the temperature cluster.[+] Enlarge Image

❑ Switch to the False case of the interior Case structure.

❑ Wire the Upper Limit and Lower Limit data through the case.

8. Save the VI.

9. Save the Project.

Test1. Run the VI.

❑ Name the log file when prompted.

❑ Enter a value in the Upper Limit control that is less than the value in the Lower Limit control. Does the VI behave as expected?

2. Stop the VI when you are finished.

3. Close the VI and the project.

Global VariablesScenarioCreate a VI that generates a sine wave. Create a second VI that displays the sine wave and allows the user to modify the time between each acquisition of the sine wave data. Use one stop button to stop both VIs.

DesignTwo VIs and two pieces of global data are necessary to implement the VI:

• First VI: generate sine, write sine to Data shared variable, read Stop shared variable to stop loop

• Second VI: read Data shared variable, display on chart, write Stop button to Stop shared variable

• First shared variable: Stop (Boolean data type)

• Second shared variable: Data (Numeric data type)Implementation

1. Open a blank project.

2. Save the project as Global Data.lvproj.

3. Create the Stop shared variable.

❑ Give the variable the following properties.

–Name: Stop

Page 122: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

– Data Type: Boolean

– Variable Type: Single-process

❑ Click OK to close the Shared Variable Properties dialog box. Notice that a new library is created in the Project Explorer window to hold the variable.

4. Save the library.

❑ Right-click the library and select Save from the shortcut menu.

❑ Save the library as Global Data.lvlib.

5. Create the Data shared variable.

❑ Switch to the Project Explorer window.

❑ Right-click Global Data.lvlib and select New»Variable from the shortcut menu.

❑ Give the new variable the following properties:

–Name: Data

– Data Type: Double

– Variable Type: Single-process

❑ Click OK to close the Shared Variable Properties dialog box.

Generate Data VI1. Open a blank VI.

2. Save the VI as Generate Data.vi

3. Add a Numeric Indicator to the front panel window.

4. Name the Numeric Indicator Data.

5. Switch to the block diagram of the VI.

6. Create the block diagram shown in the figure below. No implementation instructions are given. Labels are shown to assist you.

7. Save the VI.

8. Write the data generated to the Data shared variable.

❑ Select the Data shared variable from the Project Explorer window and drag it inside the While Loop of the Generate Data VI block diagram.

❑ Right-click the global variable and select Change to Write from the shortcut menu.

❑ Wire the Sin(x) output of the Sine function to the Data shared variable.

9. Read the Stop shared variable to stop the While Loop.

❑ Switch to the Project Explorer window.

❑ Select the Stop shared variable and drag it inside the While Loop of the Generate Data.vi block diagram.

Page 123: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Wire the Stop shared variable to the Loop Condition terminal.

10. Initialize the Stop shared variable.

❑ Switch to the Project Explorer window.

❑ Select the Stop shared variable and drag it to the left of the While Loop of the Generate Data.vi block diagram.

❑ Right-click the Stop shared variable and select Change to Write from the shortcut menu.

❑ Right-click the input of the Stop shared variable and select Create»Constant from the shortcut menu to create a False constant.

❑ Use the Operating tool to change the constant to False if necessary.

11. Use the shared variable error clusters to ensure the order of operations. Refer to the following figure for assistance wiring this block diagram.

12. Save the VI.13. Close the block diagram, but leave the front panel open.

Read Data VI1. Open a blank VI.

2. Save the VI as Read Data.vi.

3. Create the front panel shown in the next figure

4. Add a vertical pointer slide and rename it Time Delay (ms).

❑ Change the range of the slide by entering 200 in the top value shown.

❑ Right-click the slide and select Representation»U32 from the shortcut menu.

❑ Add a waveform chart and rename it Data Chart.

❑ Change the x-scale and y-scale ranges and labels of the chart to the values shown in the previous figure.

❑ Add a Stop button and hide the label.

5. Open the block diagram.

6. Create the block diagram shown in the next figure. Labels are shown to assist you.

7. Read the data from the Data shared variable and display it on the waveform chart.

❑ Switch to the Project Explorer window.

❑ Select the Data shared variable and drag it inside the While Loop ofthe Read Data VI block diagram.

❑ Wire the output of the Data shared variable to the Data Chart indicator.

8. Write the value of the Stop control to the Stop shared variable.

❑ Switch to the Project Explorer window.

❑ Select the Stop shared variable and drag it inside the While Loop ofthe Read Data.vi block diagram.

❑ Right-click the Stop shared variable and select Change to Write from the shortcut menu.

Page 124: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Wire the Stop control to the Stop shared variable.

9. Use the shared variable error clusters to ensure the order of operations. Refer to the next figure for assistance wiring this block diagram.

10. Save the VI.

11. Close the block diagram.

12. Save the project.

Test1. Run the Generate Data VI.

2. Run the Read Data VI.

3. Modify the value of the Time Delay (ms) control. The Time Delay (ms) control determines how often the shared variable is read. What happens if you set the Time Delay to zero? When accessing global data, you may read the value more than once before it is updated to a new value, or you may miss a new value altogether, depending on the value of the Time Delay.

4. Stop and close the VIs and the project when you are finished.

 

Race ConditionsDescriptionYou must identify and fix a problem with the server software in a bank. The bank server handles requests from many sources and must process the requests quickly. In order to increase its efficiency, the server uses two parallel loops—one to handle deposits to the account and another to handle withdrawals. The problem with the server is that some deposit or withdrawal requests are lost, thereby resulting in incorrect balances.

 Identify Race Condition1. Open bank.vi in the zip file at the bottom of this page.

2. Run the VI.

3. Perform a deposit, a withdrawal, and a simultaneous transaction to familiarize yourself with the program.

4. Set the Deposit Amount to 20 and the Withdrawal Amount to 10.

5. Open the block diagram of the Bank VI while it is still running.

6. Arrange the block diagram of the Bank VI so that you can see it while operating the user interface.

7. Enable execution highlighting on the block diagram by clicking Highlight Execution.

8. Click the Simultaneous Transactions button and watch the code as it executes. The balance should increase by 10. Notice that either the deposit or the withdrawal is lost, causing the balance to increase by 20 or decrease by 10.

9. Stop the VI. You tracked the problem down to a race condition in a section of a code handling deposits and withdrawals for a single account. Although you can see the issue with execution highlighting enabled, during regular operation, the issue would occur sporadically.

Remove Race ConditionRemove the race condition by protecting the critical section of code using a semaphore. In the VI, the critical sections of code are those enclosed by a Sequence structure.

Page 125: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

1. Save the VI as Bank with Semaphores.vi.

2. Use semaphores to protect the critical sections of code, as shown in the figure below.

❑ Add a Create Semaphore VI to the left of the While Loops.

❑  Wire the Create Semaphore VI as shown in the previous figure.

❑ Add an Acquire Semaphore VI to the Deposit Handler loop, to the left of the Sequence structure.

❑ Add a second Acquire Semaphore VI to the Withdrawal Handler loop to the left of the Sequence structure.

❑ Wire the Acquire Semaphore VIs as shown in the previous figure.

❑ Add a Release Semaphore VI to the Deposit Handler loop, to the right of the Sequence structure.

❑ Add a second Release Semaphore VI to the Withdrawal Handler loop, to the right of the Sequence structure.

❑ Wire the Release Semaphore VIs as shown in the figure above.

❑ Add a Destroy Semaphore VI to the right of the While Loops.

❑ Wire the Destroy Semaphore VI as shown in the previous figure. Notice that the Destroy Semaphore VI requires only the reference to the semaphore.

3. Save the VI.

4. Repeat the steps detailed in the Test section to test the modification to this VI.

5. Close the VI when you are finished.

End of Exercise

State Description Next State

Acquisition Acquire data from the temperature sensor on channel AI0 and read front panel controls

Range Check

Range Check Read front panel controls and set the lower limit equal to the upper limit if upper limit less than the lower limit

Analysis

Analysis Determine warning level Data Log if a warning occurs, Time Check if

no warning occurs

Data Log Log the data in a tab-delimited ASCII file Time Check

Time Check Check whether time is greater than or equal to

.5 seconds

Acquisition if time has elapsed, Time Check if time has not elapsed

Page 126: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Module 7: State Machines - Developer Zone - National Instruments (16 March 2011 12:19 AM)

Module 7: State Machines

Introduction to Creating State Machines

The state machine is one of the fundamental architectures NI LabVIEW developers frequently use to build applications quickly. Developers use state machines in applications where distinguishable states exist. Each state can lead to one or multiple states and can end the process flow. A state machine relies on user input or in-state calculation to determine which state to go to next. Many applications require an “initialize” state followed by a default state, where you can perform many different actions. These actions depend on previous and current inputs as well as states. You can use a “shutdown” state to perform cleanup actions.

Page 127: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

In LabVIEW software, you can create a basic state machine with a while loop, a shift register, a case statement, and some form of case selector (case selectors are discussed in a later section). The while loop is the main program loop, which executes until the conditions for exiting the program are met. The while loop’s main responsibility is to call the case selector and then execute the appropriate case. The shift register keeps track of which case should execute next. Finally, each case of the case statement contains the action for one specific use action. Often the default case is used as the place to check the case selector (in other words, if the user did nothing, check again to see if he has done something yet).

State DiagramWhen designing state machines, you can create a state diagram to graphically represent the different states and how they interact. Use state diagrams, the design frameworks for state machines, to model the control algorithms you need with discrete logical states. State Diagrams make it easy to develop and understand the functionality of an application that uses a state machine.

The figure below is an example of a state diagram. The ovals represent the states and the arrows represent the possible transitions between states.

All applications require an initial state, or starting point, followed by transition states that perform different actions. A terminal state, or ending point, is the final state executed and performs cleanup actions.

State diagrams are useful in simplifying the design process of applications that use complex decision-making algorithms. To create an effective state diagram, you must know the various states of the application and how they relate to one another. By visualizing the various execution states of the application, you improve the overall design of the application.

Page 128: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Design a State Machine with a State DiagramImagine a vending machine that accepts combinations of nickels and dimes to get a coke. The cost of a coke is 15 cents and the machine does not return change. First, establish the states that the vending machine might be in:

•          Start: No money inserted

•          5 cents

•          10 cents

•          Done: 15 cents

Now think about the possible ways or paths that the vending machine can take to get into these states. Don’t forget to consider how the vending machine starts in the initial state.

•          Nickel is inserted

•          Dime is inserted

•          Default: Nothing is inserted

From these lists, you see that there are four states and three possible paths from each state. You need to depict which states are connected by which paths. For example, when the vending machine is in the initial start state, the total change inserted is 0 cents. When a nickel is inserted, the vending machine must go to the 5 cent state. Therefore, the start state leads to the 5 cent state by the nickel path. By considering all states and paths, you can create a state diagram for the vending machine:

With a state diagram, you can better understand how to create a state machine.

Building a State MachineUsing the state diagram above, create a state machine.

1.       Create a new blank VI.

2.       On the front panel place:

•          Two text buttons named “Nickel” and “Dime”

•          Text indicator named “Money Deposited”

•          Boolean indicator named “Dispense coke”

Page 129: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3.       Place a while loop on the block diagram.

4.       Place a case structure in the while loop.

5.       Create a shift register on the while loop.

6.       Create an Enum and wire it to the shift register to initialize it.

7.       Right-click the Enum, select Edit Items, and add the following “states”:

•          Start

•          5 cents

•          10 cents

•          Dispense

Page 130: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

8.       Wire the shift register to the conditional input of the case structure.

9.       Right-click the case box at the top of the case structure and select Add Case for Every Value.

10.   Wire the different cases as depicted in the following figures.

Page 131: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

11.   Wire Dispense coke to the Boolean output of the case structure.

12.   Inside the while loop, place a wait function with a constant.

Page 132: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

13.   Outside of the while loop, wire a constant of 0 to the Money Deposited string indicator.

The finished VI should look like this:

Video           Exercise          State Machine          Modules Home          FIRST Community

Module Exercise

This exercise will show you how you are able to create a State Machine in LabVIEW. You will go through the general steps needed to create and then manipulate the State Machine.

GoalUnderstand the basic mechanics of state machines in LabVIEW.

DescriptionThis exercise consists of a series of tasks in which will walk you through how state machines are created and how to manipulate and control them.

Implementation1. Launch LabVIEW and open a blank VI.

❑ Select File»New VI

2. Place a while loop on the block diagram.

❑ On the block diagram, under the View menu select Functions Palette

❑ Within the programming folder, select Structures » While Loop

Page 133: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3. Place a case structure in the while loop.

❑ Within the functions palette, select Structures » Case Structure

4. Create a shift register on the while loop.

❑ Right click the while loop

❑ Select Add Shift Register

5. Create an Enum and wire it to the shift register and case structure.

❑ Within the functions palette, select Numeric » Enum Constant

❑ Wire the Enum to the shift register input

❑ Wire the shift register output to the case structure conditional terminal

Page 134: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The Enum acts as a variable to contain the current state information. The case structure will contain the code that is to execute during the current state and to determine the next state.

6. Create a list of states contained in the Enum.

❑ Right click the Enum

❑ Select Edit Items

❑ Click Insert

❑ Type "First State"

❑ Press the <Enter> key to access the next position in the list

❑ Type "Second State"

❑ Click Ok

7. Create a button on the front panel to control the states.

❑ On the front panel, open the control palette by selecting View » Controls Palette

❑ Select Buttons » Rocker and place it on the front panel

Page 135: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

When the button is in the false state, the state machine will be in the first state and when the button is in the true state, the state machine will be in the second state.

8. Create a LED on the front panel to indicate the current state.

❑ On the front panel, open the control palette by selecting View » Controls Palette

❑ Select LEDs » Round LED and place it on the front panel

9. Wire the button into the case structure to control the state transitions from the second state.

❑ On the block diagram, move the button control to the left side of the case structure within the while loop

❑ Select Second State from the case pull down menu at the top of the case structure

❑ Open the functions palette by selecting View » Functions Palette

❑ Select Programming » Comparison » Select and place it in the case structure

❑ Wire the button output to the S input of the select function

Page 136: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

10. Specify which state to go to based on the buttons state for the second state.

❑ Right click on the Enum and select Create » Constant

❑ Move the constant into the case structure and wire it to the T input of the select function

❑ Click the down arrow on the Enum constant

❑ Select Second State

❑ Right click on the Enum and select Create » Constant

❑ Move the constant into the case structure and wire it to the F input of the select function

❑ Click the down arrow on the Enum constant

❑ Select First State

❑ Wire the select function output to right shift register

11. Use the LED indicator to show which state is the current state.

❑ Move the LED indicator to the right of the case structure within the while loop

❑ Connect the wire input into the S input terminal of the select function and the LED indicator

Page 137: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

12. Configure the case structure to control the state transitions from the first state.

❑ Select First State from the case pull down menu at the top of the case structure

❑ from the functions palette select Programming » Comparison » Select and place it in the case structure

❑ Wire the button output to the S input of the select function

❑ Right click on the Enum and select Create » Constant

❑ Move the constant into the case structure and wire it to the T input of the select function

❑ Click the down arrow on the Enum constant and select Second State

❑ Right click on the Enum and select Create » Constant

❑ Move the constant into the case structure and wire it to the F input of the select function

❑ Click the down arrow on the Enum constant and select First State

❑ Wire the select function output to right shift register

❑ Wire the input into the S input terminal of the select function and the LED indicator

12. Create a delay in the while loop.

❑ From the functions palette select Programming » Timing » Wait

❑ Place a numeric constant from Programming » Numeric » Numeric Constant

Page 138: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

❑ Type 100 into the numeric constant

❑ Wire the constant to the input of the wait function

12. Create a control to stop the while loop.

❑ Right click the input to the conditional terminal of the while loop

❑ select Create Control

When the VI is running the LED indicator will be lit when the state machine is in the second state and not lit when the state machine is in the first state. This is a basic example that can be expanded upon by inserting code in the case structure that will only execute when the respective state is the current state. Additional states can also be added by adding items to the Enum and corresponding cases to the case structure

Page 139: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: Module 8: Software Development Method - Developer Zone - National Instruments (16 March 2011 12:58 AM)

Module 8: Software Development Method

Introduction to the Software Development Method

Once you have learned many of the key NI LabVIEW software programming concepts, the next step is to create your own program. One of the most important aspects of software engineering is using an effective method to develop a program. Before you start developing applications, you need to determine all of the different project stages and plan accordingly. The first step in becoming an effective programmer is learning an efficient and reusable process to develop an application from start to finish.

Defining the ProblemBefore you start planning a project, you have to clearly define the problems. Complex projects likely involve many different problems. For example, imagine a program in a machine that sells train tickets. The program must account for several factors such as how much different train tickets cost, types of discounts, methods of payment, and the schedule for all of the train lines.

One effective way many computer scientists organize their thoughts is by using a whiteboard or chalkboard to brainstorm. By using one of these, all of the thoughts and ideas you have are illustrated in a form that others can work with. If a project involves other people, group brainstorm sessions are also an effective way to organize every group member’s ideas. During this phase, it is important to write down on the whiteboard whatever comes to mind, no matter how unfeasible the idea seems. An example can be seen in the figure below.

Page 140: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Obviously this is just a small example, but it gives you an idea of how to get started with the brainstorming stage. By writing out all of the ideas in your head, you establish a better understanding of what exactly a project entails. Notice that the coffee idea is a little extreme, but it shows how the user should not hold back his ideas during this stage. Some of the best ideas for a project can spawn from ideas that may not seem realistic at first. Every computer scientist has a different method for brainstorming, so you should feel free to do whatever necessary to illustrate your ideas.

Identifying Inputs/OutputsEvery program has a certain number of inputs and outputs. Without these, a program has no functionality. The inputs of a program are all of the different elements used to make calculations and process data to produce the end results, or outputs, of a program. The ticket machine example above  features multiple inputs and outputs. Some of the inputs include ticket type, discount type, and amount of money given to the machine. Some of the outputs or final products of the ticket machine are the printed ticket, the amount of change dispensed, and the receipt. It would be a good idea to use a whiteboard again to illustrate all of these parameters.

As you can see in the figure above, the purpose of the actual program is to manipulate the inputs to create the outputs. Therefore, it is crucial that a programmer has a clear understanding of the inputs and outputs before the actual programming begins.

Flowcharts

Page 141: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Flowcharts are essential in any type of software project. They basically illustrate the sequential steps and decisions made throughout the execution of the program and show every possible action and decision for a given algorithm. For the ticket machine example, a simple flowchart for when a customer buys a ticket is shown in the figure below.

There are a few items in the flowchart to note. The rectangular boxes represent action symbols. These actions can be anything from reading user input to displaying information to the customer. Two action symbols that should appear in every flowchart are the start and stop symbols. These symbols tell where a program begins execution and where a program halts execution. The start symbol should have one arrow only coming out of it while the stop symbol should have arrows only going into it. Each action symbol should have a maximum of one arrow coming out of it.

The other main component of the flowchart is the decision symbol. This symbol determines the actual flow of the flowchart. Once execution reaches these symbols, the specified condition inside the symbol is checked. The new path of execution from the decision symbol depends on whether the condition is met. In the example, the first decision symbol reads “A≥P?” When the execution reaches this symbol, it should check whether “A≥P,” or whether the money that the customer gave was greater than or equal to the ticket price. If the customer did not pay enough money, the execution goes back to the “Read A” action symbol. If the customer did pay enough money and the condition was met, the ticket prints and the execution continues.

Implementing the CodeNow that you have completed the planning stages, you need to start writing code. One common mistake is not using all of the resources gathered during the planning stages. You can significantly expedite the programming process by carefully following all of the charts and diagrams you created.

As far as the actual implementation goes, you should follow these widely accepted programming practices:

1.       Document any code very thoroughly

2.       Give variables and functions relevant names

Page 142: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

3.       Make code spacing readable and clean

Documentation is very critical, especially in group projects. If thorough documentation accompanies  your code, other programmers can look at the code and understand the task you were trying to implement. This saves time down the line when others are working with the code. As far as naming conventions go, by giving all the functions and variables names related to their purposes, you can drastically increase the legibility your code. Consider the following code in the figure below that was written in LabVIEW.

 

You can see that the code is not very legible, and the program’s purpose is not clear. Below is the same program written in a much more legible and linear style.

Because of the detailed documentation, the program’s intent is clear. Even a person with minimal programming experience is able to easily read this code and understand each component. The spacing and placement of components are aesthetically pleasing and very intuitive.

Programming in a Group

Page 143: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Complex projects require the attention of multiple team members. It is important to know how to effectively split up portions of code so that everyone is programming efficiently and not producing any redundant code. The first step of splitting up the work is defining different sections of the project to assign each team member.

 

Obviously with different people programming different sections, communication is essential. It is important for all of the programmers to make sure that their code can work together effectively. You also need to select team’s integrator. The integrator is responsible for combining all of the finished code written by the other team members into one complete program. The block diagram of this concept for the ticket machine example is shown below.

Make sure that each team member’s workload is realistic. Ideally, you should distribute the workload evenly among all of the group members; however, in reality, this rarely happens. Certain portions of the project are inevitably going to require more work than others. Typically, the team member responsible for integration is going to have a higher workload than the other members. It is also important that you set realistic deadlines and clearly communicate them to all of the team members. By planning out specific deadlines for project milestones, you can measure progress more effectively.

VerificationThe last stage for any software project is the verification stage. During this stage, you must complete extensive testing to make sure the final product is error- and bug-free. At the start of this stage, you should define and execute many different tests and use cases to ensure the highest-quality final product. You need to account and test for every single possibility and state. You also need to implement and test the error handling that tests invalid inputs.

A few examples of tests for the ticket machine example are:

1.       Buying a ticket with insufficient money

Page 144: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

2.       Purchasing a ticket for a train that has already left

3.       Paying more money than the amount due to test if the correct change is dispensed

Testing all of these use cases is one of the most important aspects of a project. To illustrate the importance of this, consider a standard vending machine that sells snacks and candy. Many of these vending machines are notorious for getting the snack stuck on the hook of the dispenser and, in effect, ripping off the customer. Errors like these are the direct result of improper testing and verification. Therefore, it is essential in any type of software project to allocate adequate time for extensive testing and verification.

Module Exercise

This exercise will walk you through the steps of using the software development method. You will be able to go through the process and then be able to take the software development method and apply it to your application.

GoalSolve a problem using the software development method without using software.

ScenarioYou are responsible for displaying the time until arrival for airplanes at an airport. You receive this information in seconds, but must display it as a combination of hours/minutes/seconds.

DesignWhat inputs are you given?

What outputs are you expected to produce?

What is the relationship/conversion between the inputs and outputs?

Tip: Use the Windows calculator to help you determine the relationship.

Create an algorithm or flowchart that demonstrates the relationship between the inputs and outputs.

ImplementationDuring this stage, you implement the program from the algorithm or flowchart. For this exercise, skip this stage.

TestingUse a set of known values to test the algorithm or flowchart you designed.

Example inputs with corresponding outputs:

Input Output

0 seconds 0 hours, 0 minutes, 0 seconds

60 seconds 0 hours, 1 minute, 0 seconds

3600 seconds 1 hour, 0 minutes, 0 seconds

3665 seconds 1 hour, 1 minute, 5 seconds

Page 145: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

 

MaintenanceIf a test value set has failed, return to the design phase and check for errors.

End of Exercis

Page 146: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Source: In NI LabVIEW software, the array index is zero-based.... (13 March 2011 3:10 PM)

 creating and manipulating arrays and clusters

An array, which consists of elements and dimensions, is either a control or an indicator – it cannot contain a mixture of controls and indicator

 In NI LabVIEW software, the array index is zero-based. This means that if a one-dimensional (1D) array contains n elements, the index range is from 0 to n – 1, where index 0 points to the first element in the array and index n – 1 points to the last element in the array.

If you wire an array as an input to a for loop, LabVIEW provides the option to automatically set the count terminal of the for loop to the size of the array using the Auto-Indexing feature. You can enable or disable the Auto-Indexing option by right-clicking the loop tunnel wired to the array and selecting Enable Indexing (Disable Indexing).

If you enable Auto-Indexing, each iteration of the for loop is passed the corresponding element of the array.

When you wire a value as the output of a for loop, enabling Auto-Indexing outputs an array. The array is equal in size to the number of iterations executed by the for loop and contains the output values of the for loop.

Page 147: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 148: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

LabVIEW includes hundreds of example VIs you can use and incorporate into VIs that you create. In addition to the example VIs that ship with LabVIEW, you also can access hundreds of example VIs on the NI Developer Zone (zone.ni.com).

LabVIEW programs are called virtual instruments (VIs). Controls are inputs and indicators are outputs. Each VI contains three main parts:· Front Panel – How the user interacts with the VI.· Block Diagram – The code that controls the program.· Icon/Connector – Means of connecting a VI to other VIs.

In LabVIEW, you build a user interface by using a set of tools and objects. The user interface is known as the front panel. You then add code using graphical representations of functions to control the front panel objects.

Page 149: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Use the Functions palette to build the block diagram. To view the palette, select Window»Show Functions Palette.

Page 150: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

When you create an object on the Front Panel, a terminal will be created on the Block Diagram. These terminals give you access to the Front Panel objects from the Block Diagram code.

Each terminal contains useful information about the Front Panel object it corresponds to. For example, the color and symbols provide information about the data type. For example: The dynamic data type is a polymorphic data type represented by dark blue terminals. Boolean terminals are green with TF lettering.

In general, blue terminals should wire to blue terminals, green to green, and so on. This is not a hard-and-fast rule; LabVIEW will allow a user to connect a blue terminal (dynamic data) to an orange terminal (fractional value), for example. But in most cases, look for a match in colors.

Controls have an arrow on the right side and have a thick border. Indicators have an arrow on the left and a thin border. Logic rules apply to wiring in LabVIEW: Each wire must have one (but only one) source (or control), and each wire may have multiple destinations (or indicators).

If automatic tool selection is enabled and you move the cursor over objects on the front panel or block diagram, LabVIEW automatically selects the corresponding tool from the Tools palette. Toggle automatic tool selection by clicking the Automatic Tool Selection button in the Tools palette.Use the Operating tool to change the values of a control or select the text within a control.Use the Positioning tool to select, move, or resize objects. The Positioning tool changes shape when it moves over a corner of a resizable object.Use the Labeling tool to edit text and create free labels. The Labeling tool changes to a cursor when you create free labels.Use the Wiring tool to wire objects together on the block diagram.

Page 151: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

• Click the Run button to run the VI. While the VI runs, the Run button appears with a black arrowif the VI is a top-level VI, meaning it has no callers and therefore is not a subVI.• Click the Continuous Run button to run the VI until you abort or pause it. You also can click thebutton again to disable continuous running.• While the VI runs, the Abort Execution button appears. Click this button to stop the VIimmediately.Note: Avoid using the Abort Execution button to stop a VI. Either let the VI complete its dataflow or design a method to stop the VI programmatically. By doing so, the VI is at a known state.For example, place a button on the front panel that stops the VI when you click it.• Click the Pause button to pause a running VI. When you click the Pause button, LabVIEWhighlights on the block diagram the location where you paused execution. Click the Pausebutton again to continue running the VI.• Select the Text Settings pull-down menu to change the font settings for the VI, including size,style, and color.• Select the Align Objects pull-down menu to align objects along axes, including vertical, topedge, left, and so on.• Select the Distribute Objects pull-down menu to space objects evenly, including gaps,compression, and so on.• Select the Resize Objects pull-down menu to change the width and height of front panelobjects.

Page 152: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

LabVIEW follows a dataflow model for running VIs. A block diagram node executes when allit i t il its inputs are available. When a node completes execution, it supplies data to its output terminals and passes the output data to the next node in the dataflow path. Visual Basic, C++, JAVA, and most other text-based programming languages follow a control flow model of program execution. In control flow, the sequential order of program elements determines the execution order of a program.

Consider the block diagram above. It adds two numbers and then multiplies by 2 from theresult of the addition. In this case, the block diagram executes from left to right, not becausethe objects are placed in that order, but because one of the inputs of the Multiply function isnot valid until the Add function has finished executing and passed the data to the Multiplyfunction. Remember that a node executes only when data are available at all of its inputterminals, and it supplies data to its output terminals only when it finishes execution. In thesecond piece of code, the Simulate Signal Express VI receives input from the controls andpasses its result to the Graph.

You may consider the add-multiply and the simulate signal code to co-exist on the same block diagram in parallel. This means that they will both begin executing at the same time and run independent of one another. If the computer running this code had multiple processors, these two pieces of code could run independent of one another (each on its own processor) without any additional coding.

Page 153: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

OverviewWith the release of National Instruments LabVIEW 8, you have new freedom to choose the most effectivesyntax for technical computing, whether you are developing algorithms, exploring DSP concepts, or analyzingresults. You can instrument your scripts and develop algorithms on the block diagram by interacting withpopular third-party math tools such as The MathWorks Inc. MATLAB software, Mathematica, Maple, Mathcad,IDL and Xmath. Use of these math tools with LabVIEW is achieved in a variety of ways depending on thevendor as listed below:

Native LabVIEW textual math node: MathScript node, Formula node

Communication with vendor software through LabVIEW node: Xmath node, MATLAB script node, Maple* node, IDL* node

Communication with vendor software through VI Server: Mathematica* VIs, and Mathcad* VIsIn LabVIEW 8, you can combine the intuitive LabVIEW graphical dataflow programming with MathScript, amath-oriented textual programming language that is generally compatible with popular m-file script language.

Page 154: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The MathScript Node enhances LabVIEW by adding a native text-based language formathematical algorithm implementation in the graphical programming environment. M-filescripts you’ve written and saved from the MathScript window can be opened and used in theMathScript node. M-file scripts you created in other math software will generally run as well.The MathScript allows you to pick the syntax you are most comfortable with to solve theproblem. Equations can be instrumented with the MathScript Node for parameter exploration,simulation, or deployment in a final application.

The MathScript Node:• Located in the Programming»Structures subpalette.• Resizable box for entering textual computations directly into block diagrams.• To add variables, right-click and choose Add Input or Add Output.• Name variables as they are used in formula. (Names are case sensitive.)• The data type of the output can be changed by right-clicking the input or output node.• Statements should be terminated with a semicolon to suppress output.• Ability to import & export m-files by right-clicking on the node.

Page 155: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

The MathScript Window provides an interactive environment where equations can be prototyped andcalculations can be made. The MathScript Window and Node share a common syntax and globali bl ki variables making the move from prototype to implementation seamless. The data preview paneprovides a convenient way to view variable data as numbers, graphically, or audibly (with soundcardsupport).

Features of the interactive MathScript Window:• Prototype equations and formulas through the command Window• Easily access function help by typing Help <function> in the Command Window• Select a variable to display its data in the Preview Pane and even listen to the result• Write, Save, Load, and Run m-files using the Script tab• Share data between the MathScript Node in LabVIEW and the MathScript Window using GlobalVariables• Advanced plotting features and image export features

Page 156: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 157: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

To begin our model, first we will make a simple model calculation of Newton’s classicF=m*a equation. Since we are interested in using Force and Mas as inputs, we willcalculate a=F/m.1. Create two front panel controls: a numeric control and a vertical slider.a) Right click on the front panel to bring up the Controls Paletteb) Navigate to the Modern » Numeric sub-palette by left-clickingc) Left click the Numeric control.d) Left click on the Front Panel to place the control.e) The name of the control will be highlighted. Start typing to rename thiscontrol to “Mass (kg)”f) Repeat steps a-d with a Vertical Pointer Slide. Name this control “Force(N)”2. Create a front panel gauge indicator.a) In the Controls Palette, navigate to the Modern » Numeric sub-palette.b) Select the Gauge indicatorc) Place and name this indicator “Acceleration (m/s2)”3. Notice how corresponding terminals appeared on the white block diagram.4. Place a divide function on the block diagrama) In the Functions Palette, navigate to the Programming » Numeric subpaletteb) Select and place the Divide function.5. Wire the controls and indicators to the Divide functiona) Hover the mouse on the right side of the Force control. The cursor willchange to the wiring tool automatically.b) Left click to begin a wirec) Move the mouse to the top input of the divide functiond) Left-click to complete the wiree) Repeat steps 1-4 to wire the Mass control to the Divide function’s bottominput and the output to the Acceleration indicator.

Page 158: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 159: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Motor Controller, Symbolic Transfer Function

Page 160: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them
Page 161: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Motor Controller, Symbolic Transfer Function, MathScript Block, Simulation Loop, Derived PID

Page 162: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them

Motor Controller, Symbolic Transfer Function, MathScript Block, Simulation Loop, Derived PID, Selectable Pulse Input

Page 163: hguywilliams.nethguywilliams.net/images/documents/Notes/LVTS/LabView... · Web viewThe vertical toggle switch and the round LED Boolean objects are shown below. You can find them