Graphically Display Data Using LabVIEW and USBXpress
05/148/2010 | 09:47 PM
Problem
Overview:
Using an example in the USBXpress directory, this article will explain how to use LabVIEW to graphically display the data being read from a F320 board. LabVIEW is a graphical programming environment that makes it easy to display data using one of the many display controls they support, for example, a graph, chart, or dial. These controls can be difficult and time consuming to program into your C++ application. Integrate LabVIEW into your application, and demonstrate that graphically displaying your data can be quick and easy.
Solution
Software Requirements:
USBXpress LabVIEW 7.1 Visual Studio 6.0.
This article will describe the steps to call a DLL, created in LabVIEW, from a C++ application. The c++ application will call a function exported from this dll. This function will display a dialog created in LabVIEW that will mimic the dialog created in C++. This will demonstrate how to transfer that data retrieved from the F320 using USBXpress to LabVIEW.
Test Panel Dialog Modifications:
Open the TestPanel application found in the USBXpress examples directory:
CiLabsMCUUSBXpressExamplesTestPanelHostVC6.
The application displays a dialog, called TestPanel, to display data read from the F320 board running firmware found in the following directory:
In real time, the dialog will update based on what actions are done to the board. A modification will need to be made to this application to call the dll created in LabVIEW. Also, a button will be added to the dialog that will link to a handler function to open the dialog created in LabVIEW. The updated dialog will look as follows:
LabVIEW Implementation Steps:
We want to recreate this dialog in LabVIEW 7.1 to look like the following:
The controls on the front panel are updated by globals. These globals are defined on another Virtual Instrument (VI) seen in the following illustration:
Each global corresponds to one of the controls on the MainTestPanel.vi. The block diagram of the MainTestPanel.vi is connected as follows:
The final VI that needs to be created is the one that will be called from the C++ application to update the globals with data from the F320 board. The front panel of the UpdateFrontPanel.vi is shown below. This VI also needs the controls linked to the connector diagram. This is done by right clicking on the icon and selecting “Show Connector”. There will be a connector box for each control on the front panel and the connection is made by selecting a box and then clicking on a control. This is a necessary step that will allow arguments to be added to the exported function declaration for this VI.
The block diagram will update the global variables:
Once the VI’s are created, the DLL can now be built. Select Tools>>Build Application or Shared Library (DLL). The Target settings are shown below:
Under the Source Files tab, exported VI’s will need to be added. The two for this DLL are MainTestPanel.vi and UpdateFrontPanelData.vi.
The UpdateFrontPanelData.vi will have parameters added to its function prototype. Select the Define VI Prototype button. The following dialog will pop up and parameters can be added to the function prototype.
Once everything has been defined, the Build button can be pressed and will generate a
header file, library file, and a DLL in the specified location. These files will be incorporated to the C++ TestPanel application so the LabVIEW dialog can be invoked to display the data read from the F320 board.
Final Test Panel Application Code Updates:
In the TestPanel C++ application, the project settings need to be modified to link into the library created from the LabVIEW application. From Visual Studio, select Project>>Project Settings from the menu. In the dialog displays, select the Link tab and add LVTestPanel.lib to the Object/library modules control. Press OK. See below for what the dialog should look like.
In the project view, add LVTestPanel.h to the project Header Files folder. This header file will need to be included to the TestPanelDlg.cpp file under the other includes at the top of the file.
Two code modifications will need to be made. The first will be in the OnButton handler for the Open LV Test Panel button. In that function add a call to LVTestPanel. This is one of the two exported functions generated from the LabVIEW Test Panel application. The second modification is in the OnTimer function. The line before the call to CDialog:nTimer(nIDEvent), add the following line of code:
Graphically Display Data Using LabVIEW and USBXpress