LabVIEW for Dummiees
Section 3

Back to the Section 2


Attribute Nodes

Attribute Nodes are very important and can be a bit tricky to learn. There are over 100 different attribute nodes. I have only used a small number. For the most part they are ways of computer controlling the display characteristics of the front panel. You can do all of these things by right clicking and making the current values default. However in certain circumstances, such as when you need to record the attributes for computation, or you are concerned that someone will change the default values, they are extremely useful. They can be created by Create >> Attribute Node. If you want it to be a control, leave it be. Just remember to Create Control, or Create Constant. If you need to collect data, Change to Read.

Making Works of Art

Here is a method where I used the attribute nodes to create a background curve by literally drawing it. There are two ways of performing this operation, the simple and the complicated, and I will tell you both. You will need these functions:
1) A Waveform or XY Graph (must have at least one XY Graph)
2) An Attribute Node with two elements with the selection Select Item >> Cursor Info >> Cursor Position >> Cursor X then Cursor Y
3) A While Loop, Shift Registers, Case Structures, Initalize and Replace Array, and a Time delay.

First the simple way
Bring out your two Graphs on the Front Panel. For your Artistic Pallet Graph, Show >> Cursor Display then Create >> Attribute Node, and locate it on the diagram. Double its size, Change All to Read, and choose the two elements listed above (#2). Create a while loop with a Boolean Control on the conditional operator. Place the attribute nodes inside the while loop, the Graphs shouldn't be in the Loop. Place a Bundle outside the loop. Connect the Node to the Bundle which is connected to the XY Graph control. Be sure to Enable Indexing at the tunnel on the While Loop. To make the cursor work, just enter something. You will see a yellow cursor on the graph.
If all is well, RUN, and click and drag the cursor around. When you are finished, click the Control OFF, and you should see your Work of Art!

This was the simple way and does have its limitations because, what if you want to pause? Make a mistake? Or just want certain points? This next way is more general and flexable.

Now the Hard One
First the logic behind it: (This isn't a computer code)
Initalize Array A[1000]=0; Array B[1000]=0; number=0;
While (ON)
{
GET point(x,y);
if(Start)
   {
    A[number]=x; B[number]=y;
    number=number+1;
    //Insert the cursor values into the arrays   
   }
else
   {if((NOT Start) AND (NOT Pause))
      {
       A[1000]=0; B[1000]=0;
       number=0;
       //reinitalize to default for mistakes
      }
    if((NOT Start) AND Pause)
	//just pass data through}
WAIT 100 ms;
}
I used this program to draw background curves. Above I mentioned a time delay because with an array size of only 1000, LabVIEW would go though it in less than a second, and if I had made the array size much bigger, there would be many more points than are needed for curve fitting. You can reduce the wait, but I wouldn't eliminate it. Make sure the Time delay is in the While Loop! I don't have more to say. Try you hand at it. The most common error would be the confusing of the Boolean operators. If you are lost here are the two drawing VIs zipped.

Well I could go through each of the Attribute Nodes, but I would be typing until the next millennium. But just use these facts that any control or indicator can have them, just choose Create >> Attribute Node and they can control or read the properties, or attributes of the Front Panel Icon. The names are fairly descriptive and can alter the graphing properties, foreground and background color, sizes of icons and text, to make an icon visible or blink. Play around with them. If anyone completely confuses you, I will be happy to add it.


Creating Sub-VIs

Imagine that you have just written a very complicated program. You feel really proud and run it, but it doesn't work quite right. When you look over the wire diagram you realize you missed an important complicated calculation. &#@*!! There is no way to fit it in the diagram, and if you tried, probably more mistakes would be created. Or you need a piece of code for several programs you are developing, and you don't feel like rewriting it every time. In text based programs, you could just type or copy the code in anywhere. LabVIEW uses sub-VIs which are sub-routines for functions you may use many times. In fact most of the functions from file on down are sub-VIs. All sub-VIs are squares, but not all squares are sub-VIs. An easy way of determining this is by double clicking on the node. If a new VI opens, it is a sub-VI. Sub-VIs are completely self sufficient programs, i.e. they can run on their own. The controls are the inputs and the indicators are the outputs.
How to make a sub-VI:

  1. Write your subroutine with the controls as the inputs and the indicators as the outputs
  2. Be sure to label the controls and indicators with descriptive and appropriate labels
  3. The little icon in the upper right hand corner corner icon, is where to make the node.
  4. By right clicking on the icon and choosing Edit Icon..., you can put a short description of what the sub-VI does. This is what you will see on the diagram when you use it. If you are an artist, color it. When you are finished, click on OK.
  5. Make sure that you are on the front panel. Right Click again and choose Show Terminals.
  6. The square is automatically divided for the number of indicators and controls. If you don't like it, you can choose a new pattern, add or delete terminals, or rotate the terminals. Usually LabVIEW has a good idea of what to give. Just be warned that the maximum number of terminals is 28. I never needed that many, but if you do, there are two ways around it. Use more than one sub-VI by breaking the subroutine in half, or by bundling the elements (See Clusters).
  7. Get the wire spool. Try to keep the inputs on the left and the outputs on the right. Click on the terminal, then click on the indicator or control, or vise versa. The terminal will appear in the color of the wire. Keep repeating for the rest of the terminals, but not everyone has to be used. Also, a sub-VI need not have any outputs, or any inputs.
  8. If a connection is a vital necessity, choose This connection is.... Useful if others will be using the sub-VI.
  9. SAVE IT
  10. Go to your main program, and by using the functions pallet's very bottom icon (Select a VI...), choose your sub-VI. By passing the wire spool over the sub-VI you will see the connectors appear. Now you can connect. You can also insert or replace a sub-VI.
NOTE: If you open a sub-VI from the program, and save it under a different name and alter it, the other sub-VIs in the program may be altered that you don't want. For example, in a program I was writing, I always wanted a temp file to be rewritten, but the dialog box would appear, so I altered the file to remove the dialog box appearance as I described and it altered the other file sub-VIs I wanted left alone. You can search the VI for Problems, or Replace the sub-VIs you want changed. Be sure to check!

Libraries

If you are making a program, it is just good programming practice to write sub-VIs because they will make your diagram less cluttered, easier to test and study. However, those little icons will take up much space. LabVIEW has a special folder structure for its own files called a library (*.llb). When you File >> Save As... Choose New VI Library, enter the name, VI Library, then save (*.vi). To put more VIs there, just click on the library icon when you save.
If you have many VIs in the library and just want the main program to open when you start. File >> Edit VI Library, highlight the main program, and choose Top Level, while you are there you can also delete any obsolete VIs. Repeat as necessary. NOTE: Only LabVIEW objects can be stored in the library, not just anything (such as text files).
Close LabVIEW, when you click on the library icon, the main program will open automatically.

User Libraries

If you create a new VI that you believe is important enough to be placed perminantly on the functions pallet, if you save it in the User Libraries folder, it can be accessed very easily.


Data Acquisition

Before I tell you about how to program for Data Acquisition, you need to know how to connect the hardware. The data acquisition (DAQ) device we have here is a PCI-MIO-16E-1. The configuration we used is (Under the NI-DAQ Configuration Utilities
<-10.0V - +10.0V><Referenced Single Ended><Bipolar><None><Disabled>
If you have no idea how to use it, here is how the first electronic nose team did it. When the DAQ board came we unwrapped it carefully. There is a board you have to insert into the computer. We put it into a slot where it fit (I'm not a computer engineer). Turned the computer on and it worked! Afterwards we waited for a month for the cable and the DAQ connection board. The company said we didn't specify it when we ordered. Make sure all the software is installed. Find a friend and a multimeter. Just in case you can't find a multimeter, you can use a LED (light emitting diode). Be sure to attach a resistor or it will burn out! Go to the NI-DAQ for Windows, and view the NI-DAQ Test Panels.

Symbol meanings on the DAQ board
ACH#
AIGND
DAC#OUT
DIO#
DGND
Analog input channel #
Analog input ground
Analog output
Digital Input/Output (5 V)
Digital Ground

Find the DIO0 and DGND pins (on my board 52 and 53), place your two multimeter probes on the "screws". You should register +5 V. If it is negative, you have the probes backwards. Once you have reached the test panels, go to the Digital I/O where there is a long row of circles. Move your mouse to the second row left hand side where there should be a clear circle above the 0. CLICK! If you did this right, the voltage should reduce to ZERO. Find the other Digital I/O pins on the DAQ board and click on the corresponding circles. This can get exciting when it works for the first time. By connecting a MOSFET to the board (not the DAQ board, your own circuit of course), you can operate a solenoid switch.

Find the DAC0OUT and the AOGND pins (on my board 22 and 55), and place the multimeter on the "screws". You should register 0 V. Go to Analog Output on the Test Panels. Output a DC Voltage anywhere between -10 V and 10 V. The multimeter should register the voltage being put out. If you are using a LED, the intensity will change.

Find the ACH0 and AIGND pins (on my board 68 and 67), get a 1.5 V battery (if you can, a calculator battery is fine), and two wires. Make sure the battery has some life yet! Go to the Analog Input Panel. The chart should be nearly constant, there is always some noise. If there is some drift, don't worry, you just need to connect it to a ground. Connect your battery terminals to the two pins and voltage should jump to +1.5 Volts, or whatever the battery voltage is. If it's negative, your backwards. Use the Multimeter to compair the two voltages. The agreement is usually very good.

If you need more specific info on the technical specifications see the user's manual that comes with the DAQ board. Now that you are familiar with the location of the pins and what they do, I will explain what the electronic nose group used the DAQ board for.

Be mindful that our needed data acquisition rate was slow. If you need faster rates or more control over your hardware, you can design your DAQ VI from the elementary parts used in the common DAQ VIs. Here are the sub-VIs we used.
  1. AI Sample Channels.vi - You will need the device number which can be determined when you open the NI-DAQ Test Panels. The channel numbers which are written in a string comma delimited. The high and low limit don't have to be wired, they use the values set down in the NI-DAQ Configuration Utility (-10 V to +10 V). The output (Samples) is a 1-D array. Connect it to a Build Array to make a 2-D array which defines the values as different plots. Finally connect this to a Waveform Chart. Make sure to have all this in a While Loop.
  2. AO Update Channel.vi - Three simple things
    a) Device - same as above
    b) Channel Number - a string 0 or 1
    c) Value - How many volts between -10 V and 10 V.
    That's all there is too it.
  3. Run_me.llb/Getting Started Digital I/O.vi - This is what I used for the control of the switches. But I had to alter it. Remember to save it under a different name!! The program uses a cluster to control the ON/OFF. Just run it to see if it works. Look at the diagram to see what is happening.
    A cluster of 8 Boolean Switches moves to the Cluster to Array which moves to Boolean Array to Number and so on.
    You could just use the cluster as a manual control, but it becomes more difficult if you want to control from a file. I deleted the Custer and Cluster to Array, and made a control going to the Boolean Array to Number. Now enlarge the array to 8 elements and try it. It is as good as the original. Try it to make sure. Now reconnect the terminals, so you can have your sub-VI. I didn't bother altering the rest. In your control file you need to have interger numbers. If you are just going to be using one switch, use 0 and 1 for on and off. If you need to control more switches, refer to Boolean Section to see how LabVIEW converts from number to boolean array. Connect the control to a Number to Boolean Array. You may be thinking, why didn't I just use the number as the control since it will be converted back anyway? Well, this way you can see the boolean control, and will know which switch is on.
    When you connect the program in your main diagram, you may have a problem. The first time we tried it, it kept switching on and off between each iteration. I made the "Port Configure" a control in the main program and made "configure the port for reading or writing" the default. I just had to hide it behind a graph, and it worked fine. Sometimes if it isn't working right try anything.
Control Files for the Outputs are very easy to create. In Excel or another spreadsheet, enter the numbers in a column and save as a Text File (Tab Delimited). If you want a time value to see how far along you are, just insert it in another column. By using the Read Lines from File.vi as an example you can extract the values, convert to a number and input to the Output sub-VI.

As a good exercise, I suggest you look at a recent issue of Scientific American in The Amateur Scientist section. There are some inexpensive and interesting projects where a DAQ system could be useful.


Analysis

The Analysis sub-VIs in LabVIEW covers just about every possible need for analyzing and creating data series. You can create a many types of wave patterns. Look under Signal Generation. Try connecting the different sub-VIs to Waveform Graphs and view the results. Alter the inputs and observe the changes. Also try adding waves.
For some of the analysis VIs, if you need to know the mathematics behind their operation, use the Online Help, and you will see the Name Details. Not every VI will have them. The analysis VIs are very easy to use, usually only needing the input data.
Under Digital Signal Processing you can perform FFT (Fast Fourier Transform), but only if there are 2x points. However, LabVIEW automatically looks for the number of points, and if it's not 2x points, the DFT (Descrete Fourier Transform) is implemented. Also avaliable is the Hilbert Transforms, and Derivatives and Integrals (Numeric only!).
The Most important sub-pallet is the curve fitting VIs. You can perform any order polynomial or exponential fit on data series and the points need not be identically spaced, any X and any Y. For a N order polynomial fit you need at least N+1 points. If you need a smoother curve, a possibility is using an even coefficient fit, i.e. a0+a1x2+a2x4+... This can easily be accomplished by squaring the x points before they enter the poly fit, and use the original x's when the fit points are generated. NOTE: The Y points generated are for the original X points entered. If you entered the points [(1,23)(4,2)(5,7)], the result would be [(1,Y0)(4,Y1)(5,Y2)]. Also the default for the polynomial fit is SVD. I noticed some problems when I used it. I like to use the Housholder instead.

The basics of Probability and Statistics, filters for cleaning waves, the tools necessary to perform Matrix operations, polynomial evaluations are all available. It would take too long to explain all of them. If you need it, you will know how to use it. If anything completely confuses you, I will be happy to add it.


Other Stuff

Clusters

Clusters can best be describes as all purpose arrays. While arrays can only hold data from one wire type, Clusters can be used to hold data from all wire types, including cluster. Clusters are used mostly for X,Y Plots and errors, but can be useful to limit the amount a wires in the diagram. Here are important terms:
  1. Bundle - Used to combine any combination of your needed wire types. Just enlarge and attach as needed. It is a good idea to have a different descriptive label name for each of the items. If you don't have them coming from a direct control or constant, Create Indicator and name it. As a starting point the Source Element doesn't need to be wired. To replace an element in the cluster, wire your original cluster to the Source Element, make sure the Bundle size is the same as the original, and only add an input to the element you want changed.
  2. Unbundle - Quite simply, it undoes the bundle operation. All you have to do is make sure that the size is the same, and then just wire them to indicators or the rest of the diagram.
  3. Bundle By Name - If you have a large bundle and just want to replace one or two of the elements in a cluster, you can tell the VI to replace only the element with a particular name. This is why I told you to label the inputs before! Wire the cluster, then Select Item >> "Whatever", and wire your new value. This is analogous to the Replace Array.
  4. Unbundle By Name - Can you guess? Same thing as above, just the item will be an output.
  5. Cluster to Array & Array to Cluster - They do what they sound like. However, it only works for elements individually clustered, that is only individual numeric and Boolean.
  6. Here is an example of the bundling operations for clusters. Reproduce them and try your own.

List & Ring

An interesting feature of LabVIEW is the ability to choose from a List, if you want the VI to do a particular thing. Think of the List as an "Ordered List <OL>" in HTML, i.e. each description is preceded by a number. To see what I mean, on the Front Panel call up the Control >> List & Ring >> Single Selection Listbox. Now you will see a box where you can enter your different names, a different item is made by hitting the Enter Key. Look at the terminal on the diagram. This is one thing I don't like. It is looks exactly the same as a Long Interger. Make an indicator to the control. You will see a regular digital display. Put the VI on Continuous Run, and click on the different words. You will see the number change. This could be connected to a Case Structure and work like a bigger Enumerated Control. The Multiple Selection Listbox allows you to select more than one item, and appears as a 1-D array. However, to select multiple items you must hold down the Shift Key when you click on the item. You can also add symbols in front of the name by choosing Show >> Symbols, then Item Symbol, where you can choose what you want. From the diagram you can get a symbol from the Functions Pallet >> Numeric >> Additional Numeric Constants >> Listbox Symbol Ring, and by using the hand, choose your symbol. Be sure to take a look at the Attribute Nodes, where you can control the size, need click or double click, and symbols.

Advanced

If you are an old softy who craves the good old days of text programming and are being forced to learn LabVIEW, you can still use your beloved FORTRAN, BASIC, C++, etc. You can't just use the text programming. You need to compile them and they need to have *.lsb extension. Get the Code Interface Node (CIN). Connect the Input terminals you will need and label them. Create .c File, write your code in the file LabVIEW gave you, compile, and Load Code Resource.... This should work. I have never used them.
Another feature in LabVIEW is the ability to call Dynamic Link Libraries (*.dll), which are the big computer programs that your computer needs to operate. Call Library Function uses the *.dll files. By using these you can call programs not normally used for LabVIEW. My opinion on this is that instead of trying to link another program to LabVIEW, just use the program that was given to you.
Also here is the Beep function. In Windows it doesn't do much, just a "phllp". Place it in a while loop and you get a longer phllp. Apparently on a Macintosh, you can control the amplitude, frequency, and duration. If you want music or nice sounds, use the Play Sound.vi, and just name a *.wav file you acquired from somewhere else. You can insert it in a program as a sub-VI. I'm not sure, but you may have to create the terminals to make it a sub-VI. I don't remember if they were included originally.

Application Control

This pallet contains the necessary controls for controlling the operation of the VI. The only one I have ever used is the Stop which stops the VI in its tracks, the same as pushing the stop botton on the tool bar. Also you can call up menues and help tools. Not used very much.

Communication

I have never used this but it can be used to access the internet for remote access devices.

Instrument I/O

Since we disn't use any other instruments, I have no experience with them. They use a GPIB (General Purpose Interface Bus), this his used for control of outside instruments by sending ASCII text to acquire data turn on/off, etc. Each instrument has its own ASCII codes but they try to be written to be easily convertable using the IEEE 488.2 standard.
Instrument Drivers contains the VIs necessary to control the HP33401A Multimeter.

Acknowledgments

Finally thanks to all the people who helped me learn LabVIEW, offered guidance on the tutorial, and gave me inspiration.
The Entire Electronic Nose Team
Dr. P. Lykos
Dr. J.R. Stetter
Dr. W. Penrose
Schattke Chemical Consulting
Asha Joesph
Harald Edvard Ziel Opsvik - Inspiration behind the Compressor example in the Quiz
If I missed you, tell me and I will include you.


I would appreciate it if you would send some feedback so I can better design this tutorial to fit everyone's needs
Name:

E-mail:

Homepage or other LabVIEW site:

Comments/info or Problems?



Copyright © 1999 Christopher Morong All Rights Reserved
Last Updated 8/26/99