Wednesday, August 18, 2010

Data Acquisition Reference Application for LabVIEW

The Data Acquisition Reference Application for LabVIEW is a specific application implementation based on the framework defined in the Data Acquisition Reference Design. This application uses the FlexSignal Reference Library to acquire data from DAQmx devices, TDMS files, or simulated signals. The data can be logged to TDMS files and viewed in several different displays such as a power spectrum, harmonic cursor, and RMS chart. The Channel Monitor XControl is used as a general channel monitoring tool to show overall level and time domain signals.

This is the top-level Project Library and contains the main application.  It also holds the System Configuration.ctl type definition.  
The best place to start with customizing the code is with the System Configuration type definition.  This type definition contains information that will be used by most of the other Project Libraries.  Any changes here will be propagated to them.  Add the data types that you think you’ll need for data acquisition and data logging.
The GUI of the main application consists of a toolbar of icons for actions and the Channel Monitor XControl
Figure 1 - GUI of main application
The Channel Monitor XControl gives the user another way to interact with the data as well as some feedback to the applied configuration settings and if the acquisition is active. 
Consider the most appropriate default data view for the application and use it in the main GUI.
The Analog Input [FlexSignal] Project Library is the acquisition engine of the application.  In this case, the acquisition source is the FlexSignal Reference Library which can acquired data from DAQmx devices, TDMS files, or simulated signals.  The main VI of the Project Library is “DAQ Analog Input.vi”.  This VI is an action engine with three states: Configure and Start, Read, and Close.
Figure 2 - DAQ Analog Input.vi block diagram
This VI contains all of the specific acquisition code.  To change or modify the way the data is acquired, change this code.
The DAQ AI Engine State.vi receives messages generated by user events (such as pressing the Start button) and translates it into the appropriate next state for the DAQ process.  This VI does not need to be modified unless the states or commands for the DAQ process are changed.
The other VIs (Get AI Channel Names and Get AI Input Range) are helper VIs used to setup the Channel Monitor XControl.
This is the VI to modify if you want to change the file type, file naming convention or add other application information to the log file such as test run, user, hardware settings, etc.
Figure 3 - TDMS Data Logging.vi block diagram
The TDMS Log Engine State.vi receives messages generated by user events (such as pressing the Log button) and translates it into the appropriate next state for the Logging process.  This VI does not need to be modified unless the states or commands for the Logging process are changed.

MathScript node (in a LabVIEW Block diagram)


You can include MathScript commands in the Block diagram of a VI  in a MathScript node which is available on the Functions / Mathematics / Scripts & Formulas palette. Let us look at a simple example. Below are the Front panel and the Block diagram of mathscript_example.vi, followed by comments. You will soon be guided through the development of this VI.


Comments to the Front panel:
·         To the left of the Front panel are the scalar controls (or numbers in DBL (double) formal), a and b, and two real matrices, A and x.
·         Further to the right are indicators, z and y. z is a real scalar. y is a real matrix.
·         error out is a cluster indicator displaying any MathScript errors on the Front panel.
Comments to the Block diagram:
·         a, b, A, and x are names of the inputs to the MathScript. The data type of a and b are real scalars (we may also say doubles). A and x are real matrices.
·         Matrices are used, not arrays, in these matrix based calculations! Connecting arrays to the MathScript node in stead of matrices in such applications will cause an error.
Scalars and matrices are probably the most common data types in MathScript applications. However, you can also use arrays and strings (text). The data type of a MathScript node input or output are set via right-clicking on the input/output, and selecting the sata type from a list.
The MathScript node contains three commands: One comment, which starts with a percent sign, and two ordinary commmands separated by semicolon.
·         The MathScript contains an error cluster output which here is wired to a front panel indicator. It is wise to include an error cluster in the early stage of the development of a VI containing a MathScript node as it helps you to find errors. These error may otherwise be quite hard to find.
Note: If you want to include a matrix constant in the Block diagram, you may face trouble because there is no matrix constant on the Functions palette (this is a little strange...). In this case, you may in stead intermediately create a matrix control on the Front panel, and then change its Block diagram terminal from control to constant via right-click on the terminal. If you really want to use matrix constants in the Block diagram, you may consider creating or defining the matrix directly in the MathScript node. For example you can type
M = [1,2;3,4]
which creates a 2x2 matrix with 1 and 2 in the first row, and 3 and 4 in the second row.
Now, it's your turn. To create a VI similar to mathscript_example.vi:
  • Open a blank VI, save it as my_mathscript.vi in any folder you prefer.
  • Add the following to the Front panel, as on the Front panel of mathscript_example:
    • Two Matrix controls from the Controls / Array & Matrix palette, and label them A (real matrix) and x (real matrix), respectively.
    • One Matrix indicator from the Controls / Array & Matrix palette, and label it y (real matrix).
    • Two scalar Numeric controls, and label them a (real scalar) and b (real scalar), respectively.
    • One scalar Numeric indicator, and label it z (real scalar).
Enter values to these Front panel elements as on the Front panel of mathscript_example.
  • Do the following with the Block diagram (re-position the elements as you wish):
    • Add a MathScript node from the Functions / Mathematics / Scripts & Formulas palette. In the node, type the commands as shown in the Block diagram of mathscript_example
    • Create input tunnels and output tunnels to the node by right-clicking on the border of the node, and give these inputs and outputs names as shown in the Block diagram of mathscript_example.
    • Connect the control terminals to the inputs of the MathScript node according to the Block diagram of mathscript_example. The data type of each input is then automatically set by LabVIEW, but you should check the settings by right-clicking on each of the inputs.
    • It turns out that the data type of the outputs are not set automatically by LabVIEW. In stead, you must set the data type manually by right-clicking on each of the outputs:
      • z: Scalar, DBL
      • y: Matrix, real
Then connect the ouputs y and z to their respective indicators.
  • Create an error indicator on the Front panel: Right-click on the error output (at the lower right corner of the MathScript node) / Create Indicator.
Save the VI, and run it. Does it work?
Note: This VI will run the code once since the code is not inside any While loop. If you want, you can add a While loop, a Stop button, and a Metronome. If you do not want to add a While loop, but still want to run your VI continuously while testing it, click the Run Continuously button in stead of the Run button in the toolbar.


Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers

Followers